![]() |
Servo Values to Degrees... How?
I don't know if this is because it's very early (4AM in RI) or if I'm just dense :confused: , 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) = %d\r\n", (((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. |
Re: Servo Values to Degrees... How?
Quote:
It works great! |
Re: Servo Values to Degrees... How?
Quote:
-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. |
Re: Servo Values to Degrees... How?
Ah! Thankyou so much. Everything makes sense now. :)
|
Re: Servo Values to Degrees... How?
If this helps at all, I did the math and if a 127 servo value to parrelle to the floor 1.4111111 "servo points" (Values in programming) equals one degree
|
Re: Servo Values to Degrees... How?
I'm not my team's programmer, but I'm trying to help him with some math that we're not sure needs to be done. He hasn't looked at the camera code yet (We are FAR behind, we know), but I was wondering if it was necessary to come up with some sort of relation between camera angle and distance from the light or something like that. We've done some math, but we really don't know what we're doing with it. Since we won't have access to the camera code until this time Monday, I was wondering if you guys could help me out before I fry my brain with all this trigonometry.
Thank you so much. |
Re: Servo Values to Degrees... How?
Quote:
-Kevin |
Re: Servo Values to Degrees... How?
but how can you convert tilt servo values into degrees. sorry, i'm kinda tired, so i might be being dense
EDIT: Would this work? Code:
angle= (TILT_SERVO-STOP)*0.75757575; |
Re: Servo Values to Degrees... How?
So, wait a minute. I wrote this:
unsigned float Find_Distance(void) { float radian; float range; radian = ((((angle I will measure in degrees that the tilt servo has to offer from down to up) / 256) * pi) / 180) * pwm07(which is my tilt_servo pwm); range = (116 - (distance I have yet to measure between the floor and my camera because we haven't placed it yet)) / tan(radian); } I read on another thread that the angle has to be in radians for the Tan() function to take in. Also, I put this in Tracking.c. Does it matter where I place this function? SO, my real questions are, Does anything about what I wrote make sense? And how does this compare to the: pan angle = ((current pan PWM) - (pan center PWM)) * degrees/pan PWM step that was stated earlier in this thread (other than I'm looking for tilt rather than pan) Do I have to subtract my pwm07 by 124 like you did in this one? Sorry if I'm being confusing, but I'm trying to understand all of this at once. I also have questions about why my camera doesn't work PERIOD. It's all hooked up but it seems to not be getting power. Anyway, one thing at a time. Please help me if you can! Thanks |
Re: Servo Values to Degrees... How?
Quote:
Good luck, Robinson |
Re: Servo Values to Degrees... How?
From "The C Library Reference Guide, 1997, Eric Huss" (available online):
2.7.2.9 tanIn short - yes, the angle is in radians (and it should be a double). |
Re: Servo Values to Degrees... How?
This is what I have now, I have no idea if it is going to work. Please help if you can.
My tilt_servo is pwm07, my default MAX for tilt is 194, min is 94, center is 144, step is 50. QUESTION: if I change the step to 25, will it automatically make twice as many steps? will it cut the time in half? how is that programmed. ALSO, DOES THIS MAKE ANY SENSE???? Code:
const rom unsigned short targetRange[] = |
Re: Servo Values to Degrees... How?
Thats an interesting idea. Essentially you prefer to tabulate rather than calculate the tangent. In principle, I have no objections. You can choose whatever step size and range you want for the tracking. Those won't affect the range calculation because they are merely properties of the search algorithm (see tracking.c). You will be taking the pwm value after the search is over and the camera is locked on. I am not sure why you are subtracting 67 from the pwm lookup. Shouldn't it be the tilt min 94?
Jason |
Re: Servo Values to Degrees... How?
Hey, I've been having a problem setting the correct degrees to a variable, even though it prints to the terminal correctly.
pan_angle = (((int)PAN_SERVO - 124) * 65)/124; tilt_angle = (((int)TILT_SERVO - 144) * 25)/50; I have tried making these variables ints, floats, and doubles (they are global static declared in user_routines.h, set in terminal.c, and used in user_routines_fast.c). Would it help if I cast pan_angle and tilt_angle as ints or changed 124 to 124.0? Maybe if I did (int) pan_angle = (int) (((int)PAN_SERVO - 124) * 0.5242); Any help would be appreciated. Thanks! |
Re: Servo Values to Degrees... How?
I would appreciate any help, especially if you had problems using the bells and whistles camera code versus the regular one.
Thanks |
| All times are GMT -5. The time now is 18:25. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi