The job
A controller can decide what to do in two ways: from the goal alone, or from the goal plus a measurement of the result. We compare both on one job: fill an empty tank with exactly 100 litres.
The tank is the plant and the volume of water is its output. The valve is the actuator, fed by the water supply. The label on the valve says that, wide open, it passes 10 litres per minute.
Open loop
The open-loop controller does the sum before it starts: 100 L ÷ 10 L/min = 10 minutes. It opens the valve, runs a timer and shuts the valve at 10 minutes. It uses the goal and the label, and nothing else.
On a normal day the valve really does pass 10 L/min. After 10 minutes the timer shuts it with 100.0 litres in the tank. Open loop is simple, cheap and exact, as long as its model is right.
Today the water pressure is low and the open valve only passes 8 L/min. The timer still shuts it at 10 minutes: 80.0 litres, 20.0 L short. Nothing tells the controller, because it never reads the tank.
Closed loop
Start again with an empty tank, and add a level gauge: the sensor. It reads how much water is in the tank and sends that back to the controller. That return path is feedback, and it closes the loop.
The controller works out the error: goal minus reading, 100 − 0 = 100 litres missing. It asks for 1 L/min for every litre missing. 100 L/min is more than the valve can give, so it opens wide.
Measure, compare, act, every three seconds. Below 90 litres the valve stays wide open. After that the error is small, so the valve eases shut. The tank holds 99 litres at 11.3 minutes and ends at 100.0 litres.
Same low-pressure day, 8 L/min. The valve stays open longer because the gauge still shows litres missing. The tank holds 99 litres at 13.6 minutes instead of 11.3, and still ends at 100.0 litres.
Choosing
Open loop needs no sensor, so it is simpler and cheaper: fine for a toaster or a washing-machine timer. Closed loop costs a sensor and a rule, but it ended at 100.0 litres on the bad day; open loop stopped at 80.0.
What is happening
# step 1/10 · job
# about: Goal 100 L, Tank (plant)
goal (setpoint) 100 L
tank right now 0 L
Two ways to decide:
open loop from the goal alone
closed loop from the goal AND a
measurement of the result
The tank is a simple model with illustrative numbers: the volume grows by exactly the flow through the valve, and the valve passes at most 10 L/min (normal) or 8 L/min (low pressure). Every curve and number in the figure is computed from that model. The Python on each step is plain Python 3. It updates the controller every 0.05 minutes and adds the flow times the time step to the volume, exactly as the figure does.