Quote:
|
Originally Posted by chakorules
I might be way off base here...
but what we did was make a global varible called cam_Size. Then in the "Capture Tracking Data", there is a pull down box called Region Size. We selected cam_Size in that box. cam_Size needs to be declared as an unsigned char in your globals.
Region size is the size of your "blob" from the CMU cam. The closer you are to your color tracking parmeters, the larger the "blob" will appear on the screen. The futher away you are, the smaller the region will be on the screen.
This relationship is almost linear.
Let's assume that you get a region size of 255. That would mean your camera lens is right ontop of your light or let's just say 1 foot away.
Then let's assume you get a region size of 1, and you note that your camera is 30 feet away.
Everything inbetween can be calculated on a linear scale with some kind of a conversion factor.
(note, I didn't crunch the numbers, I just assumed for this topic of discussion)
1 foot = 255
1.1 feet = 254 etc...
29.9 feet = 2
30 feet = 1
|
Actually, the relationship is hyperbolic (inversely proportional), NOT linear. You can set up a proportion as follows:
Code:
(target distance)/(image distance (i.e. camera focal length)) = (target height (illuminated part))/(blob height)
This is the standard formula for a single lens (which is what the CMU Cam has). Of course, experimental factors (such as amount of the target that's illuminated) make using the above formula unrealistic. Therefore, it's more accurate to calculate a best-fit line. Solving for the target distance, you get the simplified formula:
Code:
(target distance) = (some constant)(1/(blob height))
The blob size is an area, so it's proportional to the blob height squared:
Code:
(blob size) = (some constant)(blob height)^2
or
Code:
(blob height) = (some constant)squareRoot(blob size)
Therefore, the formula in terms of blob size is:
Code:
(target distance) = (some constant)(1/squareRoot(blob size))
| | |
y = m x
The graph of target distance vs. blob size is a hyperbola, so in order to get a straight line, you have to compare target distance to 1/squareRoot(blob size).
Using this information, my team's programming group took some data using the blob sizes printed to the terminal screen (with Kevin Watson's code) when the camera is locked on to the target. We took data every 4in from 6ft (simulating when the robot is right below the target) to 25ft (simulating when the robot is at half court), and analyzed the data. Fortunately for us (and any team wanting distance data from the camera), the graph of target distance vs. 1/squareRoot(blob size) is a very straight line.
I analyzed the data using some fancy PHP code, and put the results, along with the graph and formula, in an
Excel spreadsheet on Team 1717's website. (Links to the raw data can be found under "Programming Team" > "FRC robot code" on our
downloads page.)
The final formula is then:
Code:
(target distance) = 798.48871156253/squareRoot(blob size)
The formula can be easily converted to code:
Code:
#define TARGET_DISTANCE_FORMULA_CONSTANT 798.48871156253
targetDistance = TARGET_DISTANCE_FORMULA_CONSTANT / sqrt((double)T_Packet_Data.pixels);
So, one formula down, several more to go for an accurate ball launcher!
