Quick way to tune Servo/Position PID controller

I recently learnt an easy way to tune a servo loop, which has been working pretty well for me. Here is a summary of the steps:

  • The first step is to have a robust current controller. This can be a properly tuned PID controller, with Sinusoidal Field Oriented, 120-Degree Trapezoidal or any other type of control.
  • Next, you need a simple PD controller for the position loop, which would essentially have these three lines of code:

Error = Reference – Feedback;
Output = Kp*Error + Kd*(Error-OldError);
OldError = Error;

  • Once done with coding, run your controller with Kp and Kd set to zero. Slowly, increase Kd and feel the how the rotor reacts when you try to rotate it by hand. You would see that the rotor seems to resist rotation and feels as if it is immersed in some viscous liquid. Keep increasing Kd till it is sufficiently high, without making the controller go unstable or generate any audible noise.
  • You can then increase Kp as you see fit, depending on how sharp or slow you want the response to be. With the high Kd you set in the previous step, the controller is less likely to go unstable due to high Kp values. That’s it. You ‘ll have a nicely tuned servo loop!

Debug tips:

  • It is really important to have a good current controller before you start implementing the position controller.
  • If the rotor doesn’t rotate smoothly during Kd tuning, double check your encoder alignment, commutation sequence, etc.
  • Make sure you have the correct signs for calculating error and Kd component in your code.
  • Check the order of motor wires.
  • Keep things simple!

Texas Instruments InstaSPIN™ – Mind. Blown.

After unsuccessfully spending days on a STM32 evaluation kit to get their motor control firmware up and running, I was pleasantly surprised by the Three Phase BLDC Motor Kit with DRV8312 and Piccolo MCU from Texas instruments. And I was blown away by their InstaSPIN™-BLDC Solution. I could set up everything and have the motor running in under an hour.

This video by Dave Wilson is the most comprehensive and clear motor controller demo I have ever seen.

The beauty of InstaSPIN is its ability to run almost any motor – it instantly ran the motor that came with the STM32 Evaluation kit, and also ran couple of motors my friend found from a surplus store – there is no change in the code necessary – all you need to do is change the flux threshold value in the GUI.

Another impressive feature is how robust the control system is, even at very low duty cycles. Less than 10% duty cycle without sensors? InstaSPIN does.