Definition
PID controller
A PID controller is a feedback rule that adjusts an output using the present error, the accumulated past error and the rate the error is changing.
- P reacts to the error now, I to the error built up over time, and D to how fast the error is changing.
- The output is the sum of the three terms, each scaled by a gain.
- Tuning the three gains is the practical work.
A PID controller keeps a measured value close to a target. It compares the target (the setpoint) with the measurement, finds the error, and sets an output from three terms: proportional, integral and derivative. The output is Kp·e + Ki·∫e dt + Kd·de/dt, where e is the error and Kp, Ki and Kd are gains you choose.
Example: a robot holding a set speed
A robot should hold 1.0 m/s. Right now it measures 0.8 m/s, so the error is e = 1.0 − 0.8 = 0.2 m/s. Take the gains Kp = 2, Ki = 1 and Kd = 0.5.
- Proportional: Kp × e = 2 × 0.2 = 0.4. A bigger error pushes harder.
- Integral: suppose the error has been positive for a while and its accumulated total is 0.1. Ki × 0.1 = 0.1. This term grows until a steady shortfall, such as friction, is removed.
- Derivative: the speed is rising, so the error is shrinking at −0.4 m/s per second. Kd × (−0.4) = −0.2. This eases off before the robot overshoots.
Add them: 0.4 + 0.1 − 0.2 = 0.3. The motor command is 0.3 in whatever units the controller uses. The numbers are only for illustration.
Why it matters
PID is used wherever something must hold a value: motor speed, a heater's temperature, a drone's tilt. P alone often leaves a small steady error, I removes it, and D calms oscillation. Too much of any term makes things worse, so gains are tuned by trial. A tilt measurement may come from an IMU. Read tuning a PID controller step by step for a method.
Related terms
Further reading
Reviewed . Next review .
Owner: DuckyHelper