Regulating a Heat Engine — PID Control Meets Thermodynamics
A thermostat holding a boiler at a set temperature, a turbine governor keeping a generator's speed locked to grid frequency, an engine control unit trimming fuel to hold air-fuel ratio — every one of these is a feedback loop wrapped around a thermodynamic process. Getting the loop right requires two separate disciplines to meet: the thermodynamic model of how the engine actually behaves, and PID (Proportional-Integral-Derivative) control theory for turning a measured error into a corrective action.
1. The Thermal Engine as a Plant
In control-engineering terms, the heat engine (boiler, combustion chamber, Stirling hot-side, or turbine) is the "plant": a physical system with an input (fuel/heat rate) and an output (temperature, pressure, or shaft speed) linked by thermodynamics rather than simple algebra:
2. PID Control Basics
A PID controller drives the plant input from the error e(t) = setpoint − measured value using three terms:
3. Closing the Loop on Temperature
Combining the plant and controller equations gives the closed-loop dynamics:
4. Tuning: Ziegler-Nichols and Beyond
Classic tuning finds gains empirically from the plant's own response, without needing a full analytical model:
5. Efficiency Under Regulation
Controlling temperature is not the only goal — the engine's thermodynamic efficiency depends on how tightly it is held near its design operating point:
6. JavaScript PID + Thermal Plant Simulator
// First-order thermal plant + discrete PID controller
class PID {
constructor(Kp, Ki, Kd, dt) {
Object.assign(this, { Kp, Ki, Kd, dt, integral: 0, prevError: 0 });
}
step(setpoint, measured) {
const error = setpoint - measured;
this.integral += error * this.dt;
const derivative = (error - this.prevError) / this.dt;
this.prevError = error;
const u = this.Kp*error + this.Ki*this.integral + this.Kd*derivative;
return Math.max(0, Math.min(1, u)); // clamp to valve range [0,1] (anti-windup via clamping)
}
}
function simulateEngine({ C, hA, Tamb, QmaxIn, Tset, Kp, Ki, Kd, dt = 0.5, steps = 1200 }) {
const pid = new PID(Kp, Ki, Kd, dt);
let T = Tamb;
const log = [];
for (let i = 0; i < steps; i++) {
const u = pid.step(Tset, T); // controller output in [0,1]
const Qin = u * QmaxIn; // heat input [W]
const Qloss = hA * (T - Tamb); // Newton cooling [W]
const dT = (Qin - Qloss) / C * dt;
T += dT;
log.push({ t: i*dt, T, u });
}
return log;
}
// Boiler: Tset 90°C, ambient 20°C, tuned via Ziegler-Nichols
const trace = simulateEngine({
C: 50000, hA: 120, Tamb: 20, QmaxIn: 15000, Tset: 90,
Kp: 180, Ki: 6, Kd: 40
});
console.log(`Final temperature: ${trace[trace.length-1].T.toFixed(1)} °C`);
7. Real-World Applications
Steam Boiler Control
Industrial boilers use cascaded PID loops: an outer loop regulates steam pressure/temperature, an inner faster loop regulates fuel valve or burner firing rate.
Turbine Governors
Steam and gas turbine governors use PID (often with droop feedback) to hold rotational speed against variable electrical load, keeping grid frequency stable.
Automotive Engine Control
Modern ECUs use PID-family loops (often augmented with feedforward maps) to regulate idle speed, boost pressure, and exhaust-gas recirculation against a thermodynamic combustion model.
3D Printer Hotends
A familiar small-scale example: PID (or bang-bang with hysteresis) firmware holds nozzle temperature against ambient cooling and filament heat absorption.
8. Limitations and Advanced Control
Classic PID assumes a roughly linear, time-invariant plant near the operating point. Real thermal engines break this in several ways:
- Nonlinearity: combustion heat release and radiative losses scale with T⁴, not linearly — gain-scheduled PID (different gains at different operating temperatures) is common.
- Dead time: fuel transport and combustion delay create pure time lag that destabilises aggressive PID tuning — Smith predictor compensation is a standard fix.
- Multi-variable coupling: temperature, pressure, and air-fuel ratio interact — model predictive control (MPC) increasingly replaces single-loop PID in modern engine management.
- Actuator saturation: valves and injectors have hard limits — anti-windup logic (clamping or back-calculation) is essential to avoid large overshoot after saturation ends.