PID Tuning
Key Notes
This covers tuning the PID parameters for use with stepper motors. Rose Engine Butler's motors have no encoders, but every axis and spindle still runs a PID loop: the Mesa card's stepgen reports the position it has actually stepped to, and the PID loop (pid.x, pid.z, ... ) closes the loop on that. On this machine FF1 does most of the tracking, with P and I correcting the small remaining error. The gains are set in the Rose Engine Butler Settings program - see Axis and Stepper Motor Tuning (↗ User Manual).
The PID components are named by axis letter: pid.x, pid.z, pid.u, pid.v, pid.w, pid.a, pid.b, pid.c, and for the spindles pid.p0/pid.s0 (Sp0 position/velocity) and pid.p1/pid.s1 (Sp1).
The automatic method is shown first as it is recommended to use. For background, see this Wikipedia article on PID controllers.
Claude AI Notes
Claude is excellent at performing these tasks.
Common Tuning Issues
- High following error: increase P or use feedforward terms
- Hunting or oscillation: add D or reduce P/I values
- Error spikes: reconsider all 3 terms, observe system with a scope, and test combinations.
Automatic PID Tuning Steps
For these actions, N is the name of the PID to be tuned (e.g., pid.x - so the first command becomes halcmd setp pid.x.tune-effort 0.1).
Caution: auto-tuning moves the axis back and forth, and while tune-mode is on the axis's normal control loop is disabled. Make sure the axis has room to move and nothing is in the way.
PID values changed live with halcmd are saved to /home/reuben/Documents/REBset_v1.ini when LinuxCNC shuts down, and will then show in the Settings program.
- Move the axis near the center of travel using either jogging or a Gcode command.
- Set tune-effort to a small value and increase as needed. Open a command prompt and then enter this HAL command:
|
halcmd setp pid.N.tune-effort 0.1 |
- Enable tune-mode and set tune-start to true. Open a command prompt and then enter these HAL commands:
|
halcmd setp pid.N.tune-mode 1 |
- The process generates a square wave for system analysis and determines optimal PID settings.
- After tuning completes, compare the results, and test accuracy.
- pid.N.Pgain
- pid.N.Igain
- pid.N.Dgain
- pid.N.FF0
- pid.N.FF1
- pid.N.FF2
- pid.N.FF3
|
halcmd setp pid.N.tune-mode 0 |
Once those numbers have been obtained, you can use them to manually adjust from there.
Manual PID Tuning Steps
- Begin with very low values for all three gains:
- P (Proportional): Gradually increase P gain until the system starts to oscillate, then back off slightly for stability.
- I (Integral): Introduce I gain to reduce steady-state error, but too much can lead to instability.
- D (Derivative): Add D gain to dampen oscillations and improve responsiveness.
- Optionally adjust feedforward to further reduce error.
- FF0 (0th order feedforward gain).
- For position loops, it should usually be left at zero.
- For velocity loops, FF0 can compensate for friction or motor counter-EMF and may permit better tuning if used properly.
- FF1 (1st order feedforward gain) - affects Velocity.
- For position loops, the contribution is proportional to speed, and can be used to compensate for friction or motor CEMF.
- For velocity loops, it is proportional to acceleration and can compensate for inertia.
- FF2 (2nd order feedforward gain) - affects Acceleration.
- For position loops, the contribution is proportional to acceleration, and can be used to compensate for inertia.
- For velocity loops, the contribution is proportional to jerk, and should usually be left at zero.
- FF3 (3rd order feedforward gain)
- For position loops, the contribution is proportional to jerk, and can be used to compensate for residual errors during acceleration.
- For velocity loops, the contribution is proportional to snap(jounce), and should usually be left at zero.
- FF0 (0th order feedforward gain).
Additional Resources
Websites
LinuxCNC Manual
LinuxCNC Forum
Other
Videos
- PID tuning linuxcnc Chinese servos (YouTube video)
|
eMail comments to |
