Bode Plots of the Loop and Loop Shaping
A speed controller for the course's small DC motor has to do three things at once: follow speed commands that change a few times per second, hold the speed when a load torque appears, and ignore the encoder's quantisation noise at kilohertz frequencies. Those are three statements about frequencies, and one plot answers all three: the Bode plot of the loop transfer function . This lesson reads that plot the control engineer's way and uses it to shape a PI controller. How to draw Bode plots is in Circuit Theory; here the plot is a design tool.
Why the loop gain says everything
With , the output and the error of the loop in the intro's figure are
Two approximations turn this into a design rule:
| Where | Approximation | Consequence |
|---|---|---|
| (low frequency) | , | tracking error and disturbance effect are divided by |
| (high frequency) | , | sensor noise reaches the output attenuated by ; feedback does nothing there |
| (crossover ) | neither | here can get small: margins decide overshoot and peaking |
So make large where commands and disturbances live, small where noise lives, and cross cleanly in between. The gain-crossover frequency is roughly the closed-loop bandwidth, and the rise time follows from it: for a well-damped loop.
Crossing cleanly. For a minimum-phase loop, Bode's gain–phase relation ties the phase to the slope of : a slope of held for a decade or so around crossover gives about of phase, i.e. a phase margin near ; a slope of gives about , i.e. almost no margin. Loop shaping therefore aims for through crossover, steeper slopes only well away from it. Margins are made precise in Gain and Phase Margins.
Worked example: shaping a PI speed loop
Given: the reference motor (armature voltage to speed), with , , , , . PI controller .
Find: a PI controller with crossover at ; its phase margin; how well it rejects a disturbance at and and how much encoder noise at reaches the speed.
Solve:
- Plant: denominator , poles at and , DC gain .
- Shape: put the PI zero on the slow plant pole, . Then : an integrator ( everywhere below ) with infinite DC gain.
- Gain: gives and .
- Phase margin: .
- Rejection: below crossover: () at , at . Noise: .
Check:
import numpy as np
import control as ct
J, b, Ra, La, k = 2e-6, 1e-6, 2.0, 1e-3, 0.02
G = ct.tf([k], np.polyadd(np.polymul([J, b], [La, Ra]), [k * k]))
p_slow = -max(ct.poles(G).real)
wc = 300.0
s = 1j * wc
Gwc = k / np.polyval(np.polyadd(np.polymul([J, b], [La, Ra]), [k * k]), s)
Kp = 1 / abs(Gwc * (s + p_slow) / s)
C = ct.tf([Kp, Kp * p_slow], [1, 0])
L = C * G
gm, pm, wpc, wgc = ct.margin(L)
print(f"plant poles {np.round(ct.poles(G).real, 1)}, DC gain {ct.dcgain(G):.2f} (rad/s)/V")
print(f"Kp = {Kp:.4f} V/(rad/s), Ki = {Kp * p_slow:.3f} V/rad")
print(f"gain crossover {wgc:.1f} rad/s, phase margin {pm:.1f} deg, gain margin {gm:.3g}")
S, T = ct.feedback(1, L), ct.feedback(L, 1)
for w in (1, 10, 100, 300, 1000, 5000):
print(f"w = {w:5d} rad/s: |L| = {abs(L(1j * w)):8.3f}, |S| = {abs(S(1j * w)):.4f}, |T| = {abs(T(1j * w)):.4f}")
print(f"closed-loop bandwidth {ct.bandwidth(T):.0f} rad/s")plant poles [-1894.4 -106.1], DC gain 49.75 (rad/s)/V
Kp = 0.0575 V/(rad/s), Ki = 6.105 V/rad
gain crossover 300.0 rad/s, phase margin 81.0 deg, gain margin inf
w = 1 rad/s: |L| = 303.738, |S| = 0.0033, |T| = 1.0000
w = 10 rad/s: |L| = 30.373, |S| = 0.0329, |T| = 0.9996
w = 100 rad/s: |L| = 3.033, |S| = 0.3181, |T| = 0.9650
w = 300 rad/s: |L| = 1.000, |S| = 0.7699, |T| = 0.7699
w = 1000 rad/s: |L| = 0.269, |S| = 1.1034, |T| = 0.2964
w = 5000 rad/s: |L| = 0.022, |S| = 1.0205, |T| = 0.0220
closed-loop bandwidth 358 rad/s
The closed-loop bandwidth, , is close to the crossover, as the rule of thumb says. The gain margin is infinite (inf): with this model the phase never reaches , it only approaches it as . Real loops always have more lag (the current loop, the PWM, the sampling delay), so do not believe an infinite margin; Sampled-Data Loops adds the delay that a microcontroller brings.
Intuition with the Bode lab
The Bode lab plots a loop with three real poles. At its defaults (, poles at , , ) it reads a gain crossover of with a phase margin of and a gain margin of . Raise to : crossover , phase margin . At : and only , because crossover has moved onto the and part of the curve. More gain bought speed (and smaller at low frequency) at the price of margin: the central trade-off of loop shaping.
Guided lab: measure the speed loop
Hand calculation. With your motor's measured , and mechanical time constant, place the PI zero on the mechanical pole and choose for a crossover a decade below the PWM and sample rates. Predict the closed-loop bandwidth () and the phase margin.
Simulation. Put your numbers in the program; check at the frequencies of expected load changes.
What you would measure. A small brushed motor on a current-limited supply through an H-bridge, an encoder, and the PI running at on a microcontroller (see Discrete PID). Add a small sine to the speed command ( around ) at , , and and log command and speed. Expect near below , about () near the predicted bandwidth (), within about 20 %: the motor constants have 10 % tolerances and the real loop carries extra delay.
Hazards and safe setup. Current limit about , motor clamped to the bench, no load that can fly off, a stop switch on the driver enable; keep the sine amplitude small so the driver stays out of saturation.
Pitfalls
- Reading the plant's Bode plot instead of the loop's: margins and crossover belong to .
- Treating crossover as the bandwidth exactly: they agree only roughly, and less with small phase margin.
- Asking for crossover beyond the frequencies where the model is trusted (unmodelled resonances, delays).
- Expecting feedback to reduce noise: above crossover passes it, below crossover passes it unchanged.
Practice
- A loop has . What is the error to a sinusoidal command at , approximately?
- Why does the PI design above have a phase margin close to ?
- To halve the disturbance effect at in the example, by how much must grow (same zero), and where does crossover move?
Answer
- of the command amplitude.
- Around crossover behaves like an integrator (, ); the far plant pole at only adds at .
- , so double ; crossover moves to (a little less than , since the pole starts to bend the curve), and the phase margin drops to .
Test yourself
At frequencies where , the sensitivity is approximately
- 1
- 0 dB
Loop shaping aims for which slope of near the gain crossover of a minimum-phase loop?
- 0 dB/decade
- dB/decade
- dB/decade
- dB/decade
In the Bode lab's three-pole loop, raising from 20 dB to 30 dB moved the crossover from 78 Hz to 163 Hz and the phase margin to
Why is it wise to place a PI zero on the slow mechanical pole of a motor speed loop?
- it makes the loop unstable
- the loop becomes an integrator over a wide band, crossing 0 dB at dB/decade
- it removes the need for a current limit
- it doubles the DC gain