I have a REALLY weird problem going on. My guess is that it has nothing to do with webbotlib, mainly because this exact code worked *perfectly* fine before I re-built my robot. I hadn't changed the code at all.
Here is the problem: I have motors hooked up to quadrature encoders, which are used for PD control through PWM using an Axon. I want to set the target of one motor to, say, 100 (out of a possible 600 counts on the encoder). I do this:
//...initialize bottom motor, PID, PWM, etc...
//read the encoder
pidSetTarget(&bottomPID,200.0); //set the target
encoderRead(quad1); //quad1 is connected to the motor
enc1 = pidSetActual(&bottomPID,quad1.encoder.value); \\get the PID output
//and now the actual control happens
pwmSetDutyCycle(f1m1PWM,(int)enc1); //bottom motor
So all this should do is: set the target for the PID, read the encoder, evaluate the error, and move the motor (and yeah, I account for a negative output and all that. this is just a code snippet).
What actually happens is this: the motor doesn't move at all initially. There is no sound that indicates PWM is on (which is usually a high-pitched whine as the switching happens). If I move the motor by hand, there will be no resistance -- until I get to the right encoder value, at which point the control kicks in, PWM turns on, and the motor starts resisting attempts to move it from the position.
a) my wiring is right, since it actually is powering the motor eventually
b) pwm is working
c) in theory, PID is also working
somehow, the PID error does not set the PWM until the encoder gets to the right position in the first place. I tossed an rprintf on it to see if the error wasn't working, but all the readings are entirely correct. The PWM is just not turning on...at first :-P
Why does the PWM turn on only after the motor has been moved by hand? Does this make ANY sense?
**EDIT: got the code blocks working