---
title: Tuning PID controllers
heading: First-order-plus-dead-time models from a step test, Ziegler–Nichols rules from the step response and from the ultimate gain, relay autotuning, and SIMC tuning with a single closed-loop time constant
eyebrow: S9 · Lesson 16 · Tuning PID controllers
xp: 50
---

::: hook
Most PID loops are tuned on the plant itself, from a quick experiment, without a detailed model. In 1942 John Ziegler and Nathaniel Nichols published two recipes that turn one simple test into three PID settings. Their rules give aggressive, oscillatory loops, and modern rules such as Sigurd Skogestad's SIMC do much better from the same test, with a single knob that trades speed against robustness. This lesson covers the tests, the rules and what each one gives you.
:::

::: play
- The step response of a first-order-plus-dead-time (FOPDT) plant $\frac{Ke^{-\theta s}}{\tau s + 1}$: nothing for θ seconds, then a first-order rise.
- The dashed tangent at the start of the rise crosses zero at θ and reaches K at θ + τ: that's how the three numbers are read off a measured step response.
- The readouts give SIMC's PI settings with $\tau_c = \theta$, the recommended default.
:::

```sim plot
view: graph
x: t = 0..40 s
y: y = 0..3
slider: K = 0.5..2.5 = 2
slider: tau = 2..20 = 10 s
slider: th = 0.2..5 = 1 s
plot: K*(1 - exp(-(t - th)/tau))*step(t - th) | samples: 600 | label: plant step response
plot: K*(t - th)/tau | dashed | color: ch3 | label: tangent
point: th, 0 | label: θ
point: th + tau, K | label: θ + τ
readout: SIMC Kc = tau/(K*2*th) | digits: 3
readout: SIMC Ti, s = (tau + 8*th - abs(tau - 8*th))/2 | digits: 3
```

::: predict
## Ziegler and Nichols tuned their rules for a decay ratio of one quarter between successive peaks. What overshoot does that imply?

- [ ] About 5%
- [ ] About 15%
- [x] About 40 to 50%
- [ ] None

::: reveal
A quarter-amplitude decay means ζ ≈ 0.215, about 50% overshoot. On the plant $1/(s + 1)^3$ the ultimate-gain PID rule gives 41% overshoot. Ziegler–Nichols settings are a fast starting point; most loops are then detuned.
:::
:::

::: nameit
## Plant tests

- **Step test (reaction curve):** step the actuator and fit $K$ (final change over input change), the apparent dead time θ and time constant τ.
- **Ultimate gain test:** under proportional control, raise the gain until the loop oscillates steadily. That gain is $K_u$ and the oscillation's period $T_u$.
- **Relay test (Åström and Hägglund, 1984):** replace the controller with a relay of amplitude d. The loop settles into a limit cycle at nearly the same period $T_u$, with amplitude a, and $K_u \approx 4d/(\pi a)$ (lesson 43 explains why). It finds the ultimate point safely, without running near instability.

## Ziegler–Nichols rules

| Controller | From $K_u$, $T_u$ | From the step test |
|---|---|---|
| P | $K_p = 0.5K_u$ | $K_p = \tau/(K\theta)$ |
| PI | $K_p = 0.45K_u$, $T_i = T_u/1.2$ | $K_p = 0.9\tau/(K\theta)$, $T_i = 3\theta$ |
| PID | $K_p = 0.6K_u$, $T_i = T_u/2$, $T_d = T_u/8$ | $K_p = 1.2\tau/(K\theta)$, $T_i = 2\theta$, $T_d = \theta/2$ |

## SIMC (Skogestad, 2003)

For an FOPDT plant, choose a closed-loop time constant $\tau_c$ and use PI with

$$K_p = \frac{\tau}{K(\tau_c + \theta)}, \qquad T_i = \min(\tau,\ 4(\tau_c + \theta))$$

$\tau_c = \theta$ gives a fast, robust loop (gain margin about 3, around 10% overshoot); larger $\tau_c$ is slower and gentler. **Lambda tuning** is the same rule with $T_i = \tau$.
:::

::: example
## Tune $P = 1/(s + 1)^3$ by the ultimate-gain method.

::: solution
1. **Ultimate gain and period.** The Routh array (lesson 9) gives $K_u$ = 8 and oscillation at $\sqrt{3}$ rad/s, so
   $$\begin{aligned} T_u &= 2\pi/\sqrt{3} \\ &= 3.63\ \text{s} \end{aligned}$$
2. **Apply the PID rule.**
   $$\begin{aligned} K_p &= 4.8 \\ T_i &= 1.81\ \text{s} \\ T_d &= 0.453\ \text{s} \end{aligned}$$
