r = tr − yoff: Gc = 1K = 1.0371 / s(s+1)(s+2)angle y1Gc = lambda s: (s+0.05)/(s+0.005)2Kv = 1.008 * Gc(0) / 2 # K·Gc(0)/23print(round(Kv, 2)) # 5.04K = 1.037
−3−2−101−2−1012σ, real partjω, imaginary partS-PLANE: ROOT LOCUSζ = 0.5old s*ZOOM ×34 near 0−0.050zeropoleslow0.0010.010.1110−4004080ω (rad/s)dBBODE MAGNITUDE |L(jω)|no lag, K 1.037lag, K 1.0080 dBpole 0.005zero 0.05+20 dBωc ≈ 0.45PM 52° → 47°1/Kv = 1.931/Kv = 0.198030609012000.511.522.5time (s)error (rad)RAMP ERROR e(t) = t − y(t)no lagwith lag
Lit wire with moving dashes: a signal is flowing along itBlocks: ramp command, compare, lag compensator, gain dial K, plant G(s), arm angle; the code card computes KvPlots: root loci on the s-plane (dots = closed-loop poles), Bode magnitude of the open loop, ramp error over timeThe pill travelling into the plant is the new gain KA unity-feedback servo with a lag compensator between the compare block and the gain dial. The lag's pole and zero sit close to the origin, ten times apart, so it multiplies the low-frequency gain (and Kv) by 10 while leaving the root locus near the dominant poles almost unchanged. Re-tuned to K = 1.008 on the ζ = 0.5 ray, the ramp error falls from 1.93 to 0.198 rad, slowly, through a closed-loop pole at −0.055. Rule of thumb: put the lag zero about a decade below the crossover frequency (or about ten times closer to the origin than the dominant poles), and make the zero-to-pole ratio the factor you need in the error constant.

The problem

  1. This servo, G(s) = 1/(s(s+1)(s+2)), was tuned in the lesson "Choosing the gain for a target damping ratio". K = 1.037 puts the closed-loop pair at −0.333 ± 0.577j, damping ratio 0.5. The transient is good.

Add a lag

Check it

The working

# step 1/10 · start
# about: Command: ramp, Compare (error), Gain dial K, Plant G(s), Arm angle y, locus without lag, closed-loop poles

plant       G(s) = 1 / (s(s + 1)(s + 2))
gain        K = 28/27 = 1.037
closed-loop poles  -0.333 ± 0.577j, -2.333
damping ratio      ζ = 0.5

The step response is fine. This lesson asks
a different question: how well does the arm
follow a command that keeps moving?

The plant 1/(s(s+1)(s+2)) is a standard textbook servo model with round numbers. The loci are the exact roots of the closed-loop polynomial for many values of K, the Bode curves are |K·Gc(jω)·G(jω)| point by point, and the ramp errors are integrated from the closed loop (RK4, 0.01 s steps). The Python uses only the standard library. With python-control installed, ct.bode_plot and ct.root_locus_plot on ct.tf([1, 0.05], [1, 3.005, 2.015, 0.01, 0]) draw the compensated loop.