View Single Post
  #3   Spotlight this post!  
Unread 21-01-2006, 11:57
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Servo Values to Degrees... How?

Quote:
Originally Posted by mogunus
I don't know if this is because it's very early (4AM in RI) or if I'm just dense , I can't for the life of me figure out how to convert from the cmucam servo's values to degrees. I know that in terminal.c keven does what's explained by this comment:

// pan angle = ((current pan PWM) - (pan center PWM)) * degrees/pan PWM step
printf(" Pan Angle (degrees) = %drn", (((int)PAN_SERVO - 124) * 65)/124);

To get the pan angle of the camera. I have no idea how this works, or why.

This is a problem for me, because I just finished implementing a feed-forward-ish style tracking algorithm, based on kevin's original code. I got the idea for it from his post here, and there's another great thread about it here.

I'm definately getting better results from the camera. At least, it looks like it's tracking the light better than before at approx 8 ft. distant in my room, have to test that on the 'bot tomorrow.

But the problem is, my code totally broke going from the servo values to degrees in terminal.c. I know that 128 is the "y-axis." So should I just grab a protracter, and "sv 0 whatever" until it looks like there's a 90 degree difference between the position at 128 and the current position, and divide (current - 128)/90 degrees travelled? And would that give me proper degrees/single servo pwm value?

Sorry if that was all really incoherant. Any help would be greatly appreciated.
The first part of the equation, PAN_SERVO - 124, converts the PWM to a signed value where positive PWM values are on one side of the zero point(124) and negative PWM values are on the other side. The second part, * 65/124, converts PWM angular units to degrees. I measured a rotation of 65 degrees when I commanded the servo to rotate from 0 to 124 in PWM units, which means for every PWM unit increase, the servo rotates 65/124 degrees. Because I'm using integer arithmetic, I use the parentheses to tell the compiler the order I want the operations to take place to prevent over/underflow of the variable and maximize precision. Consider what would happen if you took the same expression, but put parentheses around the 65/124 expression (answer below).

-Kevin



Answer: 65/124 when evaluated using integer arithmetic is converted to zero, making the entire expression equal to zero no matter what PWM value is plugged in.
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org

Last edited by Kevin Watson : 21-01-2006 at 16:17. Reason: Spelling error.