Lab 01: Temperature Control of a Heater-and-Sensor Board

Overview

A transistor heats a small aluminium fin and a thermistor measures its temperature, in the style of the open TCLab kit. We log a heater step, identify a first-order-plus-dead-time (FOPDT) model, see why proportional control leaves an error, design a PI controller on the root locus, run it with a saturating heater (and show windup), and use Bode and Nyquist plots to see how the dead time caps the phase margin and the bandwidth.

Heater-and-sensor board: a transistor heats an aluminium fin, a thermistor measures its temperature, and the firmware samples it every second

The heater-and-sensor board of lab 01.

The system

quantity demo board A homework board B basis
heater input 0-100 % (PWM of the transistor) same TCLab-style firmware
static gain $K$ 0.62 °C/% identify from the log representative values
heater/fin time constant $\tau_1$ 150 s identify from the log representative (TCLab fits give a few minutes)
thermistor lag $\tau_2$ 15 s identify from the log representative
transport delay 4 s about 6 s (board documentation) representative
ambient 21.0 °C read from the log
sampling, resolution, noise 1 s, 0.1 °C, 0.04 °C rms same

The logs were simulated from the two-lump plant

$$ T = T_a + \frac{K e^{-\theta_0 s}}{(\tau_1 s + 1)(\tau_2 s + 1)}\, Q , $$

and they are not measurements from a real board. The identification fits the simpler FOPDT model $G(s) = K e^{-\theta s}/(\tau s + 1)$, so the lab contains a deliberate model mismatch to check.

step course tool lecture
heater step test to $K$, $\tau$, $\theta$ (demo 1) first-order step response, parameter reading L6-L7
P control, $e_{ss} = (r - T_a)/(1 + K K_p)$ (demo 2) steady-state error, type-0 loop L12
Padé approximation, PI zero at $1/\tau$, gain for $\zeta = 0.7$ (demo 3) root locus, PI/PID design L13-L17, L19
heater saturation, windup and clamping anti-windup (demo 3) PID implementation L19
controller on the identified model and on the true plant, fan disturbance (demo 3) model mismatch, disturbance rejection L12, L22
PM, GM, delay margin, bandwidth against delay (demo 4) Bode, Nyquist, margins L20-L26

Demo 1: a first-order-plus-dead-time model from a heater step test

The heater of board A is switched from 0 % to 50 % and the temperature is logged every second. The response looks like a first-order rise that starts a little late. Fitting $G(s) = K e^{-\theta s}/(\tau s + 1)$ by least squares gives $K = 0.620$ °C/%, $\tau = 152.4$ s and $\theta = 18.6$ s. The firmware applies each logged heater value from the next 1 s sample on, so the step reaches the board 5 s after it is logged: the 4 s transport delay plus one sample of computation delay. The fitted dead time is much longer than these 5 s because the FOPDT model explains the S-shaped start of the two-lump plant (the thermistor lags the fin by 15 s) with extra apparent delay, and about 13.6 s of $\theta$ stands in for that sensor lag. For a step of size $\Delta u$ at time $t_s$,

$$ T(t) = T_0 + K \Delta u \left(1 - e^{-(t - t_s - \theta)/\tau}\right), \qquad t > t_s + \theta . $$

The data and the fit are fixed, so this demo is shown as computed by the lab script.

Logged temperature during a 0 to 50 percent heater step, the FOPDT fit and the true two-lump response, with the fit residual

The heater step log with the FOPDT fit and the residual.

Zoom on the first two minutes after the step showing the transport delay and the longer fitted dead time

The first two minutes after the step: the fitted $\theta$ stands in for the transport delay, one sample of computation delay and the sensor lag.

Demo 2: proportional control leaves a steady-state error

With $u = K_p (r - T)$ the heater power is zero when the error is zero, but holding the board above ambient needs power, so the loop settles where the error is just large enough to supply that power. The loop $L = K_p G$ is type 0, and for a set-point step of size $r - T_a$

