Go to Post Battle Bots and other robot fighting competitions is to First Like McDonalds to Hamburgers They get the idea, and have the taste, but they are bad for you in the long run. - Conor Ryan [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-04-2016, 15:28
Rflax40's Avatar
Rflax40 Rflax40 is offline
Registered User
AKA: Ross Flaxman
FRC #1124 (UberBots)
Team Role: Mechanical
 
Join Date: Jan 2015
Rookie Year: 2011
Location: Avon, CT
Posts: 6
Rflax40 has a spectacular aura aboutRflax40 has a spectacular aura about
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 11-04-2016, 15:42
TheOtherGuy's Avatar
TheOtherGuy TheOtherGuy is offline
Unregistered User
AKA: Kevin Forbes
FRC #4183 (Bit Buckets)
Team Role: Engineer
 
Join Date: Jul 2006
Rookie Year: 2006
Location: Tucson, AZ
Posts: 408
TheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond repute
Re: Angle Calculation from image of goal

Quote:
Originally Posted by Rflax40 View Post
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.
We plan on doing this soon, so I'll just share how I expect we'll do it. We'll double check the horizontal field of view (in degrees) of our camera, then find an equation that maps the goal position to degrees. For example, if the camera is 90° horizontal FoV and the resolution is 640 horizontally, then a simple equation would be

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.
__________________
Reply With Quote
  #3   Spotlight this post!  
Unread 11-04-2016, 15:55
Tottanka's Avatar
Tottanka Tottanka is offline
It isnt about bots,its about humans
AKA: Liron Gurvitz
FRC #3211 (The Y Team)
Team Role: Mentor
 
Join Date: Dec 2006
Rookie Year: 2006
Location: Hadera, Israel
Posts: 1,418
Tottanka has a reputation beyond reputeTottanka has a reputation beyond reputeTottanka has a reputation beyond reputeTottanka has a reputation beyond reputeTottanka has a reputation beyond reputeTottanka has a reputation beyond reputeTottanka has a reputation beyond reputeTottanka has a reputation beyond reputeTottanka has a reputation beyond reputeTottanka has a reputation beyond reputeTottanka has a reputation beyond repute
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.
__________________
My FRC record: 10 Years,FTA (2008-9), 3 Teams(1947,2669,3211).3 RCA, 1 Championship EI(2016), 1 Divisional finalist (2016), 1 Regional winner.
Israeli 2016 Volunteer of the year.
Reply With Quote
  #4   Spotlight this post!  
Unread 11-04-2016, 16:29
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Angle Calculation from image of goal

Quote:
Originally Posted by TheOtherGuy View Post
For example, if the camera is 90° horizontal FoV and the resolution is 640 horizontally, then a simple equation would be

angle = (goalx - 640/2) * 90/640
This can be a decent enough approximation, but there is a more correct way to do this conversion:

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)
The idea of a focal length is a little unintuitive at first, but is explained here: https://en.wikipedia.org/wiki/Angle_of_view

Typically, unless you calibrated your camera to compensate for manufacturing imperfections (total overkill for FRC):
Code:
center_x = (image_width_pixels / 2 - .5)
The -.5 compensates for the fact that if there are an even number of columns/rows in your image, the center is actually on the border between two of them (and we start counting rows/cols from 0 typically).

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.
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2016-04-11 at 1.31.15 PM.png
Views:	250
Size:	52.5 KB
ID:	20578  
Reply With Quote
  #5   Spotlight this post!  
Unread 11-04-2016, 16:49
Unsung FIRST Hero
Al Skierkiewicz Al Skierkiewicz is offline
Broadcast Eng/Chief Robot Inspector
AKA: Big Al WFFA 2005
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1996
Location: Wheeling, IL
Posts: 10,772
Al Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond repute
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.
__________________
Good Luck All. Learn something new, everyday!
Al
WB9UVJ
www.wildstang.org
________________________
Storming the Tower since 1996.
Reply With Quote
  #6   Spotlight this post!  
Unread 11-04-2016, 16:55
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Angle Calculation from image of goal

Quote:
Originally Posted by Al Skierkiewicz View Post
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.
There is a reason why our vision system this season uses a device that provides APIs to fetch pixel array size and focal length information from per-device factory calibration
Reply With Quote
  #7   Spotlight this post!  
Unread 11-04-2016, 17:58
TheOtherGuy's Avatar
TheOtherGuy TheOtherGuy is offline
Unregistered User
AKA: Kevin Forbes
FRC #4183 (Bit Buckets)
Team Role: Engineer
 
Join Date: Jul 2006
Rookie Year: 2006
Location: Tucson, AZ
Posts: 408
TheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond reputeTheOtherGuy has a reputation beyond repute
Re: Angle Calculation from image of goal

Quote:
Originally Posted by Jared Russell View Post
This can be a decent enough approximation, but there is a more correct way to do this conversion:

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)
Are you doing linear approximation or using focal length in real life? I figure since atan approximates a line when the camera is near aligned with the goal, the linear approximation would work more or less identically with any moderate framerate. This is certainly useful if the camera isn't aligned with the robot, though!

