Module 4/5 · Weeks 10–12 · 27 h

Introductory feedback control

UAT 202 Fundamentals of Automation Technology

About 80 minDraft, awaiting reviewLast updated 27 September 2026

Lesson

By the end of this module you will be able to

  1. Explain ON/OFF control with hysteresis and why it oscillates
  2. Explain the roles of the P, I and D terms of a PID controller
  3. Simulate a temperature loop and compare ON/OFF, P and PI by steady-state error and oscillation
  4. Explain integral windup and a basic way to prevent it

Prerequisites: UAT 202 modules 1–3 · UAT 101 (applied mathematics)

Why this matters

Lithium batteries charged in heat wear quickly and risk becoming dangerous, so the swap station’s charging cabinet must hold its temperature with a cooling fan. Ways of commanding the fan range from the simplest, on when hot and off when cool, to a PID controller that adjusts fan power continuously. The same principle is used in a drone’s flight controller, holding attitude hundreds of times a second.

The feedback block diagram

A 30 °C setpoint enters a summing junction, giving the error e into a controller, ON/OFF, P or PI, which commands the cooling fan, which cools the battery charging cabinet. Charging heat enters the cabinet from above. A temperature sensor measures the cabinet and feeds back negatively to the summing junction
Figure 1 Block diagram of the cabinet temperature loop

A simple cabinet model: charging heat warms it, the fan removes up to , and the walls exchange heat with the surrounding air at rate . With no fan at all, the temperature settles at , here °C, which is far too hot.

ON/OFF, P, I and D

  • ON/OFF runs the fan at full when too hot and off when cool enough. It needs hysteresis (a dead band), such as on above 30.5 °C and off below 29.5 °C; otherwise the fan switches so often it wears out. The temperature therefore always oscillates within that band
  • P (proportional) commands in proportion to the present error: the hotter, the harder the fan runs. It usually leaves a steady-state error, because some error must remain to keep the fan running
  • I (integral) accumulates the error over time. As long as an error remains, the command keeps rising until the steady-state error disappears
  • D (derivative) looks at the rate of change of the error, helping reduce overshoot, but is sensitive to noise; slow temperature processes often omit D

Example 1 Comparing ON/OFF, P and PI

The cabinet starts at 32 °C and should be 30 °C. Simulate one hour in 1 s steps, with the fan command between 0 and 1.

def cabinet(mode, kp=0.3, ki=0.002, t_end=3600, dt=1.0):
    C, h, Ta, Q, Pmax, sp = 20000.0, 10.0, 32.0, 300.0, 600.0, 30.0   # J/K, W/K, °C, W, W, °C
    temp, integ, on, switches, hist = 32.0, 0.0, False, 0, []
    for _ in range(int(t_end / dt) + 1):
        e = temp - sp                                    # positive when too hot
        if mode == "ON/OFF":
            new_on = True if temp > sp + 0.5 else False if temp < sp - 0.5 else on
            switches += new_on != on
            on = new_on
            u = 1.0 if on else 0.0
        elif mode == "P":
            u = min(max(kp * e, 0.0), 1.0)
        else:                                            # PI, not integrating while saturated
            integ += e * dt
            raw = kp * e + ki * integ
            u = min(max(raw, 0.0), 1.0)
            if u != raw:
                integ -= e * dt
        temp += dt * (Q - Pmax * u - h * (temp - Ta)) / C
        hist.append(temp)
    last = hist[-1200:]                                  # the last 20 minutes
    return min(last), max(last), switches


for mode in ("ON/OFF", "P", "PI"):
    lo, hi, sw = cabinet(mode)
    print(f"{mode:<6} last 20 min: {lo:.2f}–{hi:.2f} °C" + (f", fan switched {sw} times" if mode == "ON/OFF" else ""))
ON/OFF last 20 min: 29.50–30.51 °C, fan switched 52 times
P      last 20 min: 31.68–31.68 °C
PI     last 20 min: 30.00–30.00 °C

ON/OFF oscillates around 30 °C and the fan switches dozens of times an hour. P does not oscillate but settles about 1.7 °C above the target. PI settles exactly at 30 °C, because the I term keeps raising the command until the error is gone.

A plot of temperature against time from 0 to 60 minutes. A dashed horizontal line at 30 °C is the target. The orange ON/OFF line zigzags between about 29.5 and 30.5 °C. The purple P line falls from 32 and settles near 31.7 °C. The blue PI line dips slightly below 30 then settles at 30 °C
Figure 2 Cabinet temperature under ON/OFF, P and PI

Integral windup

If the command saturates, for example the fan is already at full but it is still too hot, the I term keeps accumulating with no effect. When the temperature reaches the target, the excess accumulation keeps the fan on until it is too cold. This is integral windup. The example prevents it the simplest way, by pausing accumulation while the command is saturated. PX4’s flight controller also limits the I term in its rate loop.

Module lab

Lab: tuning a temperature controller

  1. Run the code in Example 1, change the ON/OFF band to ±0.2 and ±1.0 °C, and record the number of fan switches and the oscillation range.
  2. Raise the P controller’s to 0.6 and 1.2, record the steady-state error, and explain why it never fully disappears.
  3. Remove the line that pauses I accumulation and start from a 45 °C cabinet, comparing with the windup-protected version.
  4. With a training rig, use a real temperature sensor and fan through a PLC or microcontroller, write ON/OFF with hysteresis, and record the response.
  5. Conclude which controller the station’s charging cabinet should use, with reasons.

Common mistakes

Watch out

  • Using ON/OFF without hysteresis, so equipment switches rapidly and wears out
  • Raising to chase steady-state error until the system oscillates
  • Not preventing integral windup when the command saturates
  • Adding a D term to a noisy signal
  • Tuning a real system without safety limits, such as cutting charging when overheated

Summary

  • ON/OFF is simple but always oscillates, and needs hysteresis
  • P reduces error but usually leaves a steady-state error; I removes it; D reduces overshoot but is noise-sensitive
  • PI suits slow processes such as temperature
  • Integral windup must be prevented when the command saturates

Check your understanding

  1. A cabinet has °C, W and W/K. Without a fan, where does its temperature settle?
  2. A P controller has and an error of 2 °C. What is the command?
  3. Which PID term removes steady-state error?
  4. Why does ON/OFF need hysteresis?
  5. When does integral windup occur?
Answers
  1. °C
  2. The I term
  3. So equipment does not switch too often when the value is near the target
  4. When the command is saturated but error remains, so the I term keeps accumulating without effect

Key formulas

PID controller
Charging cabinet model
Steady temperature without cooling

Key references

  1. Åström, K. J., & Murray, R. M. (2021). Feedback systems: An introduction for scientists and engineers (2nd ed.). Princeton University Press. link
  2. Nise, N. S. (2019). Control systems engineering (8th ed.). Wiley. link
  3. PX4 Autopilot. Controller diagrams. PX4 user guide (main). link

Further reading

Study the assigned knowledge units in advance, review media and take the module quiz

In class / field

Lab or field practice from worksheets with a safety checklist

Learning evidence: Checked worksheets and quiz results

Module quiz

This is a formative self-check, not a graded exam

Knowledge domain: Control, autopilot and navigation · Mission planning, flight and simulation