PID control, explained
In Hebrew: בקר PID
A PID controller sets its output from the error between where a system is and where it should be: one part proportional to the error, one to its accumulated sum, and one to how fast it is changing. Tuning means choosing the three gains.
PID controller calculator
Pre-filled with the worked example below. Change any value.
- Proportional gain K_p
- 4.8
- Integral time T_i
- 1s
- Derivative time T_d
- 0.25s
- Integral gain K_i
- 4.81/s
- Derivative gain K_d
- 1.2s
Embed this calculator
Free to use on a course site, a blog or a class page. Paste this where you want it.
<iframe src="https://carnot.taueng.com/embed/en/pid-control" width="100%" height="560" style="border:0" loading="lazy" title="CARNOT calculator"></iframe>
<p>Calculator by <a href="https://carnot.taueng.com/en/learn/pid-control">CARNOT</a></p>The three terms
The proportional term K_p e reacts to the error now. More gain means a faster, stronger response, and eventually overshoot and oscillation. On its own it often leaves a steady error, for example when a constant load has to be held against.
The integral term adds up the error over time and keeps pushing until the error is gone. That removes the steady error. Too much of it causes overshoot and slow oscillation. When the actuator saturates, the integral keeps growing anyway, and the system overshoots badly once it recovers. This is integral windup, and real controllers limit it.
The derivative term reacts to the rate of change of the error. It anticipates, and damps the overshoot the other two cause. It also amplifies measurement noise, so in practice it is filtered, and it is often applied to the measurement instead of the error, so a step in the setpoint does not produce a spike.
Tuning with Ziegler–Nichols
The classic starting point is the Ziegler–Nichols ultimate gain method. Run the loop with proportional control only and raise K_p until the output oscillates steadily, neither growing nor dying. That gain is K_u and the period of the oscillation is T_u. Then set K_p = 0.6 K_u, T_i = T_u/2 and T_d = T_u/8.
The result is aggressive, with a lot of overshoot. Treat it as a first guess and tune by hand from there: usually less proportional gain, more integral time.
A worked number
A loop starts to oscillate steadily at K_u = 8, with a period T_u = 2 s. Ziegler–Nichols gives K_p = 0.6 × 8 = 4.8, T_i = 2/2 = 1 s and T_d = 2/8 = 0.25 s.
In the parallel form that many software libraries use, K_i = K_p / T_i = 4.8 per second and K_d = K_p T_d = 1.2 seconds.
Common mistakes
- Entering T_i and T_d where a controller expects K_i and K_d, or the reverse. Vendors use both forms, and the numbers are very different.
- Leaving out anti-windup on a loop whose actuator can saturate.
- Running the derivative on a raw, noisy signal, which makes the output chatter.
Mechanical engineering, explained
- The Carnot cycle, explained
- Bernoulli’s equation, explained
- The Reynolds number, explained
- Mohr’s circle, explained
- Von Mises stress, explained
- Euler buckling, explained
- Entropy, explained
- The first law of thermodynamics, explained
- The Rankine cycle, explained
- Heat exchangers and LMTD, explained
- Second moment of area, explained
- Beam deflection, explained
- Stress concentration, explained
- Fatigue and the S–N curve, explained
- Tolerances and fits, explained
- GD&T true position, explained
- Torsion of shafts, explained
- The Brayton cycle, explained
- The Otto and Diesel cycles, explained
- The boundary layer, explained
- Pipe friction losses and the Moody chart, explained
- Natural frequency and resonance, explained