PID with feedforward

Act on a disturbance as soon as it is measured, before it moves the PV. Feedback still runs alongside to clean up what the feedforward gets wrong.

Theory

If a measured disturbance dd reaches the PV through Gd(s)G_d(s) and the valve through Gu(s)G_u(s), the output that cancels it exactly is

uff=−Gd(s)Gu(s) du_{ff} = -\frac{G_d(s)}{G_u(s)}\,d

With first-order-plus-dead-time models of both paths, that becomes a gain, a lead-lag and (sometimes) a delay:

uff=−KdKu⋅τus+1τds+1⋅e−(θd−θu)s du_{ff} = -\frac{K_d}{K_u}\cdot\frac{\tau_u s + 1}{\tau_d s + 1}\cdot e^{-(\theta_d - \theta_u)s}\, d
  • Static feedforward (the gain alone) gets the steady state right. It is often enough, and it comes straight from a mass or energy balance.
  • Lead-lag fixes the timing when the two paths have different speeds.
  • If θd<θu\theta_d < \theta_u the ideal feedforward would need to see the future. It can only be partly cancelled, and feedback has to do the rest.

Stability. Feedforward is outside the loop, so it doesn't change the stability margins at all. A wrong feedforward makes the response worse, never unstable.

When it works, and when it breaks

Works
  • Big, frequent disturbances that can be measured upstream: throughput, feed temperature, feed composition.

  • Processes with dead time, where feedback alone reacts too late.

  • Where a balance (mass, energy) gives the gain without any test.

Breaks
  • Unmeasured disturbances: there is nothing to feed forward.

  • Disturbances that reach the PV faster than the valve can: only partial cancellation.

  • Wrong or drifting models: fouling, valve wear, a mis-ranged transmitter. Too much feedforward makes upsets worse.

  • A failed transmitter: feedforward follows the bad reading straight into the valve.

How to tune it

  1. Static gain first: from a balance, or from two bump tests (output step → PV, disturbance step → PV) as −Kd/Ku-K_d/K_u. Start at 70–80 % of it.
  2. Lead-lag: lead = τu\tau_u, lag = τd\tau_d. If they are close, leave both at zero.
  3. Test with real disturbance steps, with feedback in automatic.
    • The PV first dips, then rises: the timing is wrong.
    • The PV ends up away from setpoint while feedback catches up: the gain is wrong.
  4. Re-check after maintenance: feedforward gains drift with the plant.
The tuning rules in the lab
SIMC (Skogestad) (PI, PID)
Kc=τK(τc+θ),Ti=min⁡(τ, 4(τc+θ))K_c = \frac{\tau}{K(\tau_c + \theta)},\quad T_i = \min\big(\tau,\ 4(\tau_c + \theta)\big)

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.

Lambda (IMC) (PI)
Kc=τK(λ+θ),Ti=τK_c = \frac{\tau}{K(\lambda + \theta)},\quad T_i = \tau

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.

IMC-PID (Rivera–Morari–Skogestad) (PI, PID)
Kc=2τ+θ2Kλ,Ti=τ+θ2PID: Kc=2τ+θK(2λ+θ), Td=τθ2τ+θK_c = \frac{2\tau + \theta}{2K\lambda},\quad T_i = \tau + \frac{\theta}{2}\qquad\text{PID: } K_c = \frac{2\tau + \theta}{K(2\lambda + \theta)},\ T_d = \frac{\tau\theta}{2\tau + \theta}

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.

