View Single Post
  #7   Spotlight this post!  
Unread 11-02-2013, 12:43
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: |Calculating Distance to targets

The line
Code:
double range = (kTopTargetHeightIn-kCameraHeightIn)/Math.tan((y*kVerticalFOVDeg/2.0 + kCameraPitchDeg)*Math.PI/180.0);
is the same as the formula I provided before, if you substitute y*kVerticalFOVDeg/2.0 for relativeTargetAngle, substitute kCameraPitchDeg for cameraAngle, then convert it to radians before calculating tan() (multiplying by Math.PI/180.0 does this).

This method has some serious advantages over using height and linear perspective; you don't have to worry about distortions or weird angles, and these cameras are pretty accurate when it comes to relative angles. Make sure you use the right values for your horizontal and vertical field of view values though. For the M1011, it has a 47 degree horizontal field of view and this stackexchange question provides a calculation for the vertical field of view yielding about 36.13 degrees.
__________________
I code stuff.