Tune the controllers

Find gains that make an axis follow its target closely, step by step, with the plots to watch and what each symptom means.

Tuning sets the gains of the controllers so that an axis follows its target quickly, without overshoot or oscillation. You make the same small move again and again, watch the plot in Motorcortex Desk, and change one gain at a time until the response looks like the middle one:

Gain too low slow, lags behind About right fast, little overshoot Gain too high overshoots and rings

Work from the inside out: when you use both controllers, tune the velocity controller first. The position loop can only be as good as the velocity loop inside it.

Before you start

  1. Check the settings in simulation. Switch the controllers you need on, as in the table, and check that the axis moves the right way. Then tune the gains on the real machine, with its real load and friction.
  2. Limit the output. Set controlOutputMin and controlOutputMax to the largest correction you allow: a velocity in rad/s or m/s, or a torque in Nm.
  3. Start from P only. Set proportionalGain small, integratorGain and derivativeGain to 0, and leave controlIntegrationMin and controlIntegrationMax at 0, 0.
  4. Pick a test move you can repeat: jog the axis a short distance back and forth at low speed.

What to plot

Plot these in Desk, for the axis you tune. They are under root/AxesControl/actuatorControlLoops/actuatorControlLoopNN/:

Plot Shows
actuatorVelocityTarget and actuatorVelocityActual How well the velocity follows. Plot them on the same axis
actuatorPositionTarget and actuatorPositionActual How well the position follows
actuatorVelocityError, actuatorPositionError The error the controller works on
velocityController/output/controllerOutput, positionController/output/controllerOutput What the controller adds. Flat at a limit means it is saturated
…/output/integratorOutput The integral part on its own

Tune a controller

Use the same steps for each controller, starting with the velocity controller:

  1. Raise the P gain. Double proportionalGain after every test move, until the axis starts to hum, vibrate or overshoot. Then halve it. That is your P gain.
  2. Remove a steady error. If a small error remains when the axis stands still or moves at a constant speed, allow the integral part: set controlIntegrationMin and controlIntegrationMax to a small part of the output range, for example ±20 %. Then raise integratorGain from a small value until the error goes away without extra overshoot.
  3. Damp if needed. A derivative part is rarely needed. If the position loop still overshoots, add a small derivativeGain and keep derivativeFilter low, see below.
  4. Check faster moves. Jog faster, and look for saturation: an output that sits flat at controlOutputMin or controlOutputMax.
  5. Save the parameter tree. Every axis has its own gains; tune each one.

Read the plot

What you see Likely cause What to change
The actual value lags behind, more at higher speed P gain too low Raise proportionalGain
Overshoot, then ringing P gain too high Lower proportionalGain
Humming, or a noisy controllerOutput P or D gain too high for the noise on the actual value Lower proportionalGain or derivativeGain, lower derivativeFilter
A small error that stays No integral part Widen controlIntegrationMin and controlIntegrationMax, raise integratorGain
A slow, large overshoot after a long move The integral part built up too far Narrow the integration range, lower integratorGain, or raise backCalculationGain
controllerOutput flat at a limit The output is saturated Move slower, or widen controlOutputMin and controlOutputMax if the axis can take it
The error keeps growing and the axis runs away Wrong sign Stop, and check the direction of the transformations
How the three parts are calculated

Every control cycle, with e the control error and dt the cycle time:

  • P: proportionalGain × e.
  • I: adds integratorGain × e × dt each cycle, and is held between controlIntegrationMin and controlIntegrationMax. These limits are in the output’s unit, so at 0, 0 the integral part stays 0. Errors smaller than controlErrorDeadBand are not integrated. While the output is at a limit, the integral part does not grow further in that direction, and backCalculationGain pulls it back.
  • D: derivativeGain times the change of e per second, smoothed by a low-pass filter. derivativeFilter is the filter’s corner frequency in rad/s: a lower value smooths more. At 0 the derivative part does nothing. Keep it well below 1/dt, for example below 1000 at a 1 ms cycle.

The sum of the three is limited to controlOutputMin and controlOutputMax.