seegongsik
SC · Control

PID Control

A PID controller responds to error in three ways. The proportional term (P) responds to the present error, the integral term (I) to the accumulated past error, and the derivative term (D) to the trend in which it is changing. In this lesson you move the three gains and see how I removes the steady-state error that P alone leaves, while overshoot and oscillation are kept in check by balancing the gains, until the response is fast, accurate, and smooth.

Three terms for a fast, accurate response

A PID controller is put on the plant G(s) = 1/((s + 1)(s + 2)) to make it follow the target value 1 (dashed line). The gold curve is the closed-loop step response from t = 0 to 12, and the steady-state error and overshoot in the display below are measured on the curve over these 12 seconds. At first there is only the proportional gain Kp = 4, so the output stops at 4/6 ≈ 0.67, leaving a steady-state error of 0.33. Raise the integral gain Ki and the remaining error accumulates and pushes the output up to the target; even Ki = 2 brings the error almost to 0 within 12 seconds. Raising Ki a lot, though, increases the overshoot, so you end up adjusting Kp and Kd together to find a response that is fast, error-free, and smooth.

closed-loop step response (dashed = setpoint)
proportional gain Kp4.0
integral gain Ki0.0
derivative gain Kd0.0
The three gains and the response
Kp = 4.0 · Ki = 0.0 · Kd = 0.0
steady error = 0.33 · overshoot = 0.00
The integral gain is small, so even after 12 seconds the output falls short of the target (steady-state error above 0.1). With the proportional term alone, a control input exists only while some error remains, so the error cannot reach 0 in steady state. Raise the integral gain Ki and the remaining error accumulates until the output reaches the target.
Large error or ringing

Present, past, and future of the error

A PID controller takes a single error e(t), the difference between the target value and the output, and adds it up in three ways to form the control input u = Kp·e + Ki·∫e dt + Kd·de/dt. The proportional term responds immediately in proportion to the present error, pushing hard when the error is large and gently when it is small; it is the most intuitive term. The integral term accumulates the error over time, so even a small error that lingers keeps growing the integral until it pushes that error out. The derivative term responds to how fast the error is changing, so when the error is shrinking quickly it foresees the coming overshoot and applies the brakes. In effect, the three look at the error's present, past, and future.

Observeu(t) = Kp·e + Ki·∫e dt + Kd·de/dt
A PID responds to error with three terms.
Chooseremoves steady-state offset: the ?
The integral term removes steady-state error.
Fill inadds damping, cuts overshoot: the ?
The derivative term adds damping and cuts overshoot.
On your ownthe D term amplifies ?
The derivative term amplifies noise, so it usually gets a filter.

The limit of P, the accuracy of I, the stability of D

Proportional control alone leaves a steady-state error. Since the control input is u = Kp·e, keeping an input other than 0 in steady state requires the error e not to be 0. The plant in this example has a DC gain of 1/2, so with Kp alone the output stops at Kp/(2 + Kp) and always falls short of the target. The integral term solves this. As long as any error remains, the integral keeps accumulating and increasing the input, and it stops only when the error is exactly 0, so the steady-state error becomes 0. In exchange, the integral adds a pole at the origin that delays the phase and makes the response prone to oscillation, while the derivative term does the opposite, advancing the phase and adding damping. Setting the speed with proportional, erasing the error with integral, and adding damping with derivative is the division of labor in PID.

Tuning and real-world pitfalls

PID is the standard tool of industrial control, used for temperature, speed, position, and flow alike. Choosing the three gains is called tuning, and because speed, overshoot, and robustness are interlocked, improving one tends to hurt another. The classic Ziegler–Nichols method switches off the integral and derivative terms and raises only the proportional gain to find the critical gain at which the system just starts oscillating steadily, along with that oscillation period. This is the stability boundary seen with the Routh test in the F1 unit and the Nyquist criterion in the F4 unit, and from there the three gains are set by following a table. Reality has traps, too. The derivative term amplifies fast changes and therefore measurement noise as well, so it usually comes with a low-pass filter, and, as in this plot, the derivative is sometimes applied only to the output so that the input does not jump the instant the target steps. Also, if the integral keeps accumulating while the input is stuck at its limit, it later pushes too hard, a problem called integral windup, which anti-windup schemes prevent.

Back to the first screen

On the first screen, you put a PID controller on the plant G = 1/((s + 1)(s + 2)) and tuned the three gains. With only the proportional gain, a steady-state error remained, the output stopping short of the target. Raising the integral gain accumulated the remaining error and lifted the output exactly to the target, but raising it too far increased overshoot and ringing. Adjusting proportional and derivative together to add damping smoothed the response again. With proportional handling speed, integral accuracy, and derivative damping, the three together produced a response that is fast, error-free, and well damped. The loops analyzed so far with the Routh test, the root locus, the Bode plot, and the Nyquist plot have now been shaped into the form you want by designing a controller.

The PID controller u = Kp·e (proportional, present error) + Ki·∫e dt (integral, accumulated past) + Kd·de/dt (derivative, trend of change) responds to a single error with three terms. Proportional sets the speed but leaves a steady-state error, integral accumulates until the error is 0 and removes the steady-state error (at the cost of phase lag), and derivative reads changes ahead to add damping and reduce overshoot (at the cost of amplifying noise, so it needs a filter). Tuning is a trade-off among speed, overshoot, and robustness, and the Ziegler–Nichols method starts from the critical gain (the stability boundary of the F1 and F4 units). The closed-loop characteristic equation of this example is s³ + (3 + Kd)s² + (2 + Kp)s + Ki.
On to the next unit

PID shaped the response in the time domain by adding three terms. The tool that does the same job in the frequency domain, aiming directly at the phase and gain of the Bode plot, is the compensator. The next unit, Lead and Lag Compensation, inserts into the loop a small transfer function made of one pole and one zero. A lead compensator raises the phase near the crossover frequency to enlarge the phase margin, so like the derivative term it adds damping and speed, while a lag compensator raises the gain at low frequencies to improve steady-state accuracy, so like the integral term it reduces error. What the D and I of a PID did, a compensator does again by shaping phase and gain on the Bode plot.