1t_stop = 100 / 10 # min2valve_open = t < t_stop3# never reads the tank1error = goal - level2ask = 1.0 * error # L/min3# valve gives min(ask, max)100 L0 L/min—100 L0.0 L10 L/minerror +100.0 L0.0 L
goal 100 Ltimer shutsthe valve0369121518050100time (minutes)litresOPEN LOOP: VOLUMEsupply 10 L/minsupply 8 L/mingoal 100 L0369121518050100time (minutes)litresCLOSED LOOP: VOLUMEsupply 10 L/minsupply 8 L/min
Lit wire with moving dashes: a signal or water is flowing along itBlocks: goal, valve, water supply, glass tank and level gauge; the controller is the code cardPlots: volume in the tank over time, open loop and closed loop, at two supply pressures, computed from the modelThe pill travelling back to the controller is the gauge reading: feedbackA tank-filling loop: the goal, the controller (a short Python rule), the valve (actuator) fed by the water supply, the tank (plant) and the level gauge (sensor). The plots below are simulated from the tank model as the steps play: the open-loop timer is exact only while the valve passes what its label says; feedback reaches the goal at either supply pressure. The closed loop is slower than the timer near the top because it asks for less flow as the error shrinks: 1 L/min for each litre missing. A later lesson on design goals weighs speed against accuracy.

The job

  1. 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.

Open loop

Closed loop

Choosing

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.