PID tuning in LinuxCNC

There are many articles about PID tuning in general and about LinuxCNC in particular. For example, here is a good article about PID tuning and man page with more nitty-gritty details or even source code with the most intimate details. That is why below will be only my personal experience together with a couple practical tips which might be useful… or not.

Metrics to collect

There are tons of metrics, however, below are most valuable for PID tuning:

Documentation and AI

Use documentation and any available AI. Ask any AI is a good start point. Then, do the test run, collect resulted charts as halscope.csv (there is an option to export the charts) and feed it into AI again to obtain PID values and tips for the next iteration. Not always, but AI might provide useful hints.

PID tune

Pick max expected feed rate and pretty distant target position. For example, 1000mm/s and 20mm distance. Place <board_name>.encoder.00.velocity over joint.X.vel-cmd to clearly see how actual velocity follows the command. And select a proper scale for joint.X.f-error to see small oscillations.

Then, do the following steps:

  1. If you have configured BACKLASH - remove it. It will make PID tuning harder. You can return it back after the PID tweak.
  2. Set DEADBAND in ini file to scale of the encoder. 0.005 in my case.
  3. Set FF1 to 1 and pick a really high P. For example, 1000. Do a movement and check joint.X.f-error. There should be huge oscillations, especially in the end of the path.
  4. Reduce P until oscillations will be acceptable. Not so big as in point 1, but still noticeable. In my case it was ~50.
  5. Add a bit I. Try something between 0.1 and 1.0. Aim: oscillations should disappear, but overall velocity should be on expectable level. If I is too high, velocity will be low. Kinda too smooth movement.
  6. If unable to remove oscillations, and keep a proper velocity - increase D. Usually less than 1.
  7. If you have a clear pattern in f-error after all tweaks - ask Google and/or AI. There are many threads on LinuxCNC forum with fixes for different border cases.

Resulted configuration

I found two working PIDs for my machine:

Other notes