3. **Check by simulation.** The step response overshoots 41%, peaks at 2.2 s and settles within 2% at 9.4 s: fast but oscillatory, as expected from Ziegler–Nichols.

**Answer:** $K_p$ = 4.8, $T_i$ = 1.81 s and $T_d$ = 0.453 s, which overshoots 41% and settles in 9.4 s.
:::
:::

::: example
## A heater has K = 2, τ = 10 s and θ = 1 s. Tune a PI controller by SIMC.

::: solution
1. **Closed-loop time constant.** Take $\tau_c = \theta$ = 1 s.
2. **Proportional gain.**
   $$\begin{aligned} K_p &= \frac{10}{2 \times 2} \\ &= 2.5 \end{aligned}$$
3. **Integral time.**
   $$\begin{aligned} T_i &= \min(10, 8) \\ &= 8\ \text{s} \end{aligned}$$
4. **Check by simulation.** With the exact delay, the step response overshoots 8.1%, peaks at 4.8 s and settles within 2% at about 10 s, with a gain margin of 3.1 (9.8 dB) and a phase margin of 58°.
5. **Why the shorter $T_i$.** Choosing $T_i$ = 8 s instead of τ = 10 s speeds up the recovery from load disturbances, which matters more than setpoint response for a process like this.

**Answer:** $K_p$ = 2.5 and $T_i$ = 8 s, giving 8.1% overshoot and a 58° phase margin.
:::
:::

::: example
## A relay of ±0.5 drives a loop into a limit cycle of amplitude 0.2 and period 4 s. Tune a Ziegler–Nichols PI controller.

::: solution
1. **Ultimate gain from the relay.** The relay's describing function gives
   $$\begin{aligned} K_u &= \frac{4d}{\pi a} \\ &= \frac{4 \times 0.5}{\pi \times 0.2} \\ &= 3.18 \end{aligned}$$
   and $T_u$ = 4 s.
2. **Ziegler–Nichols PI.**
   $$\begin{aligned} K_p &= 0.45K_u \\ &= 1.43 \\ T_i &= T_u/1.2 \\ &= 3.33\ \text{s} \end{aligned}$$
3. **Why autotuners use it.** The relay test found the ultimate point without ever pushing the loop to the edge of instability.

**Answer:** $K_p$ = 1.43 and $T_i$ = 3.33 s.
:::
:::

::: check
given: K = 2 | 8 | 30; T = 0.5 | 4 | 20
answer: 1.2*K/T
unit: s^-1
tolerance: 0.5%

## An ultimate-gain test finds $K_u$ = {K} and $T_u$ = {T} s. What integral gain $K_i$ does the Ziegler–Nichols PID rule give?

::: right
Right. $K_p = 0.6K_u$ and $T_i = T_u/2$, so $K_i = 1.2K_u/T_u$ = {answer}.
:::

::: misses
- [0.54*K/T] That's the PI rule. The PID rule uses $0.6K_u$ and $T_u/2$.
- [0.3*K*T] $K_i = K_p/T_i$; $T_i$ divides.
- [any] Not yet. $K_i = K_p/T_i$.
:::
:::

::: check
given: d = 1 | 5 | 12; a = 0.1 | 0.5 | 2
answer: 4*d/(pi*a)
tolerance: 0.5%

## A relay of amplitude ±{d} drives a loop into oscillation with amplitude {a} at the plant output. Estimate the ultimate gain.

::: right
Right. $K_u \approx 4d/(\pi a)$ = {answer}: the relay's fundamental is $4d/\pi$.
:::

::: misses
- [d/a] The relay's square wave has a fundamental of $4d/\pi$, larger than d.
- [any] Not yet. Compare the relay's fundamental with the output's amplitude.
:::
:::

::: check
given: K = 0.5 | 2 | 5; t = 5 | 20 | 60; h = 1 | 4; c = 1 | 3
answer: t/(K*(c*h + h))
tolerance: 0.5%

## An FOPDT plant has K = {K}, τ = {t} s and θ = {h} s. What SIMC proportional gain goes with $\tau_c$ = {c}θ?

::: right
Right. $\tau/(K(\tau_c + \theta))$ = {answer}.
:::

::: misses
- [t/(K*c*h)] Add the dead time to $\tau_c$.
- [any] Not yet. $K_p = \tau/(K(\tau_c + \theta))$.
:::
:::

::: check
given: t = 3 | 10 | 40; h = 0.5 | 2; c = 1 | 2
answer: (t + 4*(c*h + h) - abs(t - 4*(c*h + h)))/2
unit: s
tolerance: 0.5%