Lambda for integrating (averaging level) (P, PI)
Kc=2λ+θk′(λ+θ)2,Ti=2λ+θK_c = \frac{2\lambda + \theta}{k'(\lambda + \theta)^2},\quad T_i = 2\lambda + \theta

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.

Ziegler–Nichols (reaction curve) (P, PI, PID)
Kc=0.9 τKθ,Ti=3.33 θK_c = \frac{0.9\,\tau}{K\theta},\quad T_i = 3.33\,\theta

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.

Cohen–Coon (P, PI, PID)
Kc=τKθ(0.9+θ12τ),Ti=θ 30+3θ/τ9+20θ/τK_c = \frac{\tau}{K\theta}\Big(0.9 + \frac{\theta}{12\tau}\Big),\quad T_i = \theta\,\frac{30 + 3\theta/\tau}{9 + 20\theta/\tau}

Like Ziegler–Nichols but corrected for dead time, so it copes better when θ/τ is large. Also aimed at quarter-amplitude decay, so also aggressive.

AMIGO (Åström–Hägglund) (PI, PID)
Kc=0.15K+(0.35−θτ(θ+τ)2)τKθ,Ti=0.35θ+13θτ2τ2+12θτ+7θ2K_c = \frac{0.15}{K} + \Big(0.35 - \frac{\theta\tau}{(\theta+\tau)^2}\Big)\frac{\tau}{K\theta},\quad T_i = 0.35\theta + \frac{13\theta\tau^2}{\tau^2 + 12\theta\tau + 7\theta^2}

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

  • Use the deviation from the disturbance value when the loop went to automatic, so switching on is bumpless.
  • Add the feedforward to the PID output inside the anti-windup (the integral sees the total output), or to a cascade slave's setpoint.
  • Re-zero in manual, limit its contribution, and freeze it on a bad-quality input.
  • Discretize the lead-lag with backward Euler at the controller cycle.

Siemens and elsewhere

Siemens
  • PID_Compact: newer versions have a Disturbance input added to the output; check your version.
  • Otherwise: compute the feedforward in SCL (the exported LL_LeadLag block) and add it through LL_PID's Feedforward input, or to the cascade slave's setpoint.
  • Bad quality: use the analog input's status (or the PROFINET IO status) to freeze the feedforward.
Elsewhere
  • DCS: most PID blocks have a feedforward input with its own gain, and many have lead-lag blocks for the dynamic part.
  • Rockwell: the PIDE instruction has a feedforward input.
  • Ratio control is the common special case: a flow kept in proportion to another (fuel to air, additive to main flow) is feedforward with a gain set by the ratio.

Interactive Controller Sandbox

Test and tune PID with feedforward 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 response
Kc (gain): 1.5
Ti (integral): 29 s
Td (derivative): 0 s

Closed-Loop Response: Feedforward vs Baseline PI

Simulating…
Running test scenarios…
Block Diagram
SP rΣ+−PIDKc·(1 + 1/Ti·s + Td·s)PIDΣ++FFK(Ls + 1)/(Ts + 1)ffmeasured: process flow, inlet temperatureCV uValve1/(τᵥs + 1), char.stemΣ++d: steam supply pressureProcesswall → fluidPV yTransmittere^(−θs)/(τₘs + 1)Σ++noise nPV measured
Generated code
// Loop Lab export: Steam heat exchanger, TIC-301
// TIA Portal SCL (S7-1200 / S7-1500). Generated code: review before use on a real plant.

FUNCTION_BLOCK "LL_LeadLag"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT
      In : Real;              // the measured disturbance, engineering units
      Reset : Bool;           // TRUE (e.g. in manual): re-zero on the present value
      Gain : Real;            // % per unit of the disturbance
      Lead : Real;            // s
      Lag : Real;             // s
      Delay : Real := 0.0;    // s, wait before acting (up to 1000 cycles)
      Cycle : Real := 0.5;
   END_VAR
   VAR_OUTPUT
      Out : Real;             // %, zero at the value it started from
   END_VAR
   VAR
      Started : Bool;
      X0 : Real;
      XPrev : Real;
      Y : Real;
      Past : Array[0..999] of Real;   // the lead-lag's output over the last Delay
      Head : Int;
   END_VAR
   VAR_TEMP
      x : Real;
      n : Int;
      i : Int;
   END_VAR

BEGIN
    // Deviation from where the loop was switched on, so feedforward starts bumpless.
    IF #Reset OR NOT #Started THEN
        #X0 := #In;
        #XPrev := 0.0;
        #Y := 0.0;
        FOR #i := 0 TO 999 DO
            #Past[#i] := 0.0;
        END_FOR;
        #Head := 0;
        #Started := TRUE;
    END_IF;
    #x := #In - #X0;
    // Backward Euler of (Lead*s + 1) / (Lag*s + 1).
    #Y := #Lag / (#Lag + #Cycle) * #Y
              + (#Lead + #Cycle) / (#Lag + #Cycle) * #x
              - #Lead / (#Lag + #Cycle) * #XPrev;
    #XPrev := #x;
    // Dead time: the value from Delay ago, out of a ring of the last n cycles.
    #n := REAL_TO_INT(#Delay / #Cycle);
    IF #n > 1000 THEN
        #n := 1000;
    END_IF;
    IF #n <= 0 THEN
        #Out := #Gain * #Y;
    ELSE
        IF #Head >= #n THEN
            #Head := 0;
        END_IF;
        #Out := #Gain * #Past[#Head];
        #Past[#Head] := #Y;
        #Head := (#Head + 1) MOD #n;
    END_IF;
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 := 1.5;        // % output per % of span
      Ti : Real := 29.0;          // 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 := 120.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).
// "TT-301" is the scaled input (NORM_X/SCALE_X from the analog card), "FV-301" the output to scale back to 0-27648.
"FF_F_DB"(In := "FT-302", Reset := "Manual", Gain := 5.0, Lead := 0.0, Lag := 0.0);
"FF_Tin_DB"(In := "TT-302", Reset := "Manual", Gain := -1.24, Lead := 0.0, Lag := 0.0);
"TIC_301_DB"(Setpoint := "SP", Input := "TT-301", ManualEnable := "Manual", ManualValue := "ManualOut", Feedforward := "FF_F_DB".Out + "FF_Tin_DB".Out);
"FV-301" := "TIC_301_DB".Output;