The nice thing about making your own PID controller, is that it's easily modified to add extra features. The nice thing about having PC software development skills, is that it's easy to whip up a small program for a particular task.
I've mentioned on a number of occasions, that I hadn't yet tuned the PID settings in my controller. I didn't want to do this because I could spend all day tinkering with values without being able to accurately judge the exact effect. What I needed was a way to monitor the servo response.
It took less than a dozen extra lines of microcontroller code, and a couple of dozen lines of C# (WinForms) to make a GUI application to test and monitor the servo. Once I had this, I could change values and with a mouse-click see the results. This made it very quick to tune by trial and error.
|

Step response before tuning
|

Step response after tuning
|
The best "simple" explanation I've heard for these values are:
-
P - Proportional - Spring - The greater the error, the more correction applied
-
I - Integral - Accuracy - The longer the error, the more correction applied
-
D - Derivative - Dampening - The more the error changes, the more correction applied
The best "simple" tuning method I've heard is:
-
Set P, I & D gain values to 0.
-
Increase P until it becomes unstable (post-step oscillations don't fade).
-
Halve P.
-
Increase D until overshoot is removed.
-
Increase I until it settles quickly enough when disturbed
I used this method and it appears to work well, but this was a simple test on an unloaded motor. It will be interesting to try this once fitted to a more complicated system.
There is an issue with the current test... this a step-response scenario. That's great for a system which needs to move from A to point B as quick as possible. But in a CNC machine, it doesn't just move from one point to another. The motion controller (e.g. Mach3 or EMC2) will produce "smooth" motion with a constant stream of position updates. What is more important, is that the servo accurately follows this acceleration, than achieve high outright point to point speed.
In the future, I think I'll need to add a "Curve Follower" tuning option. Instead of jumping from point to point, this will drive the servo as if it was tracing a circle (a sine wave pattern).