$$ e_{ss} = \frac{r - T_a}{1 + K K_p}. $$

Raising $K_p$ shrinks the error, but the delay makes the loop oscillate. The simulation runs on the true plant with its delay, sensor noise, 0.1 °C resolution and the heater clipped to 0-100 %.

Interactive: P control and the steady-state error

The button loads Python (Pyodide with numpy, scipy, matplotlib and python-control, about 40 MB on the first visit, cached afterwards) into this page; after that, changing a parameter re-runs the computation and redraws the figures. Until then the figures and numbers below are the output of the original demo script with the default parameters.

added to the board's 4 s transport delay
Static view: pre-rendered figures from the original script.
Printed by the original demo script (default parameters)
identified K = 0.620 degC/%; set point 50 degC, ambient 21 degC
Kp =  2.0 %/degC: K*Kp =  1.24, predicted e_ss = 12.94 degC, simulated e_ss = 12.95 degC
Kp =  5.0 %/degC: K*Kp =  3.10, predicted e_ss = 7.07 degC, simulated e_ss = 7.07 degC
Kp = 10.0 %/degC: K*Kp =  6.20, predicted e_ss = 4.03 degC, simulated e_ss = 4.03 degC
Kp = 20.0 %/degC: K*Kp = 12.41, predicted e_ss = 2.16 degC, simulated e_ss = 2.16 degC
Responses for Kp = 2, 5, 10 and 20
Responses for Kp = 2, 5, 10 and 20 (pre-rendered by the original script)
Python output
(appears after the first live run)
Show code
Loading the source...

Demos 3 and 4: PI design on the root locus, windup, and the delay margin

The integrator of a PI controller removes the steady-state error. The root locus needs a rational $G(s)$, so the dead time is replaced by a first-order Padé approximation $e^{-\theta s} \approx (1 - \theta s/2)/(1 + \theta s/2)$, which puts a stable pole at $-2/\theta$ and a right-half-plane zero at $+2/\theta$ that bends the locus to the right. The controller is

$$ \begin{aligned}C(s) &= K_c \frac{s + z}{s} = K_p + \frac{K_i}{s},\\K_p &= K_c,\quad K_i = K_c z = \frac{K_p}{T_i}.\end{aligned} $$

Choosing $z = 1/\tau$ ($T_i = \tau = 152.4$ s) cancels the slow plant pole, and the root locus gives $K_c = 7.175$ for a dominant pair with $\zeta = 0.7$. The controller then runs the way the board runs it: sampled at 1 s, with the heater clipped to 0-100 %. A large set-point step saturates the heater, and without anti-windup the integrator keeps charging and the temperature overshoots.

On the frequency side, the dead time does not change $|L(j\omega)|$ but adds the phase lag $-\omega\theta$, which grows without bound. With $L(j\omega) = C(j\omega)G(j\omega)e^{-j\omega\theta}$, the phase margin is $PM = 180^\circ + \angle L(j\omega_c)$ at $|L(j\omega_c)| = 1$, the gain margin is $GM = 1/|L(j\omega_{180})|$, and the extra delay the loop tolerates is $\Delta\theta = PM\,[\mathrm{rad}]/\omega_c$. These margins belong to the continuous loop with the transport delay. The sampled loop also has one 1 s sample of computation delay and the zero-order hold, which lower the margins of the demo design on the true board from 61.6° and 8.80 to 59.3° and 6.51.

The interactive version below takes $K_p$, $T_i$ and the anti-windup switch, runs the loop on the true board or on the identified model, and lets you add loop delay to see the margins shrink. The extra delay enters the simulation, the margins and the Padé model of the root-locus panel, whose dead time becomes the fitted 18.6 s plus the extra delay.

Interactive: PI control of the heater board

The button loads Python (Pyodide with numpy, scipy, matplotlib and python-control, about 40 MB on the first visit, cached afterwards) into this page; after that, changing a parameter re-runs the computation and redraws the figures. Until then the figures and numbers below are the output of the original demo script with the default parameters.

