Smith predictor
A PID that sees a prediction of its measurement. A model of the process runs beside the plant, with and without its dead time, and the difference is added to the measurement, so the PID can be tuned as if the dead time weren't there.
Theory
O. J. M. Smith, 1957. Split the process into a fast part and a delay, , and keep a model of both, . The controller is fed
If the model is exact, the last term cancels the real measurement's response to . What is left is : the process without its delay. The closed loop becomes
The delay has moved out of the loop. is tuned for alone, and the answer arrives later.
As a single controller. The predictor and together are
That's what the Bode plot here uses. Its gain ripples with frequency, every rad/s, which is why the delay margin, not the phase margin, is the number to watch.
What it doesn't change. Load disturbances still pass through the plant's full delay before the controller sees them. Only the response after that gets faster. Setpoint tracking gains the most.
When it works, and when it breaks
Dead time much longer than the process lag (θ/τ above about 1): belts, long sample lines, paper machines, extruders, analysers.
The dead time is known and steady, or can be calculated (belt length / belt speed).
Frequent setpoint changes, where "the fast response, θ later" is a real gain.
The dead time changes and the model doesn't: 20 % error with a fast inner PI can be worse than a plain PI.
Integrating processes: a plain Smith predictor can't reject a constant load on one (it leaves an offset or drifts). They need a modified structure.
Load upsets: they still take the full dead time to be seen, so the predictor helps little there.
Maintenance: three model parameters someone must keep right, inside a structure most technicians haven't met.
How to tune it
- Identify gain, lag and dead time from a bump test (FOPDT is usually enough).
- Put them in the model. is the whole dead time the loop sees, half a controller cycle included.
- Tune the PI for the lag alone, as if . SIMC gives , .
- Choose for robustness, not speed. The undelayed process would allow of a few seconds, but any error in acts like unmodelled dead time. Here keeps Ms near 2 with the dead time ±15 % off. Faster and the loop rings as soon as the belt slows down.
- Test with the model wrong on purpose: dead time ±20 %, gain ±20 %.
The tuning rules in the lab
Model-based, one tuning knob: the closed-loop time constant τc. τc = θ gives a fast, still robust loop (Ms ≈ 1.6); larger τc is smoother. The min() on Ti keeps lag-dominant and integrating processes from responding too slowly to load upsets. PID uses the second-order model: Td = τ2 in series form.
The process-industry favourite: choose λ, the closed-loop time constant, and the setpoint response is first-order with no overshoot. Ti = τ cancels the process pole, which makes load rejection slow on lag-dominant processes. λ = 1–3 × τ is typical for robustness.
Internal model control worked back into a PID (Rivera, Morari and Skogestad, 1986): the controller that makes the loop a first-order λ response, with the dead time replaced by its first-order Padé approximation. That approximation is what gives the derivative, and why Ti = τ + θ/2 rather than τ. Keep λ above about 0.8θ for the PID and 1.7θ for the PI, where the approximation stops holding. Like Lambda, it cancels the process lag, so load upsets on lag-dominant processes recover slowly. The IMC structure itself (the model running beside the plant) is the Smith predictor on the bench.
For integrating processes such as levels, from the ramp rate k′ (% of span per second, per % of output). λ is the arrest time: how long the level keeps moving after an inflow upset. For a step upset Δ (in % of output) the level swings about k′·Δ·λ/e before it turns round, so choose λ from the room the tank has. A long λ lets the tank absorb the upset and keeps the outflow smooth: averaging level control. P-only: Kc = 1/(k′λ), which leaves an offset that is harmless in a buffer.
The 1942 rules, aiming for a quarter-amplitude decay. Aggressive: Ms is often above 2, so the loop rings and is sensitive to model error. Worth knowing because so many loops in the field were tuned this way.
Like Ziegler–Nichols but corrected for dead time, so it copes better when θ/τ is large. Also aimed at quarter-amplitude decay, so also aggressive.
Derived by optimizing load rejection with a robustness limit (Ms ≈ 1.4) over a large test batch of processes. A safe modern default when you have no reason to choose a speed.
How to implement it
- Order in the cycle: update the model with last cycle's controller output, compute the corrected measurement, then run the PID.
- The dead time is a ring buffer of model outputs. The cycle time must be constant, so use a cyclic interrupt.
- Manual mode: re-zero the model (output = the present value, buffer cleared), so switching to automatic is bumpless.
- Show the real measurement to the operator, not the corrected one.
- Variable dead time: recompute from the speed that causes it (belt speed, line flow).
Siemens and elsewhere
- No standard block for dead-time compensation in PID_Compact or PID_Temp.
- The exported LL_Smith FB (SCL, ring buffer of up to 1000 cycles) goes in front of PID_Compact: its Corrected output feeds PID_Compact's Input.
- For longer dead times, sample the model slower than the PID (a buffer entry every few cycles), or use a larger array.
- Keep the PID's own pretuning switched off: it would tune for the delayed process.
- DCS libraries often have a dead-time block (DEADTIME, DELAY) that makes building a Smith predictor a few blocks of configuration.
- IMC (internal model control) is the general form of the same idea: a model in parallel with the plant, and the controller acting on the model error. A Smith predictor is IMC with a PI in place of the model inverse.
- MPC handles dead time natively, in its prediction, along with constraints.
Interactive Controller Sandbox
Test and tune Smith predictor live on a process, benchmark against baseline PI, and inspect the resulting code.
Interactive Gains (Primary Loop)
Drag sliders or nudge gains to observe the closed-loop transient responseClosed-Loop Response: Smith predictor vs Baseline PI
Simulating…// Loop Lab export: Belt feeder (dead time), WIC-701
// TIA Portal SCL (S7-1200 / S7-1500). Generated code: review before use on a real plant.
FUNCTION_BLOCK "LL_Smith"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
Input : Real; // measurement, engineering units
PidOutput : Real; // the PID's output from the last cycle, %
Reset : Bool; // TRUE (e.g. in manual): restart the model from the present output
Cycle : Real := 0.5;
END_VAR
VAR_OUTPUT
Corrected : Real; // to the PID's Input: the measurement with the dead time predicted away
END_VAR
VAR
K : Real := 0.8; // model gain, % of span per % output
Tau : Real := 5.5; // model lag, s
DeadTime : Real := 32.8; // model dead time, s (at most 1000 cycles)
InLow : Real := 0.0;
InHigh : Real := 20.0;
Buffer : Array[0..999] of Real; // the model output over the last DeadTime
Head : DInt;
Ym : Real; // undelayed model output, % (deviation from where it started)
U0 : Real;
Started : Bool;
END_VAR
VAR_TEMP
n : DInt;
i : DInt;
a : Real;
ymd : Real;
END_VAR
BEGIN
#n := LIMIT(MN := 0, IN := TRUNC(#DeadTime / #Cycle), MX := 1000);
IF #Reset OR NOT #Started THEN
#U0 := #PidOutput;
#Ym := 0.0;
#Head := 0;
FOR #i := 0 TO 999 DO
#Buffer[#i] := 0.0;
END_FOR;
#Started := TRUE;
ELSE
// One cycle of K / (Tau*s + 1) driven by last cycle's output (exact for a held output).
#a := 0.0;
IF #Tau > 0.0 THEN
#a := EXP(-#Cycle / #Tau);
END_IF;
#Ym := #a * #Ym + (1.0 - #a) * #K * (#PidOutput - #U0);
END_IF;
// The same model, DeadTime later: a ring buffer of the last n values.
IF #n > 0 THEN
IF #Head >= #n THEN
#Head := 0;
END_IF;
#ymd := #Buffer[#Head];
#Buffer[#Head] := #Ym;
#Head := (#Head + 1) MOD #n;
ELSE
#ymd := #Ym;
END_IF;
// Measurement + (what the model says is coming − what the model says is arriving now).
#Corrected := #Input + (#Ym - #ymd) / 100.0 * (#InHigh - #InLow);
END_FUNCTION_BLOCK
FUNCTION_BLOCK "LL_PID"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
Setpoint : Real; // engineering units
Input : Real; // measurement, engineering units
ManualEnable : Bool; // TRUE = manual: Output follows ManualValue
ManualValue : Real; // %
Feedforward : Real; // %, added to the output (0 when unused)
HoldIntegral : Int; // +1 / -1: don't integrate up / down (a cascade slave is saturated)
ExtResetEnable : Bool; // override: this controller is not selected, so its integral follows ExtReset
ExtReset : Real; // %, the selected (valve) output, for external reset feedback
Cycle : Real := 0.5; // s, must match the cyclic interrupt the block is called from
END_VAR
VAR_OUTPUT
Output : Real; // %
AtLimit : Int; // +1 / -1 when the output is pinned high / low
END_VAR
VAR
Gain : Real := 0.41; // % output per % of span
Ti : Real := 5.5; // s, 0 = no integral action
Td : Real := 0.0; // s, 0 = no derivative action
PWeighting : Real := 1.0; // setpoint weight b on P
DWeighting : Real := 0.0; // setpoint weight c on D
TdFiltRatio : Real := 0.1; // derivative filter = TdFiltRatio * Td
InLow : Real := 0.0;
InHigh : Real := 20.0;
OutLow : Real := 0.0;
OutHigh : Real := 100.0;
Invert : Bool := FALSE;
Integral : Real; // integral term, in % output (so gain changes don't bump)
DTerm : Real;
LastED : Real;
END_VAR
VAR_TEMP
sp : Real;
pv : Real;
dir : Real;
e : Real;
eP : Real;
eD : Real;
p : Real;
tf : Real;
iNext : Real;
v : Real;
u : Real;
END_VAR
BEGIN
// Scale to % of span: the gains are then independent of engineering units.
#sp := (#Setpoint - #InLow) / (#InHigh - #InLow) * 100.0;
#pv := (#Input - #InLow) / (#InHigh - #InLow) * 100.0;
#dir := 1.0;
IF #Invert THEN
#dir := -1.0;
END_IF;
#e := #dir * (#sp - #pv);
#eP := #dir * (#PWeighting * #sp - #pv);
#eD := #dir * (#DWeighting * #sp - #pv);
#p := #Gain * #eP;
IF #ManualEnable THEN
// Track: preload the integral so switching to auto doesn't bump the output.
#u := LIMIT(MN := #OutLow, IN := #ManualValue, MX := #OutHigh);
#Integral := #u - #p - #Feedforward;
#DTerm := 0.0;
#LastED := #eD;
#Output := #u;
#AtLimit := 0;
RETURN;
END_IF;
// Derivative on c*SP - PV through a first-order filter (backward Euler).
IF #Td > 0.0 THEN
#tf := MAX(IN1 := #TdFiltRatio * #Td, IN2 := 1.0E-6);
#DTerm := #tf / (#tf + #Cycle) * #DTerm
+ #Gain * #Td / (#tf + #Cycle) * (#eD - #LastED);
ELSE
#DTerm := 0.0;
END_IF;
#LastED := #eD;
IF #ExtResetEnable AND #Ti > 0.0 THEN
// External reset feedback: the integral follows the selected output through a Ti lag,
// so this controller's output is the valve signal plus its own P and D.
#iNext := #Integral + #Cycle / MAX(IN1 := #Ti, IN2 := #Cycle) * (#ExtReset - #Integral);
ELSIF #Ti > 0.0 THEN
#iNext := #Integral + #Gain * #Cycle / #Ti * #e;
ELSE
#iNext := #Integral;
END_IF;
#v := #p + #iNext + #DTerm + #Feedforward;
#u := LIMIT(MN := #OutLow, IN := #v, MX := #OutHigh);
// A saturated slave asks its master to stop integrating in that direction.
IF #ExtResetEnable THEN
#Integral := #iNext;
ELSIF #Ti > 0.0 AND NOT ((#HoldIntegral > 0 AND #iNext > #Integral) OR (#HoldIntegral < 0 AND #iNext < #Integral)) THEN
// Conditional integration: stop integrating while the output is pinned and the error pushes it further.
IF NOT ((#v > #OutHigh AND #iNext > #Integral) OR (#v < #OutLow AND #iNext < #Integral)) THEN
#Integral := #iNext;
END_IF;
END_IF;
IF #v > #OutHigh THEN
#AtLimit := 1;
ELSIF #v < #OutLow THEN
#AtLimit := -1;
ELSE
#AtLimit := 0;
END_IF;
#Output := #u;
END_FUNCTION_BLOCK
// OB30 "Cyclic interrupt", cycle time 0.5 s (500 ms).
// "WT-701" is the scaled input (NORM_X/SCALE_X from the analog card), "SC-701" the output to scale back to 0-27648.
// Smith predictor: feed it last cycle's PID output first, then give the PID its corrected measurement.
"WIC_701_Smith_DB"(Input := "WT-701", PidOutput := "WIC_701_DB".Output, Reset := "Manual");
"WIC_701_DB"(Setpoint := "SP", Input := "WIC_701_Smith_DB".Corrected, ManualEnable := "Manual", ManualValue := "ManualOut");
"SC-701" := "WIC_701_DB".Output;
// Show "WT-701" on the HMI, not the corrected value: the operator wants the real measurement.