Computing Library › Control Theory
Control Theory

PID Control

The PID controller sums proportional, integral, and derivative action on the error, covering most industrial control needs with three tunable gains.

The Three Terms

A PID controller computes the plant command from the error e(t) = reference minus measurement as u(t) = Kp*e + Ki*integral(e dt) + Kd*de/dt. Each term addresses a different aspect of performance.

Kronos motion — three machines

Why each term exists

Proportional-only control leaves a steady offset because a nonzero command requires a nonzero error. The integral term fixes this: it keeps accumulating until the error is exactly zero. The derivative term counteracts the overshoot that high proportional and integral gains introduce, by pushing back when the error is closing quickly.

In Laplace form

The ideal PID transfer function is C(s) = Kp + Ki/s + Kd*s. The integral 1/s contributes infinite DC gain (killing steady-state error) and the derivative s contributes phase lead near crossover (adding stability margin).

Practical refinements

python
def pid_step(e, e_prev, integ, Kp, Ki, Kd, dt):
    integ += e * dt
    deriv = (e - e_prev) / dt
    u = Kp*e + Ki*integ + Kd*deriv
    return u, integ

PID remains dominant because it needs no accurate plant model and its three gains map onto intuitive behavior. Most temperature, flow, pressure, and motion loops in industry are PID. Its limits appear with long delays, strongly coupled multivariable plants, and hard constraints, where model-based methods like MPC do better.