## For the same SIMC rule, a plant with τ = {t} s and θ = {h} s, and $\tau_c$ = {c}θ: what integral time?

::: right
Right. $\min(\tau, 4(\tau_c + \theta))$ = {answer} s.
:::

::: misses
- [any] Not yet. Take the smaller of τ and $4(\tau_c + \theta)$.
:::
:::

::: check
given: K = 0.5 | 3; t = 2 | 15; h = 0.4 | 2
answer: 1.2*t/(K*h)
tolerance: 0.5%

## A step test gives K = {K}, τ = {t} s and θ = {h} s. What $K_p$ does the Ziegler–Nichols step-response PID rule give?

::: right
Right. $1.2\tau/(K\theta)$ = {answer}, with $T_i$ = 2θ and $T_d$ = θ/2.
:::

::: misses
- [0.9*t/(K*h)] That's the PI rule.
- [any] Not yet. $K_p = 1.2\tau/(K\theta)$.
:::
:::

::: check
given: t = 0.1 | 1 | 5
answer: 2*pi*t/sqrt(3)
unit: s
tolerance: 0.5%

## A plant $K_0/(\tau s + 1)^3$ with τ = {t} s is put under proportional control and the gain raised until it oscillates. What's the period?

::: right
Right. The phase reaches −180° where each pole gives −60°, at $\omega = \sqrt{3}/\tau$: $T_u = 2\pi\tau/\sqrt{3}$ = {answer} s.
:::

::: misses
- [2*pi*t] The crossing frequency is $\sqrt{3}/\tau$, not $1/\tau$.
- [any] Not yet. Find where $(1 + j\omega\tau)^3$ is real and negative.
:::
:::

::: check
kind: parts
given: K = 0.5 | 2 | 5; t = 5 | 20 | 60; h = 1 | 3

## A step test gives K = {K}, τ = {t} s and θ = {h} s. Tune a Ziegler–Nichols PID from the step-response rules.

::: part
answer: 0.6*t/(K*h^2)
tolerance: 0.5%

### What integral gain $K_i$ results?

::: misses
- [any] $K_p = 1.2\tau/(K\theta)$ and $T_i = 2\theta$: $K_i = K_p/T_i$.
:::
:::

::: part
answer: 0.6*t/K
tolerance: 0.5%

### What derivative gain $K_d$?

::: misses
- [any] $K_d = K_pT_d$ with $T_d = \theta/2$.
:::
:::
:::

::: check
kind: derivation
vars: d = 0.1..10, a = 0.01..5, T = 0.1..100

## A relay of amplitude d drives a loop into a limit cycle of amplitude a and period T.

::: step
answer: 4*d/(pi*a)

### What ultimate gain does it imply?
:::

::: step
answer: 0.6*4*d/(pi*a)

### What $K_p$ does Ziegler–Nichols PID give?
:::

::: step
answer: T/2

### What $T_i$?
:::

::: step
answer: T/8

### What $T_d$?
:::

::: right
Right. The relay measures the ultimate point directly, and the rules turn it into a controller.
:::
:::

::: explain
## Why does SIMC choose the closed-loop time constant equal to the dead time by default?

::: model
No controller can make a plant respond before its dead time has passed, so asking for a closed-loop time constant much shorter than θ means demanding more than the plant can deliver, and the loop becomes oscillatory and fragile: small errors in the estimated delay push it toward instability. Asking for a much longer time constant is safe but needlessly slow. Setting $\tau_c = \theta$ balances the two: the loop responds about as fast as the delay allows while keeping a gain margin near 3 and a phase margin between about 47° and 60°, which tolerates realistic errors in the identified K, τ and θ.
:::
:::

::: practice

::: check
given: K = 3 | 15; T = 1 | 10
answer: 1.2*K/T
unit: s^-1
tolerance: 0.5%

## Ziegler–Nichols PID $K_i$ from $K_u$ = {K}, $T_u$ = {T} s?

::: misses
- [any] $1.2K_u/T_u$.
:::
:::

::: check
given: d = 2 | 10; a = 0.3 | 1.5
answer: 4*d/(pi*a)
tolerance: 0.5%

## Ultimate gain from a ±{d} relay and output amplitude {a}?

::: misses
- [any] $4d/(\pi a)$.
:::
:::

::: check
given: K = 1 | 4; t = 8 | 30; h = 0.5 | 3
answer: t/(K*2*h)
tolerance: 0.5%

## SIMC $K_p$ with $\tau_c = \theta$: K = {K}, τ = {t} s, θ = {h} s?

::: misses
- [any] $\tau/(2K\theta)$.
:::
:::
:::
