---
title: Feedforward and two-degree-of-freedom control
heading: Acting before the error appears: disturbance feedforward and its limits, inverse-model reference feedforward in motion control, prefilters and setpoint weighting
eyebrow: S9 · Lesson 19 · Feedforward and two-degree-of-freedom control
xp: 50
---

::: hook
Feedback has a built-in handicap: it can't act until an error has already appeared. If a disturbance can be measured, or a reference is known in advance, there's no need to wait. A furnace controller that sees the door open can add heat before the temperature falls; a motion controller that knows the planned trajectory can supply the torque to accelerate before any position error builds up. That's **feedforward**. It relies on a model, so it's never perfect, but feedback cleans up what it misses: together they do far better than either alone.
:::

::: play
- The curve is the output's deviation after a step disturbance at a plant's input, $1/(10s + 1)$, with a PI loop of crossover 1 rad/s acting alone: the response from lesson 8, peaking at 0.077 and lingering for tens of seconds.
- The dashed curve adds a feedforward that cancels a fraction g of the disturbance. By superposition, what's left is (1 − g) times the feedback-only deviation.
- A feedforward 80% right removes 80% of the deviation; feedback handles the rest without ever seeing the part that was cancelled.
:::

```sim plot
view: graph
x: t = 0..40 s
y: y = 0..0.09
slider: g = 0..1 = 0.8
plot: 0.1/0.9*(exp(-0.1*t) - exp(-t)) | label: feedback only
plot: (1 - g)*0.1/0.9*(exp(-0.1*t) - exp(-t)) | dashed | label: with feedforward
```

::: predict
## A disturbance feedforward is built from a model whose gain is 20% too low. How much of the disturbance's effect does it remove?

- [ ] None: a wrong model is useless
- [x] About 80%, with feedback correcting the remaining 20%
- [ ] About 20%
- [ ] It makes things worse

::: reveal
The feedforward injects 80% of the input that would exactly cancel the disturbance, so 20% of the disturbance gets through, and feedback then reduces that by its own factor S. Feedforward doesn't have to be accurate to be useful; it only has to be closer than zero. A gain twice too high, though, would overcorrect by 100% and help nothing.
:::
:::

::: nameit
## Disturbance feedforward

A measured disturbance d reaches the output through $P_d$, and the input reaches it through P. A feedforward $u_\text{ff} = Fd$ adds $PF\,d$, so the disturbance's net path is $(P_d + PF)$, zero for
$$F = -\frac{P_d}{P}$$
That ideal F must be stable and causal: if P has more delay than $P_d$, or a right-half-plane zero, it can't be inverted exactly, and a **static feedforward** $F = -P_d(0)/P(0)$ is the usual fallback. With feedback too, what's left reaches the output as $(P_d + PF)S$: feedforward shrinks the disturbance, feedback attenuates the remainder.

## Reference feedforward and two degrees of freedom

A one-degree-of-freedom loop acts only on the error, so the response to the reference and the rejection of disturbances are tied together through the same C. A **two-degree-of-freedom** controller separates them:
- **inverse-model feedforward**: $u = F_rr + C(r - y)$ with $F_r = P^{-1}$ makes the output follow r exactly when the model is right, and feedback corrects the error when it isn't;
- **prefilter**: shape the reference before the loop, $r_f = F_pr$, so the overall response is $F_pT$, for instance to cancel a slow or overshoot-causing zero of T;
- **setpoint weighting** in PI control, $u = K_p(br - y) + K_i\int(r - y)$, with $0 \le b \le 1$, puts only a fraction b of a setpoint step into the proportional term, which reduces overshoot without changing disturbance rejection.

## Motion control

For a motor of inertia J, viscous friction b and torque constant $K_t$, a trajectory with acceleration a(t) and velocity v(t) needs current
$$i_\text{ff} = \frac{Ja + bv}{K_t}$$
Supplying it ahead of time lets the position loop handle only modeling errors and disturbances, which is why motion controllers carry acceleration and velocity feedforward gains.
:::

::: example
## A rotary stage has J = 2 × 10⁻⁴ kg·m², b = 10⁻³ N·m·s and $K_t$ = 0.05 N·m/A. Its planned move accelerates at 500 rad/s² while at 100 rad/s. What feedforward current does that moment need?

::: solution
1. **The two torques.** One accelerates the inertia and one overcomes friction at this speed:
   $$\begin{aligned} Ja &= 2 \times 10^{-4} \times 500 \\ &= 0.1\ \text{N·m} \\ bv &= 10^{-3} \times 100 \\ &= 0.1\ \text{N·m} \end{aligned}$$
2. **Feedforward current.**
   $$\begin{aligned} i_\text{ff} &= \frac{Ja + bv}{K_t} \\ &= \frac{0.1 + 0.1}{0.05} \\ &= 4\ \text{A} \end{aligned}$$
3. **Without feedforward.** The position loop would have to build up a tracking error large enough for its gain to command those 4 A, and the error during every acceleration would be proportional to them.

**Answer:** the feedforward current at that moment is 4 A.
:::
:::

