The car
A 1000 kg car cruises at 20 m/s. The driver switches on cruise control and sets 25 m/s (90 km/h). From now on a controller must move the car there and hold it, flat road or hill.
Newton along the road: m·dv/dt = u − b·v − m·g·sinθ. Engine force u pushes; drag b·v and the hill pull back. The transfer function, the rule from force in to speed out, is G(s) = 1/(1000s + 50): time constant 20 s.
Open loop
Holding 25 m/s on the flat needs b × 25 = 1250 N, so fix the engine there. The car creeps up with its own 20-second time constant and reaches 24.8 m/s after a minute. The controller never reads the speed.
At 60 s the road climbs 4 %. Gravity pulls back with m·g·sinθ = 392 N. Nothing tells the fixed force, so the car slows towards 25 − 392/50 = 17.2 m/s, a loss of 7.8 m/s.
Feedback
Start again at 20 m/s, now with a speed sensor on the wheels. Its reading goes back to the controller, which works out the error: 25 − 20 = 5 m/s too slow. That return path is feedback.
Try force = 350 × error. Holding a steady speed still takes 1094 N, and that force needs an error: the car levels off at 21.9 m/s, 3.1 short. On the hill the gap grows to 4.1 m/s.
PI design
An integral term keeps adding force while any error is left. The loop's poles are the roots of 1000s² + (50 + Kp)s + Ki; they set how fast it settles. Both at s = −0.2 (no wobble) gives Kp = 350, Ki = 40.
A practical detail: the integral starts at 1000 N, the force already holding 20 m/s, so switching on causes no lurch. The first command is 350 × 5 + 1000 = 2750 N, inside the engine's 0 to 3000 N.
Measure, compare, push, a hundred times a second. The car peaks at 25.36 m/s after 12 s (7.3 % overshoot, added by the PI zero) and settles within 2 % in 24 s. No error is left.
The same 392 N hill. The speed dips 0.72 m/s, lowest 5 s in, and is back within 0.1 m/s after 22 s. The integral has climbed to 1642 N: 1250 for drag plus 392 for gravity.
This run peaked at 2750 N, under the 3000 N limit, so the linear design held. A jump from 20 to 30 m/s would ask for 4500 N: the engine hits its limit and the integral winds up. See “Actuator limits and integrator windup”.
What is happening
# step 1/11 · goal # about: Set speed, Car (plant) car mass 1000 kg speed now 20 m/s (72 km/h) set speed 25 m/s (90 km/h) The design: model the car, try open loop, close the loop, add integral action, pick the gains, then check the practical bits.
The car is a simple linear model with illustrative numbers: 1000 kg, drag and rolling loss of 50 N per m/s, engine force 0 to 3000 N. Every curve and number in the figure is computed from that model. Its transfer function G(s) and 20 s time constant are explained in “The transfer function of a system” and “First-order response and the time constant”; what happens when the engine hits its limit is in “Actuator limits and integrator windup”. The Python on each step is plain Python 3 with the math module. It updates the controller every 0.01 s and moves the car forward with the exact solution of its equation between updates, just as the figure does.