Finding servo location?

Just as a quick question, seeing as I never got to test my code, would getting the location of the servo be as simple as

printf("Servo Location is... %d\r", pwm01) 

or would I have to do something more to find where it is betweeen 0 and 255…?

that works

printf("Servo Location is... %d\r", (int)pwm01) 

First of all what are you trying to do? If you are setting a value to pwm01 and then printing it out later, this should work. However, you can’t physically read the current position of the servo motor. Neither the hardware or software support this.

wait so there is no way to tell where the camera, like to read what position the tilt servo is at?

You can. Just read the value of the PWM - in Kevin’s code, the position is in the variable TILT_SERVO and PAN_SERVO

If you are using the onboard motor control (PWM) to move the camera servos, you can put that printf right after the line that modifies that outputs value (make sure it is before the PutData !!)

If you are using the servo controller on the camera, you will have to ask the camera for what the current servo value is.

well i tried that in user routines, in the default code funtion. the code compiles just fine but when i add int he comman

int testTest = PAN_SERVO ;
static int testTest = PAN_SERVO;

i get syntax errors
is there a way to access these varible outside of tracking.c?

Paste the whole file where you put this line of code.

alright its attached
its down where it is commented out for the aim up code

user routines.txt (18 KB)

user routines.txt (18 KB)

Don’t you have to declare the variable andrew OUTSIDE the routine?

That might be it, then again, I could be wrong.

(code trimmed out to point out lines in question)

void Default_Routine(void)
int shooter;
// aim up code... WOOT
// ok so find the value of pwm1 to line up the robot.. should be easy enough
static int Andrew = PAN_SERVO;

I thought that was it but shooter is declared…
i will try it out tho

wow alright… so turns out i fail at remembering basic C…
had to declare Andrew at the top of default routines…

Keep in mind this tells you where the servo is being commanded to go, not where it is, in most case they’re synonomous, but if you’re caught on something, or doing a lot of tracking this value could introduce lag which creates oscillations, making it worse, feedback loops, a constantly increasing error, all kinds of bad stuff. Just remember thats where it’s trying to be and 98% of the time it should be there.

Just out of curiosity, is there a better way, then?

Other than having a rotary potentiometer or something on it…

Nope =)

Yes. Since PAN_SERVO is in a #define statement in tracking.h you just need to make sure you include that .h file. Or just directly use pwm01 if that is what your #define is set to.

Please note that the only thing Matt is pointing out are possible error conditions which should not be encountered in normal operation.

  1. Do not command your servo to go into a position where the servo’s movement is physically limited.

  2. Setting the pwm value is where the servo will end up. This is pretty accurate. If you are worried about the speed in which the servo gets to the commanded position versus the speed of your processing loop then use the Hitec specification for the speed of your servo to figure out if you need a delay.