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!
- 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!