::: example
## A furnace's temperature rises 2 °C per watt of heater and 1 °C per °C of ambient. What static feedforward on the measured ambient cancels it, and what's left if the real heater gain is 2.4 °C/W?

::: solution
1. **Static feedforward.**
   $$\begin{aligned} F &= -P_d(0)/P(0) \\ &= -1/2 \end{aligned}$$
   Cut the heater by 0.5 W for each °C the ambient rises.
2. **With the true gain.** The feedforward removes
   $$2.4 \times 0.5 = 1.2\ \text{°C per °C}$$
   overcorrecting by 20%.
3. **Residual.**
   $$1 - 1.2 = -0.2\ \text{°C per °C}$$
   of ambient change, a fifth of the original, which the feedback loop then reduces further.

**Answer:** cut the heater by 0.5 W per °C of ambient rise; with a true gain of 2.4 °C/W, −0.2 °C per °C remains, a fifth of the original.
:::
:::

::: example
## A PI loop around $1/(s + 1)$ with $K_p$ = 3 and $K_i$ = 8 gives $T = (3s + 8)/(s^2 + 4s + 8)$: ζ = 0.707, but with a zero at −2.67. What does the zero do to a step, and how does a prefilter fix it?

::: solution
1. **Without the zero.** ζ = 0.707 alone would overshoot 4.3%.
2. **With the zero.** The zero adds a multiple of the derivative to the response, and a simulation of T gives 11.9% overshoot.
3. **The prefilter.** This cancels the zero:
   $$F_p = \frac{8}{3s + 8}$$
4. **What the reference sees.**
   $$F_pT = \frac{8}{s^2 + 4s + 8}$$
   which overshoots 4.3% again.
5. **Disturbances.** Disturbance rejection is unchanged, since the prefilter sits outside the loop.

**Answer:** the zero raises the overshoot from 4.3% to 11.9%, and the prefilter $8/(3s + 8)$ cancels it, bringing the overshoot back to 4.3%.
:::
:::

::: check
kind: parts
given: J = 1e-4 | 5e-4; a = 200 | 1000; b = 1e-4 | 1e-3; v = 50 | 300; K = 0.03 | 0.1

## A motor with J = {J} kg·m², viscous friction b = {b} N·m·s and $K_t$ = {K} N·m/A follows a trajectory accelerating at {a} rad/s² while turning at {v} rad/s.

::: part
answer: (J*a + b*v)/K
unit: A
tolerance: 0.5%

### What feedforward current does it need at that moment?

::: misses
- [J*a/K] Friction needs current too.
- [any] $(Ja + bv)/K_t$.
:::
:::

::: part
answer: J*a/(J*a + b*v)*100
unit: %
tolerance: 0.5%

### What fraction of it goes to acceleration?

::: misses
- [any] $Ja/(Ja + bv)$.
:::
:::
:::

::: check
kind: parts
given: p = 0.5 | 2 | 5; d = 0.3 | 1 | 3; e = -30 | -10 | 20

## A process gains {p} units per unit of input and {d} units per unit of a measured disturbance; a static feedforward is designed with a model gain for the input that's off by {e}%.

::: part
answer: -d/(p*(1 + e/100))
tolerance: 0.5%

### What feedforward gain does the model give?

::: misses
- [-d/p] That uses the true gain; the model's is off by {e}%.
- [any] $-P_d(0)/P_\text{model}(0)$.
:::
:::

::: part
answer: d - p*d/(p*(1 + e/100))
tolerance: 1%

### How much disturbance reaches the output per unit, before feedback?

::: misses
- [any] $P_d + PF$ with the true P.
:::
:::
:::

::: check
kind: parts
given: K = 2 | 3 | 5; I = 4 | 8 | 20

## A PI controller ($K_p$ = {K}, $K_i$ = {I}) runs around the plant $1/(s + 1)$.

::: part
answer: -I/K
tolerance: 0.5%

### Where is the closed loop's zero?

::: misses
- [any] $T = (K_ps + K_i)/(s^2 + (1 + K_p)s + K_i)$.
:::
:::

::: part
answer: (1 + K)/(2*sqrt(I))
tolerance: 0.5%

### What is the closed-loop damping ratio?

::: misses
- [any] Match $s^2 + (1 + K_p)s + K_i$.
:::
:::

::: part
answer: K/I
unit: s
tolerance: 0.5%

### What time constant must a first-order prefilter have to cancel the zero?

::: misses
- [any] $F_p = K_i/(K_ps + K_i)$: time constant $K_p/K_i$.
:::
:::
:::

::: check
kind: parts
given: t = 5 | 10 | 30; c = 0.5 | 1 | 2; g = 0.5 | 0.8 | 0.95

## A PI zero cancels the plant pole of $1/(\tau s + 1)$, τ = {t} s, for a loop $L = 1/(\tau_cs)$ with $\tau_c$ = {c} s; a feedforward cancels a fraction {g} of a unit step disturbance at the plant's input.

::: part
answer: (1 - g)*(1/t)/(1/c - 1/t)*(exp(-ln(t/c)/(1/c - 1/t)/t) - exp(-ln(t/c)/(1/c - 1/t)/c))
tolerance: 0.5%