Quote:
Originally Posted by Jared Russell View Post
There is a reason why our vision system this season uses a device that provides APIs to fetch pixel array size and focal length information from per-device factory calibration
What's your setup for both the camera and processor?
__________________
Reply With Quote
  #8   Spotlight this post!  
Unread 11-04-2016, 21:37
Hitchhiker 42's Avatar
Hitchhiker 42 Hitchhiker 42 is offline
Roboter
AKA: Mark Lavrentyev
FRC #4557 (FullMetal Falcons)
Team Role: Programmer
 
Join Date: Oct 2015
Rookie Year: 2015
Location: Cromwell, CT
Posts: 501
Hitchhiker 42 is a splendid one to beholdHitchhiker 42 is a splendid one to beholdHitchhiker 42 is a splendid one to beholdHitchhiker 42 is a splendid one to beholdHitchhiker 42 is a splendid one to beholdHitchhiker 42 is a splendid one to beholdHitchhiker 42 is a splendid one to beholdHitchhiker 42 is a splendid one to behold
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.
Attached Files
File Type: vi vision angle analysis.vi (24.5 KB, 20 views)
__________________



2016 - NE District Championship Entrepreneurship Award
2016 - Hartford District Industrial Design Award
2016 - Waterbury District Engineering Inspiration Award
Reply With Quote
  #9   Spotlight this post!  
Unread 11-04-2016, 22:53
Maxwellfire's Avatar
Maxwellfire Maxwellfire is offline
Registered User
AKA: Max Tepermeister
FRC #2877 (LigerBots)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2010
Location: Newton, Massachusetts
Posts: 13
Maxwellfire is an unknown quantity at this point
Re: Angle Calculation from image of goal

I believe they are using a Nexus 5 with on-board vision processing
Reply With Quote
  #10   Spotlight this post!  
Unread 13-04-2016, 22:55
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,619
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
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.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #11   Spotlight this post!  
Unread 19-04-2016, 16:07
pipsqueaker pipsqueaker is offline
Registered User
FRC #1124
 
Join Date: Apr 2013
Location: Avon
Posts: 59
pipsqueaker is a name known to allpipsqueaker is a name known to allpipsqueaker is a name known to allpipsqueaker is a name known to allpipsqueaker is a name known to allpipsqueaker is a name known to all
Re: Angle Calculation from image of goal

Quote:
Originally Posted by Jared Russell View Post

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.
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.
Reply With Quote
  #12   Spotlight this post!  
Unread 19-04-2016, 16:47
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Angle Calculation from image of goal

Quote:
Originally Posted by pipsqueaker View Post
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.
I will try to post a more detailed explanation tonight, but for now: it affects both coordinates.

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?
Reply With Quote
  #13   Spotlight this post!  
Unread 19-04-2016, 22:53
Camilo86's Avatar
Camilo86 Camilo86 is offline
Registered User
AKA: camilo
FRC #0125 (Nutrons)
Team Role: Programmer
 
Join Date: Jun 2013
Rookie Year: 2012
Location: Boston
Posts: 21
Camilo86 is a glorious beacon of lightCamilo86 is a glorious beacon of lightCamilo86 is a glorious beacon of lightCamilo86 is a glorious beacon of lightCamilo86 is a glorious beacon of lightCamilo86 is a glorious beacon of light
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.
__________________
Hopper finalist 2015
Dean's List winner 2015
Reply With Quote
  #14   Spotlight this post!  
Unread 21-04-2016, 20:04
cjl2625's Avatar
cjl2625 cjl2625 is offline
apel py
AKA: Cory Lynch
FRC #2067 (Apple Pi)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Guilford, CT
Posts: 412
cjl2625 is a splendid one to beholdcjl2625 is a splendid one to beholdcjl2625 is a splendid one to beholdcjl2625 is a splendid one to beholdcjl2625 is a splendid one to beholdcjl2625 is a splendid one to beholdcjl2625 is a splendid one to beholdcjl2625 is a splendid one to behold
Re: Angle Calculation from image of goal

Quote:
Originally Posted by Rflax40 View Post
Basically it is giving out smaller angles than it should right now. Would the camera being offset ~2 inches from our center of rotation be enough to cause these issues?
Our camera is offset ~5" from the shooter wheel and we don't have that problem. If you're using a calculation that uses the camera's field of view, try increasing the value for the field of view until you get angles that look better. (that's what I did, anyway)

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.
__________________
Head Programmer / Driver
Reply With Quote
  #15   Spotlight this post!  
Unread 21-04-2016, 20:08
Rflax40's Avatar
Rflax40 Rflax40 is offline
Registered User
AKA: Ross Flaxman
FRC #1124 (UberBots)
Team Role: Mechanical
 
Join Date: Jan 2015
Rookie Year: 2011
Location: Avon, CT
Posts: 6
Rflax40 has a spectacular aura aboutRflax40 has a spectacular aura about
Re: Angle Calculation from image of goal

Quote:
Originally Posted by Jared Russell View Post
I will try to post a more detailed explanation tonight, but for now: it affects both coordinates.

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?
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
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:53.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi