Speed and position closed-loop servo drive modes
Due to memory constraints, extended modes are not always available. If you do not see folder /driver/pid_speed or /driver/pid_position, the extended modes are not present in your firmware.
If one of these bits is specified in the requested drive mode, the PID loop is activated. We call these "extended" modes.
| Bit | Dec | Name | Reference value |
|---|---|---|---|
| 4 | 16 | Speed loop | rref |
| 5 | 32 | Position loop | pref |
Drive mode = 17: The speed PID loop is active. The motor is driven in voltage mode (17 - 16 = 1)
Drive mode = 34: The position PID loop is active. The motor is driven in current mode (34 - 32 = 2)
Parameters
For /driver/pid_speed and /driver/pid_position : both folders contain the settings for the corresponding PID regulator.
| Parameter | Description |
|---|---|
P | Proportional term for the PID regulator |
I | Integral term for the PID regulator |
D | Derivative term for the PID regulator |
Td | The time constant for the input filter for the D term. The D term is sensitive to noise, using the filter can help to reduce the noise. |
The Td parameter is LPF (low-pass filter) time constant. More about it.
Tuning the loops
Tune one loop at a time, on a test stand where the motor can spin freely, with
conservative iref and rref limits. Small steps, one parameter at a time.
Start from a well-tuned current loop. The speed and position loops act on
top of the current control, which must be fast and stable first. Its
pid_iq / pid_id gains are identified automatically by identlin; re-run it
whenever the motor or the supply voltage changes substantially.
Apply a step and watch the response. Command a moderate step in rref (or
pref) and observe /driver/motor/rpmf (or the position readback). The
textbook criteria apply: rise time, overshoot, settling, and steady-state error.
Any of the standard methods gives a usable starting point:
- Manual (heuristic) tuning - raise
Puntil the response oscillates, back off to roughly half of that value, addIuntil the steady-state error disappears, then add a littleD(withTdset so the derivative does not amplify sensor noise) to damp the overshoot. - Ziegler-Nichols - find the ultimate gain
Ku(thePat which the loop sustains a constant oscillation withI=D= 0) and the oscillation periodTu, then take the tabulated fractions ofKuandTufor a P, PI or PID controller. The Tyreus-Luyben variant uses the sameKu/Tuwith more conservative fractions and suits loads that must not overshoot. - Cohen-Coon - derive the gains from an open-loop step response (process gain, dead time and time constant); useful when a closed-loop oscillation test is not acceptable on the machine.
- Relay (autotuning) test - the modern form of Ziegler-Nichols: a small
bang-bang excitation around the setpoint yields
KuandTuwithout driving the loop to the stability limit.
Textbook formulas express the integral and derivative action as time constants
(Ti, Td) in seconds; the driver's I and D are gain terms. Use the methods
for the procedure and for the ratios between the terms, then scale the
absolute values by experiment on the step response. Validate the final set at
several speeds or positions, with and without load, and in both directions.
Both loops leave saturation as soon as the error allows it, with no windup delay.
That recovery is carried by the integral action, so I is a working part of the
controller rather than a refinement on top of a P-only loop. Running a loop with
I = 0 is possible, but it changes what the loop regulates: after a saturation
event it holds the change in the measured value since the loop was engaged
instead of converging on the reference.
For the position loop this means the motion stops after
delta = 1 / P electrical radians, which is 1 / (P * 2 * PI * rpole) motor turns
regardless of pref; halving P doubles the distance travelled. This can be
used deliberately as a "move by 1/P" behaviour. For reference tracking, keep I
non-zero, including during the first step of a tuning session.
A loop saturates on its very first evaluation whenever P * err exceeds 1; for
the position loop engaged with a step command that is P * 2 * PI * pref * |cmd| > 1,
which is easy to meet with a large pref. Ramp cmd, or use a motion profile,
so the loop is not presented with a full-scale step.