The car
Cruise control holds a car at a speed the driver picks, here 100 km/h. In the words of “Parts of a loop”: the car is the plant, the engine is the actuator and the speedometer is the sensor.
On a flat road, 50 % throttle holds exactly 100 km/h. So we fix the throttle at 50 % and never look again. That is open-loop control, as in “Open loop versus closed loop”, and on this flat road it works perfectly.
Disturbances
At 20 s the road tilts up. Gravity now pulls the car back: a disturbance, a push from outside that nobody asked for. The throttle stays at 50 %, so the car slows to about 80.0 km/h.
Now close the loop, as in “Open loop versus closed loop”: the speedometer feeds back. The rule starts at 50 % and adds 5 % throttle per km/h of error, the gap between 100 km/h and the speed. On the flat, error is zero.
Same hill, same moment. The speed dips, the error grows, and the throttle opens up to 59.1 %. Within about 7 seconds the car settles at 98.2 km/h. Open loop lost 20.0 km/h; feedback lost 1.8.
No sensor measures the slope. The controller only sees the speed falling, and that is enough. Each km/h lost asks for 5 % more throttle, so the loss shrinks about 11 times: from 20.0 to 1.8 km/h.
Coping with change
Next trip, the car tows a trailer on a flat road. Nothing pushes from outside this time: the plant itself is different. A quarter more drag (and weight) means the same throttle now gives 20 % less speed.
The open-loop controller still sends 50 %, the right number for a car without a trailer. With the trailer, 50 % only holds 80.0 km/h. Its whole accuracy rested on knowing the car exactly.
The same three-line rule, not retuned. The speedometer shows the car falling short, so the throttle rises to 61.1 %. The car holds 97.8 km/h. A 20 % change in the car became a 2.2 % change in speed.
Feedback costs a sensor and a rule, and still leaves a small error. In return it fights pushes it cannot see and copes with a plant that is not what we assumed. Those two gifts are why almost every controller uses it.
What is happening
# step 1/10 · cruise # about: Set speed 100, Engine (actuator), Car (plant), Speedometer (sensor) goal (setpoint) 100 km/h plant the car (output: speed) actuator engine, throttle 0 to 100 % sensor speedometer The car's speed follows the throttle with a time constant of 20 s: about how long it takes to get two-thirds of the way.
The car is a simple model with illustrative numbers: in steady state it goes 2 km/h for every % of throttle (1.6 with the trailer), with a 20-second time constant. Every curve and number in the figure is computed from that model. The Python on each step is plain Python 3 with the math module. It updates the throttle every 0.05 s and moves the car forward with the exact solution of its equation between updates, just as the figure does.