![]() |
Angle Calculation from image of goal
Hello, our team (1124) is looking to implement an improved vision system, but is having trouble calculating the angle away from the center of the goal that our robot is pointing. If anyone could share how they accomplish that it would be great. The information we know is position of the center of our camera, and the position of the center of the goal.
|
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. |
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. |
Re: Angle Calculation from image of goal
1 Attachment(s)
Quote:
Code:
horizontal_angle_to_goal = atan((goal_x - center_x) / focal_length_pixels)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. |
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.
|
Re: Angle Calculation from image of goal
Quote:
|
Re: Angle Calculation from image of goal
Quote:
Quote:
|
Re: Angle Calculation from image of goal
1 Attachment(s)
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. |
Re: Angle Calculation from image of goal
I believe they are using a Nexus 5 with on-board vision processing :D
|
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. |
Re: Angle Calculation from image of goal
Quote:
|
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? |
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. |
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. |
Re: Angle Calculation from image of goal
Quote:
|
| All times are GMT -5. The time now is 13:48. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi