---
title: Integral action in state feedback
heading: Tracking without steady error: augmenting the state with an integrator, placing the extra pole, rejecting constant disturbances and model errors, and keeping the integrator from winding up
eyebrow: S9 · Lesson 35 · Integral action in state feedback
xp: 50
---

::: hook
Lesson 34's state feedback places every pole where it's wanted, and a reference gain $k_r$ scales the setpoint so the output settles at exactly the right value. Exactly, that is, if the model is exact. A plant gain 20% off, or a constant load torque, and the output settles somewhere else, with nothing in the controller to notice. Classical control fixed this with the integral term of PI; state feedback fixes it the same way, by adding the integral of the error as one more state and placing one more pole.
:::

::: play
- The curves are the step response of the plant $\dot x = -2x + bu$ with state feedback designed for b = 4, when the real b is set by the slider.
- With only a reference gain (solid), the output settles at $b\,k_r/(2 + bk)$, off by several percent whenever b differs from 4.
- With integral action (dashed), designed for the same nominal plant, the output always settles at exactly 1; a wrong b only changes how it gets there.
:::

```sim plot
view: graph
x: t = 0..3 s
y: y = 0..1.4
slider: b = 2..6 = 4.8
plot: b*2/(2 + 1.5*b)*(1 - exp(-(2 + 1.5*b)*t)) | label: reference gain only
plot: 1 - exp(-(2 + 1.5*b)*t/2)*(cos(sqrt(abs(6.25*b - (2 + 1.5*b)^2/4))*t) + (2 + 1.5*b)/2/sqrt(abs(6.25*b - (2 + 1.5*b)^2/4))*sin(sqrt(abs(6.25*b - (2 + 1.5*b)^2/4))*t)) | dashed | label: with integral action
```

::: predict
## A state-feedback servo with reference gain $k_r$ was designed for a plant gain of 4; the real gain is 4.8. The design put the closed-loop pole at −8. Where does the output settle for a unit step?

- [ ] Exactly 1
- [x] About 1.04
- [ ] 1.2
- [ ] 0.8

::: reveal
With k = 1.5 and $k_r$ = 2 (so that 4 × 2/(2 + 4 × 1.5) = 1), the real plant settles at $4.8 \times 2/(2 + 4.8 \times 1.5) = 9.6/9.2 = 1.043$. Feedback divided the 20% gain error by about 4.6, but didn't remove it. An integrator on the error would keep pushing until the error is zero.
:::
:::

::: nameit
## The augmented system

Add the state $z = \int(r - y)\,dt$, so $\dot z = r - Cx$. The control law becomes
$$u = -Kx + k_iz$$
and the closed loop is
$$\begin{pmatrix} \dot x \\ \dot z \end{pmatrix} = \begin{pmatrix} A - BK & Bk_i \\ -C & 0 \end{pmatrix}\begin{pmatrix} x \\ z \end{pmatrix} + \begin{pmatrix} 0 \\ 1 \end{pmatrix}r$$
If the augmented pair is controllable (it is when the plant has no zero at s = 0), all n + 1 poles can be placed, by the same methods as before: matching coefficients, or Ackermann's formula on the augmented matrices.

## Why the error goes to zero

In steady state every derivative is zero, including $\dot z = r - y$. So whatever the plant's true gain, and whatever constant disturbance acts on it, the output settles at r, as long as the closed loop is stable. The reference gain $k_r$ is no longer needed.

## Two examples

- **First-order plant** $\dot x = -ax + bu$: the closed loop is $s^2 + (a + bk)s + bk_i$, so $k = (2\zeta\omega_n - a)/b$ and $k_i = \omega_n^2/b$.
- **Double integrator** $\ddot y = u$ with $u = -k_1y - k_2\dot y + k_iz$: $s^3 + k_2s^2 + k_1s + k_i$. Three poles at −p give $k_2 = 3p$, $k_1 = 3p^2$, $k_i = p^3$.

## Windup

When the actuator saturates, z keeps integrating an error the actuator can't correct, and the output overshoots badly once the saturation ends. The fixes are the same as for PI (lesson 15): stop integrating while saturated, or feed the difference between commanded and actual input back into $\dot z$.
:::

::: example
## A plant $\dot x = -2x + 4u$ needs integral state feedback with closed-loop poles at $\omega_n$ = 5 rad/s, ζ = 0.8.

::: solution
1. **Closed-loop polynomial.**
   $$s^2 + (2 + 4k)s + 4k_i$$
2. **Target.** For $\omega_n$ = 5 rad/s and ζ = 0.8:
   $$s^2 + 8s + 25$$
3. **Match coefficients.**
   $$\begin{aligned} k &= (8 - 2)/4 \\ &= 1.5 \\ k_i &= 25/4 \\ &= 6.25 \end{aligned}$$
4. **Compare without the integrator.** The same k with $k_r$ = 2 would put a single pole at −8.
5. **What the integrator costs and buys.** It costs a second pole and some overshoot (ζ = 0.8 gives 1.5%), and buys zero steady error against any constant disturbance or gain error.

**Answer:** k = 1.5 and $k_i$ = 6.25.
:::
:::

::: example
## A double integrator $\ddot y = u$ needs integral state feedback with all three poles at −10. Find the gains.

::: solution
1. **Closed-loop polynomial.**
   $$s^3 + k_2s^2 + k_1s + k_i$$
2. **Target.**
   $$\begin{aligned} &(s + 10)^3 \\ &= s^3 + 30s^2 + 300s + 1000 \end{aligned}$$
3. **Match coefficients.**
   $$\begin{aligned} k_2 &= 30 \\ k_1 &= 300 \\ k_i &= 1000 \end{aligned}$$
4. **Why the integrator matters.** A position servo with these gains holds its position exactly under a constant load force, which a plain state feedback around the double integrator wouldn't: the load would leave an offset of $d/k_1$.

**Answer:** $k_2$ = 30, $k_1$ = 300 and $k_i$ = 1000.
:::
:::

::: example
## The plant of the first example gets a constant input disturbance d = 1. What steady error does each design leave?

::: solution
1. **Without the integrator.** With $u = -1.5x + 2r$, the disturbance adds $b\,d = 4$ to $\dot x$, shifting the steady state by
   $$\begin{aligned} \Delta x &= \frac{4}{2 + 4 \times 1.5} \\ &= 0.5 \end{aligned}$$
   an error of half the setpoint for a unit disturbance.
2. **With the integrator.** z keeps changing until the input cancels d exactly: zero steady error, reached with the closed loop's own dynamics.

**Answer:** without the integrator the error is 0.5; with it, zero.
:::
:::

::: check
kind: parts
given: a = 0.5 | 2 | 5; b = 2 | 4 | 10; w = 4 | 10; z = 0.7 | 0.9

## A plant $\dot x = -\given{a}x + \given{b}u$ gets integral state feedback $u = -kx + k_i\int(r - x)\,dt$ with poles at $\omega_n$ = {w} rad/s, ζ = {z}.

::: part
answer: (2*z*w - a)/b
tolerance: 0.5%

### What is k?

::: misses
- [2*z*w/b] The plant's own pole contributes a.
- [any] Match $s^2 + (a + bk)s + bk_i$.
:::
:::

::: part
answer: w^2/b
tolerance: 0.5%

### What is $k_i$?

::: misses
- [w^2] The input gain b scales it.
- [any] $k_i = \omega_n^2/b$.
:::
:::
:::

::: check
kind: parts
given: p = 2 | 5 | 20

## A double integrator gets integral state feedback with all three closed-loop poles at −{p}.

::: part
answer: 3*p^2
tolerance: 0.5%

### What is the position gain $k_1$?

::: misses
- [p^2] Expand $(s + p)^3$.
- [any] $3p^2$.
:::
:::

::: part
answer: 3*p
tolerance: 0.5%

### The velocity gain $k_2$?

::: misses
- [any] $3p$.
:::
:::

::: part
answer: p^3
tolerance: 0.5%

### The integral gain $k_i$?

::: misses
- [any] $p^3$.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 2; b = 2 | 4; k = 1 | 3; d = 0.5 | 2

## A plant $\dot x = -\given{a}x + \given{b}(u + d)$ runs under $u = -kx + k_rr$ with k = {k}, and a constant disturbance d = {d} appears.

::: part
answer: b*d/(a + b*k)
tolerance: 0.5%

### How far does the output shift?

::: misses
- [d/(a + b*k)] The disturbance enters through b.
- [any] $bd/(a + bk)$.
:::
:::

::: part
answer: 0
tolerance: 0.5%

### And with an integral state added (any stable gains)?

::: misses
- [any] In steady state $\dot z = r - y = 0$.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 2 | 4; b = 2 | 4; k = 1 | 1.5 | 3; e = -30 | -10 | 20

## State feedback $u = -kx + k_rr$ with k = {k} was designed for $\dot x = -\given{a}x + \given{b}u$, with $k_r$ set for unit DC gain; the real input gain is {e}% different.

::: part
answer: (a + b*k)/b
tolerance: 0.5%

### What is $k_r$?

::: misses
- [any] Unit DC gain: $bk_r/(a + bk) = 1$.
:::
:::

::: part
answer: b*(1 + e/100)*(a + b*k)/b/(a + b*(1 + e/100)*k)
tolerance: 0.5%

