The plant
A small DC motor spins a flywheel. Our job: hold it at 1 rad/s (radians per second, about 9.5 turns a minute), even when something drags on the shaft. We go the whole way: model, tune, then the snags textbooks skip.
Voltage V drives current i through the winding (R = 1 Ω, L = 0.5 H); the spinning rotor pushes back with K·ω. Current makes torque K·i, which turns the rotor (inertia J = 0.01 kg·m²) against friction b·ω (b = 0.1 N·m·s).
Laplace-transform both and remove i: ω/V = 0.01 / (0.005s² + 0.06s + 0.1001). Its poles (the motor's natural decay rates, 1/0.5 s and 1/0.1 s) are −2.0 and −10.0: overdamped, no overshoot. One volt gives 0.0999 rad/s, so we fix 10.01 V.
At 2.5 s a brake puts 0.01 N·m of drag on the flywheel. The voltage stays at 10.01 V because nothing measures the speed, so the motor slows to 0.90 rad/s and stays there. That 10 % loss is a disturbance.
Textbook tuning
An encoder measures the shaft speed and the controller computes the error e = 1 − ω every millisecond. Our specs for a 1 rad/s step: settle within 2 s, overshoot under 5 %, steady error under 1 %.
Try V = 100·e. The speed overshoots by 25.3 % and settles at 0.909 rad/s, 9.1 % short: a P controller needs some error to make any voltage. It fails two specs. More gain shrinks the error but adds overshoot.
Add 200 × the running total of error × time. While any error is left the total keeps growing, so the steady error goes to zero. But the extra push makes the overshoot worse: 30.9 %.
Add 10 × the rate of change of the error, a brake on fast swings. Overshoot drops to 1.0 % and the speed settles in 0.26 s with no error. Every spec is met. This is where most textbook examples stop.
Real hardware
The setpoint jumps, so the error's rate of change is huge for one sample: the PID asks for 10 100 V for 1 ms (derivative kick), then −102 V to brake the surge. Holding speed takes 10.0 V; our driver gives 24 V at most.
Drop the derivative and use V = 20·e + 40·∫e. Ki/Kp = 2 puts the PI zero at −2, cancelling the slow motor pole. Overshoot 1.7 %, settling 0.58 s, peak 21.2 V: every spec, inside 24 V.
The same 0.01 N·m drag hits at 2.5 s. The speed dips to 0.932 rad/s, the integral raises the voltage to 11.0 V, and it is back within 1 % after 0.59 s. Open loop lost 10 % for good.
What is happening
# step 1/11 · job # about: Setpoint 1 rad/s, DC motor (plant), Flywheel + load setpoint 1 rad/s (1 rad/s = 60/2π ≈ 9.5 rpm) plant DC motor + flywheel actuator driver, −24 to +24 V sensor encoder on the shaft disturbance a drag torque on the load Model → transfer function → specs → tune → check what real hardware allows.
The motor values (J = 0.01 kg·m², b = 0.1 N·m·s, K = 0.01 N·m/A, R = 1 Ω, L = 0.5 H) are an illustrative small motor, the set many university tutorials use for this example, not a datasheet. Every curve and number in the figure is computed from them. The controller runs every 1 ms and holds its voltage in between, as in the lesson "Writing a digital PID loop". Between updates the motor equations are stepped with fourth-order Runge-Kutta, accurate far beyond the digits shown. The controller itself is discrete: the 10 100 V kick exists because the derivative is taken over one 1 ms sample; a continuous PID would give an impulse instead.