1power = 1.0 # kW, fixed2# no rule: just record temp1if temp < 178: on = True2if temp > 182: on = False3power = 2.5 if on else 01e = 180 - temp2I += e * dt3u = Kp*(e + I/Ti - Td*dT)4power = min(max(u, 0), 2.5)1e = 180 - temp2u = Kp*(e + I/Ti - Td*dT)3power = min(max(u, 0), 2.5)4if u == power: I += e*dt180 °C0 kW—20.0 °Cshutintegral 0.00 kW20.0 °C
final 130 °C = 20 + K·1 kW63 % at θ + τ = 16 minθ = 1 min01020304050602060100130time (minutes)°CBUMP TEST · HEATER 1 kWoven, open loopsetpoint 180 °Cdoor010203040506020100180260time (minutes)°CWARM-UP TO 180 °CthermostatPID, no fixPID + clamp
Lit wire with moving dashes: a signal or heat is flowing along itBlocks: setpoint, heater, oven, thermocouple and door; the controller is the code cardPlots: the bump test and the warm-ups, computed from the oven modelThe pill travelling back to the controller is the thermocouple reading; the pill above it is the integral termAn oven temperature loop: the setpoint, the controller (a short Python rule), the heater (actuator, heats only), the oven (plant) and the thermocouple (sensor), with the door as a disturbance. Both plots are simulated from the oven model as the steps play: first the bump test the model is read from, then three warm-ups with a thermostat, a Ziegler-Nichols PID, and the same PID with its integral clamped. A real oven element is usually switched by a relay or a solid-state relay. A controller that asks for 1.45 kW gets it on average: the element is on for a share of each short cycle (time-proportioning). The oven's slow response smooths the pulses.

Model

  1. The job: bring an oven from 20 °C to 180 °C and keep it there. Our only handle is a heater that gives 0 to 2.5 kW. It can heat but never cool. A thermocouple, the sensor, reads the temperature.

Tune

Real-world fixes

What is happening

# step 1/10 · job
# about: Setpoint 180 °C, Oven (plant), Heater 0–2.5 kW

setpoint    180 °C
oven now    20 °C (room temperature)
heater      0 to 2.5 kW, heats only
sensor      thermocouple inside the oven

The design, in order:
  1. measure a model of the oven
  2. tune a controller from the model
  3. fix the problems the real parts add

The oven is a first-order model with a dead time and illustrative numbers: 110 °C per kW, a 15-minute time constant and a 1-minute delay, at 20 °C ambient. Every curve and number in the figure is computed from it. The Python on the steps is plain Python 3. It updates the controller every 0.6 s, delays the heater power by one minute in a list, and moves the oven forward with the exact solution of its equation between updates, just as the figure does.