Please help: PID position control of Futaba RC Servo, QEI feedback

25 Apr 2012

I wondered if any of you good people could help please?

I’m trying to build a PID position control system using the MBED standard PID block. I’m not sure whether the algorithm is suitable for position...maybe you can advise me.

Sensor: 4096 ppr optical encoder using QEI object Actuator: Futaba 6v RC servo (PWM input on 20ms cycle)

PID constants (Gain 0.01, Ti, 0.1, Td 0.01) RATE = 0.1 seconds I can get the PID tuned without passing to PWM (to a fashion, but is is still a little shaky). I was wondering whether to pass the CV through an FIR filter??? Since the PID has a cycle of 0.1 seconds and the servo has a cycle of 20ms I can’t find a happy medium in terms of program loop time. Do I need an RTOS to schedule tasks? I don’t understand RTOS, is there a simpler method?

I realise that my PID needs a faster RATE, but this will make my PWM impossible. Is it possible to access the DEAD BAND of the MBED PID? I notice there is a BIAS method. Do you think the MBED PID object is suitable for my task? On the encoder, which works a treat; does anyone know the maximum pulse count? Could this be 2^32? And can this be made quadrature ie divide counts by 4?

Best wishes

Craig

26 Apr 2012

Sorry folks, have I asked too much. Should I maybe fragment this?

Cheers

Craig

26 Apr 2012

I don't really understand.. Most common servos implement all of this internally (i.e. give specific duty cycle and servo goes to that position on its own) Are you using a continuous servo?

But anyway, welcome to the wonderful world of PID tuning :)

First off, I would suggest using a PI or just proportional control (i.e. turn off the derivative and keep the integral part low). This will limit the possibility of starting off with an unstable system. Once you are certain your servo is stable, you can start incrementing the P and I constants for faster response. In my experience, the derivative component is more trouble than its worth and does not add a lot of benefit. If you do opt in for using full PID, noisy feedback may be a problem with the D component.

For the most part, the PWM and PID rate are unrelated. Remember, the PWM is taken care of by the mbed. The output of your PID should be scaled from 0.0-1.0 and (centered at 0.5, I assume..). This is what will be used to control the duty cycle output of the mbed. That being said, there is no real benefit of running your PID routine much faster than the PWM frequency. If the PID runs too fast, the PID will end up waiting for the PWM cycle to complete (i.e. for the servo to register an input command and start moving) which will require slower tuning but may result in a smoother operation if tuned correctly.

You also do not need any sort of RTOS. You can use the mbed Ticker to schedule your PID routine at the desired period.

The limit of the pulse count should not be an issue. If you are using a quadrature encoder, this would be an issue only if you drive in one direction for a (very) long time. Either way, I imagine the count would be a 32 bit unsigned int which should give you plenty of room.

If you can't change the deadband, you can create your own deadband function that then feeds into the PID.

I hope that helps!