Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 37 Β· PID and Compensators

PID Tuning and Ziegler-Nichols Methods

Tune a PID controller with the Ziegler-Nichols step-response and ultimate-gain methods, a relay autotuner, and a gentler rule, with every result simulated in Python.

You know what the three terms do (PID basics). Now comes the practical question: which three numbers? Tuning by trial and error works but is slow and, on a real furnace or a heavy motor, risky. In the 1940s Ziegler and Nichols published two experiments that turn a quick measurement into starting values for Kp, Ti and Td. The rules are crude (they target a quarter-amplitude decay ratio, which rings), but they remain the standard first guess, and every later method is understood by comparison.

We tune the plant P(s) = 1/(s+1)Β³. Its ultimate gain is easy to derive: phase reaches -180Β° when 3Β·arctan(Ο‰) = 180Β°, so Ο‰u = tan(60Β°) = √3 β‰ˆ 1.732 rad/s and |P(jΟ‰u)| = 1/(1+3)^(3/2) = 1/8. Therefore Ku = 8 and the ultimate period is Tu = 2Ο€/√3 β‰ˆ 3.63 s.

Method 1: ultimate gain (closed-loop)

  1. Set the controller to P only (Ki = Kd = 0).
  2. Raise Kp until the output oscillates steadily, neither growing nor decaying. That gain is Ku; the oscillation period is Tu.
  3. Read the controller settings from the table.
Controller Kp Ti Td
P 0.5 Ku
PI 0.45 Ku Tu / 1.2
PID 0.6 Ku Tu / 2 Tu / 8

For our plant, the PID entry gives Kp = 4.8, Ti = 1.81 s, Td = 0.45 s, i.e. Ki = Kp/Ti β‰ˆ 2.65 and Kd = KpΒ·Td β‰ˆ 2.18.

Method 2: reaction curve (open-loop)

When driving a loop to sustained oscillation is too dangerous, step the open-loop input instead. Many processes then show an S-shaped curve. Draw the tangent at the steepest point; where it crosses the starting value gives the apparent dead time L, and the time it takes to climb to the final value gives the time constant T. With process gain K (the final value for a unit step) the rules are:

Controller Kp Ti Td
PI 0.9 T/(K L) 3.33 L
PID 1.2 T/(K L) 2 L 0.5 L
Python Extract L and T from a step response

Press Run (or Ctrl + Enter) to see the result here.

Program input Β· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The inflection of three equal lags is at t = 2, with slope 2eβ»Β²β‰ˆ0.27, which gives L β‰ˆ 0.8 and T β‰ˆ 3.7. The open-loop rule suggests Kp = 5.5, Ti = 1.6 s, Td = 0.4 s, close to the ultimate-gain answer (4.8, 1.81, 0.45). A first-order-plus-dead-time fit of a third-order lag is crude, which is why Ziegler-Nichols numbers are starting points, not answers.

Comparing settings by simulation

Let us run three tunings on the real plant: ZN ultimate-gain, a gentler "Tyreus-Luyben" setting, and the hand-picked PID from the previous lesson.

Python Compare tuning rules

Press Run (or Ctrl + Enter) to see the result here.

Program input Β· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You will see the classic Ziegler-Nichols behavior: about 41% overshoot for the PID and 56% for the PI, well above the 25% many designers accept, with long ringing tails. Tyreus-Luyben trades speed for far lower overshoot (about 3%) and a slower creep to the final value (settling near 20 s) and is a better default when oscillation is expensive. This is why people say: use ZN to get in the neighborhood, then detune. A common fix is to halve Kp and keep the time constants.

Relay autotuning

Driving a plant to the edge of instability by hand is risky. Relay feedback (Γ…strΓΆm and HΓ€gglund) does the same experiment safely: replace the controller by a relay that switches the output between +d and -d when the error changes sign. Most plants settle into a limit cycle with amplitude a and period Tu, and the ultimate gain follows from describing-function analysis: Ku β‰ˆ 4d/(Ο€a). Commercial "autotune" buttons work this way.

Python Relay feedback finds Ku and Tu

Press Run (or Ctrl + Enter) to see the result here.

Program input Β· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The estimate lands within a few percent of the exact Ku = 8, Tu = 3.63 s, and it never needs the loop to be unstable. The describing-function approximation is not exact, which is the source of the small error.

Practical tuning advice

  • Start with Kd = 0, Ki = 0. Raise Kp until the response is fast but slightly oscillatory, then reduce it by about half.
  • Add Ki until the steady-state error disappears in a reasonable time. Too much Ki gives overshoot and slow oscillation.
  • Add Kd only if you need more damping and the sensor is clean; filter it.
  • Tune with the real constraints in mind: actuator limits, noise, and the worst-case operating point (gain often changes with load).
  • Re-check margins after tuning: see margins.

Ziegler-Nichols closed-loop tuning means pushing a real process to sustained oscillation. Never do this on equipment where a limit cycle could cause damage; use the relay method or the reaction-curve method instead.

Check your understanding

Quick check Β· 4 questions

of 4 answered You scored / 4 Β· perfect!

  1. 1. In the ultimate-gain method, what do you measure?

    You increase Kp until a sustained oscillation appears; that gain is Ku and the oscillation period is Tu.
  2. 2. For Ku = 8 and Tu = 3.63 s, the Ziegler-Nichols PID proportional gain is:

    Kp = 0.6 * Ku = 4.8.
  3. 3. Ziegler-Nichols tuning typically gives:

    The rules target a quarter-amplitude decay, which means significant overshoot; most loops need detuning.
  4. 4. Why use relay feedback for autotuning?

    The relay produces a bounded limit cycle whose amplitude and period give Ku and Tu safely.

Summary

  • Ziegler-Nichols gives first guesses from either Ku, Tu (closed loop) or L, T (open loop).
  • The rules are aggressive; expect overshoot above 25% and detune.
  • Relay feedback estimates Ku and Tu safely: Ku β‰ˆ 4d/(Ο€a).
  • Tyreus-Luyben and halved gains are less oscillatory alternatives.
  • Always simulate or test on the real plant and check margins after tuning.

Next: Lead and Lag Compensators