Static view: pre-rendered figures from the original script.
Printed by the original demo script (default parameters)
model: K = 0.620 degC/%, tau = 152.4 s, theta = 18.6 s; Pade(1) pole/zero at -/+ 0.1077 rad/s
PI: z = 0.00656 rad/s, Kc = 7.175 -> Kp = 7.175 %/degC, Ki = 0.04707 %/(degC s)
closed-loop poles (Pade model): [-0.0393+0.0401j -0.0393-0.0401j -0.0066+0.j    ]
anti-windup True : overshoot =   0.0 %, 2% settling =  419 s, heater at 100 % for  63 s
anti-windup False: overshoot =  16.8 %, 2% settling =  456 s, heater at 100 % for 106 s
linear loop (no saturation): overshoot = 6.2 %, 2% settling = 139 s
identified FOPDT, exact delay 18.6 s: wc = 0.0292 rad/s, PM = 58.9 deg, w180 = 0.0846 rad/s, GM = 2.90 (9.2 dB), delay margin = 35.2 s
true plant, delay 4 s               : wc = 0.0274 rad/s, PM = 61.6 deg, w180 = 0.1237 rad/s, GM = 8.80 (18.9 dB), delay margin = 39.2 s
PI with and without anti-windup on the true board, 21 to 50 °C
PI with and without anti-windup on the true board, 21 to 50 °C (pre-rendered by the original script)
Root locus of PI × FOPDT (Padé 1) and the design for ζ = 0.7
Root locus of PI × FOPDT (Padé 1) and the design for ζ = 0.7 (pre-rendered by the original script)
Bode plot of the loop gain with the margins
Bode plot of the loop gain with the margins (pre-rendered by the original script)
Python output
(appears after the first live run)
Show code
Loading the source...

The remaining figures of demos 3 and 4 are shown as computed by the lab scripts. The first runs the same PI controller on the model it was designed for and on the true plant, with a cooling fan switched on at 900 s; the second compares PI with an IMC-style PID whose derivative turns the 0.1 °C sensor steps into heater chatter.

The PI controller on the identified model and on the true plant, with a cooling fan disturbance at 900 seconds

Model mismatch and a fan disturbance: the same PI on the identified model and on the true plant.

PI and PID responses to a 35 to 40 degree set-point change, with the heater signal

PI against PID on the true board: the derivative term amplifies the sensor quantization.

Raising the PI gain with the zero fixed moves the crossover up, and the delay costs $\omega_c\theta$ radians of phase there. The largest crossover with $PM \ge 45^\circ$ is about $0.76/\theta$ for each of the three delays, so halving the apparent delay roughly doubles the usable bandwidth. On the Nyquist plot the delay winds $L(j\omega)$ into a spiral, and raising $K_c$ by more than the gain margin makes the spiral encircle $-1$.

Phase margin against gain crossover frequency for three values of the dead time

Phase margin against crossover frequency when the PI gain is scaled, for three dead times.

Nyquist plot of the identified loop with exact delay for the design gain and for a gain above the gain margin

Nyquist plot of the identified loop with the exact delay.

Homework: temperature control of heater board B (100 points)

The homework uses board B, a second board in a warmer room with a differently mounted thermistor, so the demo numbers cannot be reused. It starts from two simulated logs, an open-loop step from 20 % to 60 % heater and a proportional-control run. The full problem statements are in homework.md, and the starter script hw_starter.py is in the lab folder of the lab materials on GitHub; the logs are in its data/ folder. Clone the repository, or download it as a zip file.

  1. Model from the step test (15 points; L6-L7)
  2. What proportional control can and cannot do (15 points; L12, L26)
  3. PI design with the root locus (25 points; L13-L17, L19)
  4. Implementation: saturation, windup and robustness (15 points; L19)
  5. Margins from Bode and Nyquist (15 points; L20-L26)
  6. Engineering judgement (15 points)