### Where does the real plant's output settle for a unit step?

::: misses
- [1 + e/100] Feedback reduces the error.
- [any] $b'k_r/(a + b'k)$ with the real b'.
:::
:::
:::

::: check
kind: parts
given: w = 3 | 10 | 30; z = 0.5 | 0.7 | 1

## An integral state-feedback design places its closed-loop poles at $\omega_n$ = {w} rad/s, ζ = {z}.

::: part
answer: 4/(z*w)
unit: s
tolerance: 0.5%

### About how long do disturbances take to be removed (2% settling)?

::: misses
- [any] $4/(\zeta\omega_n)$.
:::
:::
:::

::: check
kind: choice

## Why must the integral state integrate the measured error r − y, rather than an error computed from the model's predicted output?

- [ ] It's cheaper to compute
- [x] Only the measured output reflects the real plant's gain and the disturbances acting on it; an integrator on a model-predicted error would settle when the model, not the plant, reached the setpoint
- [ ] The model output is noisier
- [ ] It makes no difference

::: misses
- [1] Cost isn't the issue.
- [3] Usually the reverse.
- [4] It's the whole point of integral action.
:::
:::

::: check
kind: derivation
vars: a = -5..5, b = 0.1..10, w = 1..50, z = 0.4..1

## A plant $\dot x = -ax + bu$ gets integral state feedback with closed-loop poles at $\omega_n$ = w, ζ = z.

::: step
answer: (2*z*w - a)/b

### What is k?
:::

::: step
answer: w^2/b

### What is $k_i$?
:::

::: right
Right. The integral gain sets $\omega_n$, the state gain sets the damping, exactly as in a PI loop.
:::
:::

::: check
kind: python

## Write `settle(b_true, d, integral, T, dt)`: simulate $\dot x = -2x + b_\text{true}(u + d)$ from rest with a unit step reference, using the design k = 1.5, $k_r$ = 2 when `integral` is False, or k = 1.5, $k_i$ = 6.25 with $z = \int(r - x)$ when it's True; forward Euler; return x at time T.

```python starter
def settle(b_true, d, integral, T, dt):
    return 1.0
```

```python solution
def settle(b_true, d, integral, T, dt):
    x = z = 0.0
    for _ in range(int(T / dt)):
        if integral:
            u = -1.5 * x + 6.25 * z
            z += dt * (1.0 - x)
        else:
            u = -1.5 * x + 2.0
        x += dt * (-2.0 * x + b_true * (u + d))
    return x
```

```python tests
assert abs(settle(4.0, 0.0, False, 5, 1e-4) - 1.0) < 1e-6, "Nominal plant, no disturbance: exact."
assert abs(settle(4.8, 0.0, False, 5, 1e-4) - 9.6 / 9.2) < 1e-4, "20% gain error: settles near 1.043."
assert abs(settle(4.0, 1.0, False, 5, 1e-4) - 1.5) < 1e-4, "A unit disturbance shifts it by 0.5."
assert abs(settle(4.8, 1.0, True, 8, 1e-4) - 1.0) < 1e-3, "With the integrator: back to 1 despite both."
```

::: right
Right. The integrator doesn't need to know what went wrong; it keeps acting until the measured error is gone.
:::
:::

::: explain
## How does adding an integral state make a state-feedback servo robust to constant disturbances and gain errors?

::: model
The integral state is the accumulated error between the reference and the measured output, and it feeds the plant input through its own gain. In any stable steady state all derivatives are zero, including the integral state's derivative, which is the error itself, so the closed loop can only come to rest with the output exactly at the reference. That holds whatever the plant's true gain is and whatever constant disturbance acts on it, because the integrator keeps adjusting the input until the measured error disappears. The design cost is one more pole to place and some extra overshoot, and the integrator must be protected against windup when the actuator saturates.
:::
:::

::: practice
::: check
given: a = 1 | 3; b = 2 | 5; w = 5 | 20
answer: w^2/b
tolerance: 0.5%

## $k_i$ for $\omega_n$ = {w} on $\dot x = -\given{a}x + \given{b}u$?

::: misses
- [any] $\omega_n^2/b$.
:::
:::

::: check
given: p = 2 | 3 | 4 | 5 | 8 | 10
answer: p^3
tolerance: 0.5%

## $k_i$ for a double integrator with triple pole at −{p}?

::: misses
- [any] $p^3$.
:::
:::

::: check
given: a = 1 | 2; b = 3 | 6; k = 2 | 4
answer: b/(a + b*k)
tolerance: 0.5%

## Output shift per unit input disturbance without integral, a = {a}, b = {b}, k = {k}?

::: misses
- [any] $b/(a + bk)$.
:::
:::
:::
