Computer Systems Modelling · Section 8.6 · Interactive lab

PID control

Section 8.6 describes three ways in which a controller can turn the error e = r − y into a control input: in proportion to the error, to its integral, or to its derivative. In this lab you close a unity feedback loop around one of three plants from the book, choose the loop gains, and see the closed-loop poles and the step response change together. You can also add a step disturbance partway through a run, to see how well each kind of controller rejects it. The open-loop behaviour of the first- and second-order plants is covered in the First- and Second-Order Systems Lab.

How it works and what to try

How it works: In four tabs, one for each of §8.6.1–8.6.4. Close a unity feedback loop around the integrator plant of Example 8.2, a first-order plant (Equation 8.7) or a second-order plant (Equation 8.9), set the loop gains Kp, Ki and Kd, and watch the closed-loop poles in the s-plane and the step response change together. Turn on a step disturbance partway through a run to see how well each mode rejects it. Readouts give the poles, final value, steady-state error, peak and settling time, and each tab has Python code that reproduces them. Presets reproduce Examples 8.9–8.11.

Try this: With proportional control alone, watch the droop of a first-order plant shrink as Kp grows but never vanish. Add integral gain and see the droop disappear, then raise Ki until the response overshoots, and with the second-order plant until the loop goes unstable. See derivative control alone leave a steady-state error and let a disturbance drift away for ever, and then add damping to a second-order plant. Find PID gains that give a fast response with little overshoot and no steady-state error.

Section, example and equation numbers refer to Chapter 8 (Control Theory) of S. Keshav, Mathematical Foundations of Computer Networking, Addison-Wesley, 2012.

Proportional-mode control

With proportional control, the control input is a multiple of the error, u = Kpe, or U = KpE in the transform domain, where Kp is the loop gain (Section 8.6.1). With unity feedback, H = 1, the fundamental equation of a feedback system becomes

Y = KpG1 + KpG R + G1 + KpG WEQ 8.17

Write the plant as G = N/D. Multiplying the top and bottom of each fraction by D shows that both terms have the denominator D + KpN. So the closed-loop poles are the roots of D(s) + KpN(s) = 0, and changing the loop gain moves them.

Example 8.9 controls the request buffer of the Web server of Example 8.2, which is an integrator, G(s) = 1/s. With u = (r − y)/τ, the loop gain is 1/τ, the closed-loop pole is at −1/τ, and the step response is y(t) = 1 − e−t/τ. The steady state error is zero for every loop gain.

Section 8.6.1 warns that this is not true in general. If the plant needs a nonzero control input to hold its output steady, a proportional controller can produce it only from a nonzero error, called the droop. The first-order system of EQ 8.7 is such a plant. In this tab you can watch the droop shrink as Kp grows, but never vanish.

Plant G(s)

The request buffer of the Web server: G(s) = 1/s, a single pole at s = 0.

G(s) = K/(1 + τs) (EQ 8.7), a pole at −1/τ.

1
1

The controller

1

Disturbance

0.5
10

The disturbance is added at the plant input, as in EQ 8.14: Y = GU + GW. As printed, Examples 8.9 to 8.11 subtract W instead, which flips the sign of their disturbance terms. The errata correct this.

Time axis

The closed loop (EQ 8.17, H = 1)

—
—
closed-loop poles
—
final value of y
—
steady state error r − y(∞)
—
peak of the response to r
—
settling time (within 2%)
—

The final value and steady state error come from the final-value theorem, and include the disturbance if it is on. The peak and settling time are for the response to the step in r alone.

Output y(t)the response to a unit step in r at t = 0
y(t)setpoint r = 1response without the disturbancekept curves (faint)
The s-plane× closed-loop poles; × poles of the plant alone (faint); shaded: the right half-plane
Python · poles, final value and step response

    

What to notice

With the integrator plant, increasing Kp moves the single closed-loop pole to the left, so the output reaches the setpoint faster. The final value stays at 1 whatever the gain, as Example 8.9 shows.

Switch to the first-order plant. With Kp = 0 the closed-loop pole is the plant's own pole at −1/τ. As Kp grows, the pole moves to the left and the response speeds up, but the final value is less than 1. The final-value theorem gives the droop: the response to r has the value KKp/(1 + KKp) at s = 0.

Turn on the disturbance with the integrator plant. The output moves away from the setpoint and settles at a new level. For the integrator to hold its output steady, u + w must be zero, so the controller must supply u = −w. A proportional controller can do this only with an error of −w/Kp. Proportional control removes the steady state error caused by a step in r here, but not the error caused by a step in w.

Try these

  1. Example 8.9 with τ = 2: choose the preset. Where is the closed-loop pole, and what is the settling time? Now double Kp. What happens to each?
    Show answer
    With Kp = 1/τ = 0.5 the pole is at −0.5 and the output is within 2% of 1 after 7.82 s, which is τ ln 50. Doubling Kp to 1 moves the pole to −1 and halves the settling time to 3.91 s. The final value stays at 1.
  2. Choose the first-order plant with K = 1 and τ = 1. Read off the final value for Kp = 1, 4 and 9. How large must Kp be to bring the steady state error down to 5%?
    Show answer
    The final values are 0.5, 0.8 and 0.9, and the poles are at −2, −5 and −10. The steady state error is 1/(1 + Kp), so an error of 5% needs Kp = 19, which puts the pole at −20. A small droop needs a large loop gain, which Section 8.6.1 warns can reduce damping and cause instability in less simple plants.
  3. Choose the integrator plant with Kp = 1 and a disturbance of size 0.5 at t = 10 s. What is the final value? What is it with Kp = 5?
    Show answer
    The final value is 1.5 with Kp = 1 and 1.1 with Kp = 5. In both cases the error after the disturbance is −w/Kp: a larger gain shrinks it but cannot remove it. The next tab shows how integral mode does.
  4. Why does the integrator plant have no droop in response to a step in r, while the first-order plant does?
    Show answer
    In steady state the output of the integrator is constant only if its input is zero. So the controller must supply u = 0, which a proportional controller does with zero error. The first-order plant settles at K times its input, so holding y near 1 needs u near 1/K, which a proportional controller can produce only from a nonzero error.