← Back to Autonomy
Control Systems · Field Guide No. 1 · By Majid Mazouchi

Loop Engineering
measure → compare → correct → repeat

How feedback loops are designed, shaped, and debugged — explained in plain words, with block diagrams, two interactive labs you can play with, and the practical rules that keep real loops alive on real hardware.

A control loop is the simplest powerful idea in engineering: measure what the system is doing, compare it with what you want, and push back against the difference — thousands of times per second. Loop engineering is the craft of making that cycle fast enough to be useful, calm enough to be stable, and tough enough to survive noise, delays, and a plant that never matches its datasheet.

The same loop runs your home thermostat at one decision per minute and the current controller of a traction motor at 10,000 decisions per second. Only the speed changes — the anatomy is identical.

setpoint r Σ e = r − y Controller Plant output y Sensor − y the loop closes ~100–10,000×/s
§ 01

What a loop is (and isn't)

Suppose you want a motor to spin at exactly 3,000 rpm. The open-loop way is to look up how much voltage usually gives 3,000 rpm, apply it, and hope. It works until the load changes, the magnets warm up, or the supply sags — and then the speed drifts and nothing notices.

The closed-loop way is to measure the actual speed, subtract it from 3,000 rpm, and let that difference — the error — decide the voltage. If the motor slows under load, the error grows and the controller automatically pushes harder. Nobody recomputed anything; the loop self-corrects.

OPEN LOOP — act, then hope command Lookup / gain Plant output drifts disturbance hits — no one reacts CLOSED LOOP — act, measure, correct Σ Controller Plant output holds same disturbance — loop pushes back measurement (the loop)
Fig. 1 — Open vs. closed loop. The only structural difference is the blue wire. That wire buys disturbance rejection and accuracy — and introduces a brand-new failure mode: instability. Loop engineering is the management of that trade.
The core trade in one sentence

Feedback turns "how well do you know the plant?" into "how fast can you measure and react?" — but the price is that an over-eager loop can chase its own tail and oscillate. Everything below is about buying speed without losing stability.

§ 02

Anatomy of a real loop

Textbook loops have three blocks. Real loops have at least six, and the extra ones are where the trouble lives. The diagram below shows where the real world injects itself: a load disturbance d entering at the plant input (load torque, supply sag, a hill), and measurement noise n entering at the sensor (quantization, EMI, resolver ripple).

r setpoint Σ e = r − y_m Controller C(s) PID, lead-lag, … u Actuator sat. ± limits, delay + d load disturbance Plant P(s) the physics y true output Sensor + filter H(s) + n sensor noise y_m measured output
Fig. 2 — The loop you actually ship. The two dashed red arrows are the enemies. A good loop must reject d (which wants high loop gain at low frequency) while ignoring n (which wants low loop gain at high frequency). That conflict is the whole game.

The vocabulary, in plain words

TermPlain meaningIn a motor drive
Setpoint rWhat you wantTorque / current command from the driver's pedal
Error eHow wrong you currently arei*q − iq,measured
Controller CThe recipe: error in, effort outPI current regulator in the ISR
ActuatorThe muscle (always limited)Inverter — voltage clamps at the DC-link hexagon
Plant PThe physics you don't fully controlStator R-L dynamics, back-EMF, mechanics
Sensor HThe eyes (delayed, noisy, quantized)Current shunts + ADC, resolver/encoder
BandwidthHow fast the loop can usefully respondCurrent loop ≈ 1–3 kHz; speed loop ≈ 50–200 Hz
§ 03

The loop gain L(s) — one curve that decides everything

Walk once around the loop and multiply what you pass through: controller × plant × sensor. That product is the loop transfer function:

L(s) = C(s) · P(s) · H(s)

Almost every property of the closed loop can be read off the frequency response of this single curve. Loop engineering is often literally called loop shaping: you bend |L(jω)| into the right profile.

Margins: how close to the cliff you're standing

A loop goes unstable when the signal coming back around arrives as large as it left and exactly inverted — then the loop feeds itself. Margins measure your distance from that condition:

Why delay is the universal villain

A pure time delay Td costs phase linearly with frequency: φ = −ω·Td (radians), with no change in gain. Every sample period, ADC conversion, PWM update, filter, and bus hop eats phase margin at your crossover. This is why "just filter the noise harder" so often destabilizes a loop: the filter's lag spends the phase budget you were living on.

§ 04 · Interactive

Lab A — Crossover & margin explorer

Below is a classic loop: an integrator (for zero steady-state error) plus two lags (actuator + sensor dynamics): L(s) = K / [ s (0.5s+1)(0.1s+1) ]. Drag the gain. Watch the crossover slide right (faster loop), the phase margin shrink, and the step response start to ring. Around K ≈ 12 the gain margin hits 0 dB and the loop becomes a sine-wave generator.

Lab A · live simulation

One knob, three consequences

Crossover ω_c
Phase margin
Gain margin
Verdict
|L(jω)| in dB vs. frequency (log). Orange dot = crossover. Dashed line = 0 dB.
Closed-loop step response y(t). Dashed line = setpoint.
output y setpoint
What to notice

Speed and stability are the same knob viewed from two sides. K = 2 is calm but lazy; K = 7 is fast but rings; K = 12 oscillates forever. A loop engineer doesn't ask "what gain?" — they ask "what crossover frequency does the application need, and do I have the phase budget to afford it?"

§ 05

Sensitivity & the waterbed effect

Two transfer functions summarize what the closed loop does to the outside world, and they are locked together:

S(s) = 1 / (1 + L) ← error/disturbance amplification T(s) = L / (1 + L) ← reference & noise tracking S + T = 1, always

Worse, for most real plants Bode's integral says the area of log|S| below 0 dB must be balanced by area above it: push the sensitivity down at low frequency and it pops up somewhere in the mid band — like pressing on a waterbed. That bump (peak of |S|, written Ms) is your fragility. Keeping Ms ≤ 1.6–2.0 is a standard, very practical robustness spec. Lab A plots |S| live so you can watch the bed squirm:

Lab A continued · sensitivity view
|S(jω)| in dB for the current gain K (blue) vs. K = 2 baseline (gray). Watch the mid-band hump grow as you raise K in Lab A — that's the waterbed paying you back.
Peak sensitivity Ms
§ 06 · Interactive

PID in plain words — and a sandbox to break it

Over 90% of industrial loops use PID or a subset of it. Each term answers a different question about the error:

TermQuestion it answersPlain-words behaviorToo much of it
P — proportionalHow wrong am I now?Push in proportion to the error. The workhorse.Ringing; never quite reaches target alone
I — integralHow wrong have I been lately?Keep nudging while any error persists → zero steady-state errorSluggish recovery, windup, slow oscillation
D — derivativeWhich way is the error heading?Brake early when approaching the target → dampingAmplifies sensor noise; chatters the actuator
u(t) = Kp·e(t) + Ki·∫e dt + Kd·de/dt (D implemented on the measurement, through a filter)

The lab below runs a live plant — two lags plus a transport delay, P(s) = 2·e^(−0.1s) / [(s+1)(0.3s+1)] — with a setpoint step at t = 0.5 s and a load disturbance kicking in at t = 8 s. Tune it. Then enable actuator saturation and watch integral windup ruin your day — and anti-windup fix it.

Lab B · live PID playground

Tune the loop, then survive the disturbance

Overshoot
Settling (±2%)
Dist. dip @ t=8s
Steady-state error
Output y(t) — setpoint step at 0.5 s, load disturbance at 8 s (red marker).
Control effort u(t). With saturation on, the gold band shows the ±3 actuator limit.
output y setpoint r effort u disturbance onset

Experiments worth running

§ 07

Cascade loops — loops inside loops

Real systems rarely use one loop. They nest them: a fast inner loop tames the messy fast physics and presents a clean, simple "virtual plant" to a slower outer loop. The canonical example is field-oriented control of a PM machine:

speed loop ~100–200 Hz current loop ~1–3 kHz ω* speed cmd Σ Speed PI → iq* (torque) Σ Current PI (dq frame) Inverter SVM + delay PMSM R-L + EMF torque, ω measured iq (shunt + ADC) measured ω (resolver / encoder)
Fig. 3 — Cascade structure of an FOC drive. The current loop's only job is to make "commanded torque = delivered torque" look instantaneous to the speed loop. A position loop (servo, steering) would wrap a third ring around this one at ~10–30 Hz.
§ 08

Practical notes from the trenches

§ 09

A loop engineering workflow

The order matters. Most loop debugging pain comes from doing step 6 before steps 1–5.

1. Define spec:bandwidth, Ms,disturbance size 2. Identify plantstep / relay /freq sweep 3. Audit delays& noise; set thephase budget 4. Shape L(s)pick ωc, designC, add feedfwd 5. Verify marginsPM, GM, Ms insim + worst case 6. Commissionsoft limits, logr, y, u, e 7. Stress & guardtemp, load, aging;monitor margins iterate — specs and plants both drift
Fig. 4 — The workflow. Steps 1–3 are paperwork and measurement, not glamour — and they decide whether step 4 is even possible.
§ 10

References & further reading

  1. K. J. Åström & R. M. Murray, Feedback Systems: An Introduction for Scientists and Engineers, 2nd ed., Princeton University Press, 2021. Freely available online — the best plain-language treatment of loop shaping, sensitivity, and fundamental limits. fbswiki.org
  2. K. J. Åström & T. Hägglund, Advanced PID Control, ISA, 2006. The definitive practical PID reference: anti-windup, filtering, bumpless transfer, relay autotuning.
  3. S. Skogestad, "Simple analytic rules for model reduction and PID controller tuning" (SIMC), Journal of Process Control, 13(4), 2003. Three plant numbers in, near-optimal PI/PID gains out.
  4. S. Skogestad & I. Postlethwaite, Multivariable Feedback Control: Analysis and Design, 2nd ed., Wiley, 2005. Loop shaping, S/T trade-offs, and robustness done rigorously.
  5. G. F. Franklin, J. D. Powell & A. Emami-Naeini, Feedback Control of Dynamic Systems, 8th ed., Pearson, 2019. The standard undergraduate path: Bode design, margins, digital implementation.
  6. J. C. Doyle, B. A. Francis & A. R. Tannenbaum, Feedback Control Theory, Macmillan, 1992 (free online). Short, sharp treatment of S+T=1, Bode integrals, and why the waterbed cannot be drained.
  7. H. W. Bode, Network Analysis and Feedback Amplifier Design, Van Nostrand, 1945. Where gain/phase margins and the integral constraints were born — telephone amplifiers, not motors, but the same loops.
  8. R. D. Lorenz, T. A. Lipo & D. W. Novotny, "Motion control with induction motors," Proceedings of the IEEE, 82(8), 1994 — and any modern FOC text (e.g., Mohan, Advanced Electric Drives) for the cascade current/speed architecture of §07.
  9. G. Ellis, Control System Design Guide, 4th ed., Elsevier, 2012. The practitioner's bench book: delays, filters in the loop, resonance, and servo commissioning checklists.