1K = 0.1 # kW per °C2power = K * (goal - reading)3power = min(max(power, 0), 3)1K = 0.4 # kW per °C2power = K * (goal - reading)3power = min(max(power, 0), 3)1K = 1.5 # kW per °C2power = K * (goal - reading)3power = min(max(power, 0), 3)20 °C???0 kW8 min10.0 °C10.0 °C10.0 °C
0306090120150180101520time (minutes)°CROOM TEMPERATUREK = 0.1K = 0.4K = 1.5goalsettles 14.3 °Csettles 17.5 °Cerror 5.7 °Cerror 2.5 °Crise 41 minrise 13 minpeak 18.2 °Cswings 17.9 to 21.0 °C
Lit wire with moving dashes: a signal or heat is flowing along itBlocks: goal, heater, room, thermometer, delay and the three judges; the controller is the code cardPlot: room temperature over time for three gains, computed from the modelThe pill travelling back through the delay is the thermometer reading, 8 minutes oldA room-heating loop with a proportional controller and a thermometer whose reading is 8 minutes old. Three judge blocks ask the design questions: is it stable, fast and accurate? The plot below is simulated from the room model for three gains: more gain rises faster and ends closer to the goal, until too much gain makes the loop swing for ever. The gain limit 1.13 kW/°C comes from the continuous-time model of this loop: it is where the delay plus the room's lag make a correction arrive half a swing late. The heater's 0 to 3 kW limits stop the K = 1.5 swings growing; without them they would grow for ever.

The goals

  1. Any feedback loop is judged by three questions. Stable: does it settle down? Fast: how quickly does it get there? Accurate: how close to the goal does it end up? Our loop keeps a room at 20 °C.

A gentle gain

More gain

What is happening

# step 1/11 · three-goals
# about: Stable?, Fast?, Accurate?

stable     does the output settle, or swing
           for ever?
fast       how quickly does it get close?
accurate   how far from the goal does it
           end up?

The example: a room, a heater (0 to 3 kW),
a thermometer and a proportional rule.
Goal 20 °C, outside 10 °C.

The room is a simple model with illustrative numbers: it heads towards the outside temperature plus 7.5 °C for every kW of heat, with a 40-minute time constant, and the thermometer's reading is 8 minutes old. 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 controller every 0.1 minutes with a reading 80 updates (8 minutes) old and moves the room forward with the exact solution of its equation between updates, just as the figure does.