Home/Documentation

PID Control Documentation

How a PID controller works — the PID equation, P/I/D action, digital PID, anti-windup, derivative filtering, FOPDT plant models, Ziegler–Nichols, Cohen–Coon, IMC, SIMC and AMIGO tuning, performance metrics and gain/phase margin. The same numerics used by the free PID calculator and simulator.

1. What is a PID controller?

A PID (Proportional–Integral–Derivative) controller is a feedback mechanism that continuously measures the difference between a desired setpoint (SP) and the measured process variable (PV), and drives an actuator so that this error is reduced to zero. It is by far the most widely used control algorithm in industry — temperature loops, motor drives, flow, level and pressure control all typically run on PID.

The error is defined as e(t) = SP − PV. The controller combines three responses to that error: one proportional to its present value, one to its accumulated history, and one to its rate of change.

2. The PID equation

The parallel (independent-gain) form used throughout the solver is:

u(t) = Kp·e(t) + Ki·∫e(t)dt + Kd·de(t)/dt

The equivalent standard (time-constant) form is:

u(t) = Kp · [ e(t) + (1/Ti)·∫e(t)dt + Td·de(t)/dt ]

The two parameterisations are related by Ti = Kp/Ki and Td = Kd/Kp. The solver lets you switch between Kp/Ki/Kd and Kp/Ti/Td and converts automatically. Setting Ki = 0 gives Ti = ∞ (no integral action).

3. Proportional, integral and derivative action

Proportional — Kp

Reacts to the present error. Raising Kp speeds up the response and shrinks the offset, but too much gain makes the loop oscillate and eventually go unstable. On a self-regulating process, pure P control always leaves a steady-state offset because a non-zero output requires a non-zero error.

Integral — Ki (Ti)

Accumulates past error and keeps pushing until the error is exactly zero — this is what removes steady-state offset. The price is added phase lag: too much integral action causes overshoot, slow oscillation, and integral windup when the actuator saturates.

Derivative — Kd (Td)

Anticipates future error from its current rate of change. It adds damping, reduces overshoot and shortens settling time, but it amplifies measurement noise, so it is normally filtered (Tf = Td/N) and taken on the measurement rather than the error to avoid derivative kick.

4. Controller structures — P, PI, PD, PID

  • P — fast and simple, but leaves an offset. Used where a small steady-state error is acceptable (e.g. some level loops).
  • PI — the industrial workhorse. Removes offset and is robust to noise (no derivative). Used for flow, pressure and most process loops.
  • PD — fast and well damped but retains an offset. Used in motion/servo systems where a static error is tolerable.
  • PID — full three-term control for demanding loops with significant lag or dead time (temperature, complex mechanical systems).

In the solver, selecting a structure automatically disables the terms it does not use, and the simulator's comparison panel shows all four side by side for the current gains.

5. Digital / discrete PID

A digital controller evaluates the loop once every sample time Ts. The integral is accumulated numerically and the derivative is a finite difference. As a rule of thumb pick Ts ≤ τ/10 and well below the dead time — a coarse sample time behaves like extra dead time and destabilises the loop. The solver validates this and warns when the sample time is too large; internally it integrates the plant with a fourth-order Runge–Kutta (RK4) method for accuracy.

6. Advanced controller features

Output saturation

Real actuators have limits (0–100 % valve, ±24 V, etc.). The output is clamped to [u_min, u_max].

Anti-windup (back-calculation)

When the actuator saturates, the integral keeps charging and the loop overshoots badly on recovery. Back-calculation recomputes the integral so the unsaturated output sits exactly on the limit, eliminating windup.

Derivative filtering

The ideal derivative has infinite high-frequency gain. A first-order filter with Tf = Td/N (N ≈ 8–20) makes derivative action usable on noisy measurements.

Derivative kick & setpoint weighting

Taking the derivative of the measurement instead of the error, and weighting the setpoint in the proportional term (P = Kp(b·SP − PV), b < 1), removes the large output spike caused by a step change in setpoint.

Integral limits

An explicit clamp on the integral term as a second line of defence against windup and to bound the controller's authority.