### What peak deviation remains?

::: misses
- [(1/t)/(1/c - 1/t)*(exp(-ln(t/c)/(1/c - 1/t)/t) - exp(-ln(t/c)/(1/c - 1/t)/c))] That's feedback alone; multiply by 1 − g.
- [any] (1 − g) times the feedback-only peak.
:::
:::
:::

::: check
kind: parts
given: b = 0 | 0.3 | 0.6; K = 2 | 5; R = 1 | 10

## A PI controller with setpoint weight b = {b} and $K_p$ = {K} sees a setpoint step of {R} while the output is still at rest.

::: part
answer: K*b*R
tolerance: 0.5%

### How big is the proportional term's initial jump?

::: misses
- [K*R] Setpoint weighting scales the reference in the P term.
- [any] $K_pbR$.
:::
:::
:::

::: check
kind: parts
given: h = 1 | 2 | 5; d = 0.5 | 3

## A plant has a dead time of {h} s from its input, while a measured disturbance reaches the output after {d} s.

::: part
answer: h - d
unit: s
tolerance: 0.5%

### How far in advance would an ideal feedforward need to act?

::: misses
- [any] The input's delay minus the disturbance's.
:::
:::
:::

::: check
kind: choice

## Why does a plant with a right-half-plane zero rule out exact inverse-model feedforward?

- [ ] Its gain is too low
- [x] The inverse would put the zero as a pole in the right half-plane, an unstable feedforward whose output grows without bound, so only an approximate, stable inverse can be used
- [ ] Feedforward needs integral action
- [ ] Right-half-plane zeros only affect feedback

::: misses
- [1] Gain can be inverted; the zero's location is the problem.
- [3] Feedforward is open loop and needs no integrator.
- [4] They limit any controller that tries to invert the plant.
:::
:::

::: check
kind: derivation
vars: p = 0.1..10, d = 0.1..10, e = -0.5..0.5

## A static feedforward uses an input gain $p(1 + e)$ where the truth is p, to cancel a disturbance with gain d.

::: step
answer: -d/(p*(1 + e))

### What is the feedforward gain?
:::

::: step
answer: d*e/(1 + e)

### What net disturbance gain remains?
:::

::: right
Right. A model error e leaves about e times the disturbance, and feedback divides that by $1 + L$.
:::
:::

::: check
kind: python

## Write `peak_deviation(g, T, dt)`: simulate a unit step disturbance at the input of $1/(10s + 1)$ under PI control $C = (10s + 1)/s$, so that L = 1/s (forward Euler, step dt, for T seconds), with a feedforward that subtracts g times the disturbance at the plant's input, and return the largest output deviation.

```python starter
def peak_deviation(g, T, dt):
    return 0.0
```

```python solution
def peak_deviation(g, T, dt):
    y = 0.0
    integ = 0.0
    peak = 0.0
    for _ in range(int(T / dt)):
        e = -y
        u = 10.0 * e + integ - g * 1.0
        integ += e * dt
        y += dt * (-(y) + (u + 1.0)) / 10.0
        peak = max(peak, y)
    return peak
```

```python tests
p0 = peak_deviation(0.0, 40, 0.001)
assert abs(p0 - 0.0774) < 0.001, "Feedback alone peaks near 0.077."
for g in (0.5, 0.8):
    assert abs(peak_deviation(g, 40, 0.001) - (1 - g) * p0) < 1e-6, "Superposition: (1 − g) times as much."
```

::: right
Right. The loop is linear, so the feedforward's share of the cancellation scales the whole deviation.
:::
:::

::: explain
## Why are feedforward and feedback combined rather than used alone?

::: model
Feedforward acts on a measured disturbance or a known reference before any error appears, so it can be fast and needs no loop gain, but it relies entirely on a model and corrects nothing it didn't anticipate. Feedback needs no model of the disturbance and corrects whatever error appears, but it must first see that error and is limited by stability margins. Together, feedforward removes most of the predictable effect quickly, and feedback cleans up the residue left by model errors and unmeasured disturbances, so the combination is both fast and accurate. Because feedforward sits outside the loop, adding it doesn't change the loop's stability.
:::
:::

::: practice
::: check
given: J = 1e-4 | 1e-3; a = 100 | 1000; K = 0.05 | 0.2
answer: J*a/K
unit: A
tolerance: 0.5%

## Feedforward current for J = {J}, acceleration {a} rad/s², $K_t$ = {K}, no friction?

::: misses
- [any] $Ja/K_t$.
:::
:::

::: check
given: p = 1 | 4; d = 0.5 | 2
answer: -d/p
tolerance: 0.5%

## Static feedforward gain for process gain {p} and disturbance gain {d}?

::: misses
- [any] $-P_d(0)/P(0)$.
:::
:::

::: check
given: g = 0.6 | 0.9; P = 0.05 | 0.2
answer: (1 - g)*P
tolerance: 0.5%

## Peak deviation if feedback alone gives {P} and feedforward cancels {g}?

::: misses
- [any] Scale by 1 − g.
:::
:::
:::
