Tune the controllers
4 minute read
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:
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.
Warning
A wrong gain or a wrong sign makes the axis oscillate or run away. Tune with the axis free to move, a low velocityLimit on the limiter, and a hand on the emergency stop.
Before you start
- 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.
- Limit the output. Set
controlOutputMinandcontrolOutputMaxto the largest correction you allow: a velocity in rad/s or m/s, or a torque in Nm. - Start from P only. Set
proportionalGainsmall,integratorGainandderivativeGainto0, and leavecontrolIntegrationMinandcontrolIntegrationMaxat0,0. - 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:
- Raise the P gain. Double
proportionalGainafter every test move, until the axis starts to hum, vibrate or overshoot. Then halve it. That is your P gain. - 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
controlIntegrationMinandcontrolIntegrationMaxto a small part of the output range, for example ±20 %. Then raiseintegratorGainfrom a small value until the error goes away without extra overshoot. - Damp if needed. A derivative part is rarely needed. If the position loop still overshoots, add a small
derivativeGainand keepderivativeFilterlow, see below. - Check faster moves. Jog faster, and look for saturation: an output that sits flat at
controlOutputMinorcontrolOutputMax. - 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 × dteach cycle, and is held betweencontrolIntegrationMinandcontrolIntegrationMax. These limits are in the output’s unit, so at0,0the integral part stays0. Errors smaller thancontrolErrorDeadBandare not integrated. While the output is at a limit, the integral part does not grow further in that direction, andbackCalculationGainpulls it back. - D:
derivativeGaintimes the change ofeper second, smoothed by a low-pass filter.derivativeFilteris the filter’s corner frequency in rad/s: a lower value smooths more. At0the derivative part does nothing. Keep it well below1/dt, for example below1000at a 1 ms cycle.
The sum of the three is limited to controlOutputMin and controlOutputMax.
Next: Step 4: set up the mechanism.