7. Process (plant) models

The solver simulates three standard linear process models:

First order
G(s) = K / (τs + 1)
First order plus dead time (FOPDT)
G(s) = K·e^(−Ls) / (τs + 1)
Second order
G(s) = K / (τ²s² + 2ζτs + 1)

K is the process gain, τ the time constant, L the transport dead time and ζ the damping ratio. Dead time is applied as a true transport delay on the actuator signal. For tuning and stability analysis, higher-order models are reduced to an equivalent FOPDT approximation (Skogestad's half-rule).

8. Tuning methods

The auto tuner returns gains from every classical and modern rule, each with its assumptions and the exact formulas. All rules operate on the FOPDT parameters (K, τ, L); Ku and Pu are the ultimate gain and period at the stability limit.

MethodKpTiTdWhen to use
Ziegler–Nichols (reaction curve)1.2·τ / (K·L)2L0.5LFast, aggressive; ~20–50 % overshoot (quarter-amplitude decay).
Ziegler–Nichols (ultimate cycle)0.6·KuPu / 2Pu / 8Uses the ultimate gain Ku and period Pu at the stability limit.
Cohen–Coon(1/(K·R))·(1.35 + R/4)L·(2.5 + 0.46R)/(1 + 0.61R)L·0.37/(1 + 0.19R)Dead-time dominant FOPDT plants (R = L/τ); fast disturbance rejection.
IMC / Lambda(τ + L/2)/(K·(λ + L/2))τ + L/2τ·L/(2τ + L)Pick closed-loop time constant λ to trade speed vs robustness.
SIMC / Skogestad(1/K)·τ/(τc + L)min(τ, 4(τc + L))0The process-industry standard; τc = L is fast yet robust.
AMIGO(1/K)·(0.2 + 0.45·τ/L)L·(0.4L + 0.8τ)/(L + 0.1τ)0.5·L·τ/(0.3L + τ)Robust across a wide L/τ range; good disturbance rejection.
Tyreus–LuybenKu / 2.22.2·PuPu / 6.3Damped ultimate-cycle variant; well-behaved industrial responses.

Classical rules such as Ziegler–Nichols are deliberately aggressive; SIMC, AMIGO and Tyreus–Luyben give slower but far more robust and better-damped responses that are usually preferred in practice.

9. Numerical optimisation

Beyond formula-based tuning, the optimiser runs a Nelder–Mead simplex search over the (log) gains, repeatedly simulating the closed loop and minimising a chosen objective:

  • Minimise overshoot, settling time or rise time
  • Minimise steady-state error
  • Minimise an error integral — IAE = ∫|e|dt, ISE = ∫e²dt or ITAE = ∫t·|e|dt
  • Balanced response (a weighted combination)

The search finds a good local optimum for the given model — it is not a proof of global optimality, and the result is only as good as the model. Soft constraints penalise overshoot, Ms, gain margin and phase margin that miss the limits you set (defaults: OS ≤ 25 %, Ms ≤ 2, GM ≥ 6 dB, PM ≥ 30°). Industrial extras (noise, load, rate limit, stiction, sensor lag) are included in every trial simulation.

10. Performance metrics

  • Rise time — time from 10 % to 90 % of the commanded step, interpolated between samples.
  • Peak time & overshoot — when and how far the response exceeds the setpoint: (peak − setpoint) / step size × 100 %.
  • Settling time (±2 %) — the last instant the response leaves a ±2 % band around the setpoint.
  • Steady-state error — mean residual offset over the last 10 % of the run (so sensor noise does not dominate a single final sample).
  • IAE / ISE / ITAE — error integrals (trapezoidal). ISE punishes large early errors; ITAE punishes long-lasting errors; IAE sits between the two.
  • Oscillations & windup — a count of response reversals and a flag when the output is saturated for a large fraction of the run.

Metrics are computed numerically from the simulation. The solver's written interpretations are engineering suggestions, not mathematically guaranteed outcomes.

11. Stability & robustness margins

The solver also analyses the loop in the frequency domain. From the open loop L(jω) = C(jω)·G(jω) it computes:

  • Phase margin (PM) — extra phase lag the loop can tolerate before instability, measured at the gain-crossover frequency. Aim for 30–60°.
  • Gain margin (GM) — factor by which the gain can rise before instability, measured at the phase-crossover frequency. Aim for > 6 dB.
  • Crossover frequencies — ωc (|L| = 1) approximates the closed-loop bandwidth; ωp (∠L = −180°) is where the gain margin is read.
  • Maximum sensitivity Ms — peak of |S(jω)| = |1/(1+L)|. AMIGO and most industrial rules target Ms ≤ 1.4–2.0 (1.8 is a common default). Ms captures robustness that gain and phase margin can miss.
  • Model-error sweep — the same PID is replayed on a 3×3 grid of K at 0.8× / 1.0× / 1.2× and L (or τ) scaled by ±20–30 %. A tuning only earns a pass if every perturbed plant stays stable with overshoot ≤ 25 % and Ms ≤ 2.

A controller with healthy margins tolerates model error and disturbances; margins that are too small mean a fast but fragile loop. These are linearised estimates based on the FOPDT approximation — always confirm with the time-domain simulation.

12. Industrial test signals

To evaluate a controller the way a real plant would, the simulator can layer industrial effects on top of a run:

  • Load disturbance — a step added to the plant input at a chosen time, to test how quickly the loop rejects a process upset.
  • Measurement noise — reproducible Gaussian noise on the sensor, to check derivative filtering and gain choices under realistic conditions.
  • Setpoint ramp — a rate-limited setpoint instead of an ideal step, which reduces overshoot and actuator stress.
  • Actuator rate limit — max |du/dt|. Valves and drives cannot jump; a rate limit turns a “robust” PID into a saturating, winding loop.
  • Stiction / deadband — the valve holds until the command leaves a band around the last position. The usual reason a flow or level loop hunts while the linear sim looks fine.
  • Sensor lag — a first-order transmitter lag on PV before the controller.

13. Identification & relay auto-tune

The Identify tab fits a FOPDT model from an open-loop bump test (CSV of t, u, y) using the Sundaresan–Krishnaswamy 28.3 % / 63.2 % two-point method, then a short refine of L against the measured curve. Apply K, τ, L into the simulator when the overlay residual is small.

Relay auto-tune (Åström–Hägglund) sits in the Auto tune tab. A relay of amplitude d with hysteresis ε drives a limit cycle; Ku = 4d/(πa) and Pu from the period feed Ziegler–Nichols and Tyreus–Luyben from a measured ultimate point instead of the FOPDT formula.

14. Units & export

Setpoint and process variable can be entered in common engineering units (°C, K, °F, Pa, kPa, bar, psi, rpm, rad/s, m, mm, L/min, m³/h and more). Values are converted through a consistent internal base unit. Any run can be exported as a CSV data file, PNG charts, a JSON configuration or a print-ready PDF report containing the parameters, model, metrics, graphs and interpretation.

15. Gain-effect quick reference

What happens when you increase each parameter, holding the others constant?

ChangeRise timeOvershootSettlingSteady-state errorStability
Increase KpDecreasesIncreasesSmall changeDecreasesDegrades
Increase KiDecreasesIncreasesIncreasesEliminatedDegrades
Increase KdSmall changeDecreasesDecreasesNo effectImproves (noise-sensitive)
Increase TiIncreasesDecreasesDecreasesSlower removalImproves
Increase TdSmall changeDecreasesDecreasesNo effectImproves then degrades

Trends assume a typical self-regulating process; for integrating processes or unusual dynamics the effect can reverse. Always confirm with the simulator on your own model.

16. Suggested workflow

  1. Identify K, τ, L from a bump test, or pick a process model / example.
  2. Choose a controller structure (start with PI, add D only if you need it).
  3. Run the auto tuner (SIMC or AMIGO, or a relay test) and apply a robust rule.
  4. Simulate and read the metrics, Ms and stability margins.
  5. Sweep K and L under model error. Add load, noise, rate limit and stiction.
  6. Fine-tune manually or run the constrained optimiser against your objective.
  7. Export a CSV / PDF report for documentation.