go_away

Author Topic: [SOLVED] Weird PID/PWM behaviour using webbotlib  (Read 1176 times)

0 Members and 1 Guest are viewing this topic.

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 364
  • Helpful? 10
[SOLVED] Weird PID/PWM behaviour using webbotlib
« on: June 16, 2011, 11:49:39 AM »
Hi all,

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:

Code: [Select]
//...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.

So, clearly:

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?

MIKE

**EDIT: got the code blocks working
« Last Edit: June 16, 2011, 12:23:49 PM by mstacho »
Current project: tactile sensing systems for multifingered robot hands

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 364
  • Helpful? 10
Re: Weird PID/PWM behaviour using webbotlib
« Reply #1 on: June 16, 2011, 12:13:37 PM »
Oops, sorry for that post, it was actually just me being an idiot.  I had connected the "MOTOR_DIRECTION" pins and "MOTOR_PWM" pins backwards, so in reality PWM was never being used :-P

MIKE
Current project: tactile sensing systems for multifingered robot hands

 


Get Your Ad Here

data_list