|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
Re: Angle Calculation from image of goal
Quote:
angle = (goalx - 640/2) * 90/640 We plan on closing the loop with a gyro so we won't have to rely on a quick framerate to lock onto the goal. If you don't know the viewing angle, or want to do it empirically to be more accurate, you could mark a piece of paper with several angles, put the camera flat on the paper and measure pixel distances at different angles. |
|
#2
|
|||||
|
|||||
|
Re: Angle Calculation from image of goal
We tried doing it and ended up with awkward results.
Eventually what we did, is just get the difference between the two measurements, divide it by the distance measured from the goal (you have that in the GRIP), and use that as a fake "angle". For each "degree" in that angle we do a certain amount of encoder turns. After some calibration it works very well, and fast. |
|
#3
|
|||||
|
|||||
|
Re: Angle Calculation from image of goal
Quote:
Code:
horizontal_angle_to_goal = atan((goal_x - center_x) / focal_length_pixels) where: focal_length_pixels = .5 * image_width_pixels / tan(horizontal_field_of_view / 2) Typically, unless you calibrated your camera to compensate for manufacturing imperfections (total overkill for FRC): Code:
center_x = (image_width_pixels / 2 - .5) Note that these equations do give slightly different answers! (See attached image...red is the correct equation, blue is the approximate linear one) Also note that this angle is relative to the camera...you need to whip out some more trig depending on the angle of the camera mount relative to its robot. |
|
#4
|
|||||
|
|||||
|
Re: Angle Calculation from image of goal
You need to know the specifics of the camera and lens you are using to be ultimately accurate. If you know the focal length of the lens and the size of the pickup device, you can make a calculation using trig, to determine the angle of the field of view. Once you have that, you need to know the distance to target or you can back into the distance by calculating a known target size as a percentage of the field of view. This might be a frustrating exercise since the pickup and focal length of these lenses is so small. That allows a lot of error to creep into the calculation.
|
|
#5
|
|||||
|
|||||
|
Re: Angle Calculation from image of goal
Quote:
![]() |
|
#6
|
|||||
|
|||||
|
Re: Angle Calculation from image of goal
Quote:
What's your setup for both the camera and processor? |
|
#7
|
||||
|
||||
|
Re: Angle Calculation from image of goal
Here is some LabVIEW code that tackles this problem...
The way the VI works is it takes your current gyro heading, and does some trigonometry to find the needed gyro heading and the current distance from the goal (might be helpful if you have a certain distance range you can shoot from). Make sure to set the constants in the code (I've commented it mostly, but the important ones are the goal target width (in feet), the camera's horizontal angle of view (in degrees), and the image width (in pixels)... Disregard the Disabled code at the bottom. Hope this is helpful, feel free to PM me with any questions. |
|
#8
|
||||
|
||||
|
Re: Angle Calculation from image of goal
I believe they are using a Nexus 5 with on-board vision processing
![]() |
|
#9
|
|||||
|
|||||
|
Re: Angle Calculation from image of goal
If you've found the answer above, please disregard, but this is how we've done well:
Position the robot roughly aligned with the goal (that is, eyeball it). Do a test launch. Note where the ball ends up, in terms of inches/feet to he left or right of the goal. Rotate the robot a known amount (probably measured in terms of encoder counts on the left and right drive systems). Do another test launch. Note where the ball ends up (same criteria). Based on the two measurements above, calculate a "target point" that will result in a goal, and a "proportionality constant" to get there wif the robot is pointed somewhere else. |
|
#10
|
|||
|
|||
|
Re: Angle Calculation from image of goal
Could you elaborate more on what trig you'd need to use? I've been wondering about this, and it seems to me that the angle the camera is mounted at should only affect the y coordinate, and since the angle calculation only takes x coordinates the mount angle shouldn't affect the result.
|
|
#11
|
|||||
|
|||||
|
Re: Angle Calculation from image of goal
Quote:
Imagine a camera that is looking straight up. What does the x coordinate mean with respect to the robot? What does the y coordinate mean? |
|
#12
|
||||
|
||||
|
Re: Angle Calculation from image of goal
We actually took the time to do the trig out for the offset. You can take a look at our function https://github.com/FRC125/NU16/blob/...lator.java#L31 you will just need to now the fov, dimensions of image, height of camera, x,y offset of camera in inches and angle of the camera.
Your offset basically changes based on the distance to the target. You use the y coordinate of the target to calculate this distance. |
|
#13
|
||||
|
||||
|
Re: Angle Calculation from image of goal
Quote:
The horizontal field of view that you'd find on the camera's data sheet doesn't always agree perfectly with the observed results; it might take a bit of experimental tweaking. |
|
#14
|
||||
|
||||
|
Re: Angle Calculation from image of goal
I'm not sure this holds true when working with a "flat" image, we just tried rotating the camera and it did not change the x value of the target
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|