P 0.00r = 1e 1.00I 0.00u 0.00D 0.00y 0.000y 0.000
goal 10.833: offset 0.167024681000.51time (s)yOUTPUT y(t), GOAL r = 1PPIPD
Lit wire with moving dashes: a signal is flowing along itBlocks: goal, compare (e = r − y), the P, I and D terms, the sum and the plantBar on a term block: its share of u, positive to the right; the plot shows y(t) computed from the modelThe pill travelling back along the front is the measured output y: feedbackOne plant, 1/((s+1)(s+2)), and three controllers. The error splits to a P block and an I block; the D block reads the output itself from the feedback wire. Each block's bar is its share of the plant input u. The plot below is simulated from the model as the steps play: P leaves an offset, integral action removes it, derivative action calms the overshoot. Textbooks often write PD as Kp·e + Kd·de/dt, which adds a zero at s = −Kp/Kd = −5 and gives an impulse in u when the goal steps. Taking the derivative of the output instead (as here) keeps the same closed-loop poles and avoids that kick; Åström and Murray, Feedback Systems, ch. 11, discuss this under setpoint weighting.

The offset

  1. Our plant is G(s) = 1/((s+1)(s+2)) and the goal steps to 1. Proportional control, u = 10·e, overshoots by 22.1% and then settles at 0.833. An error of 0.167 stays for ever.

Integral action

Derivative action

Choosing

What is happening

# step 1/10 · offset
# about: Goal, Compare, P term, Sum, Plant, P

# P only
Kp, Ki, Kd, dt = 10, 0, 0, 0.0001
y = v = I = 0.0               # output, its speed, integral
for n in range(100000):       # 10 s
    e = 1.0 - y               # goal r = 1
    u = Kp * e + I - Kd * v   # P + I + D
    a = u - 3 * v - 2 * y     # plant: y'' + 3y' + 2y = u
    y, v = y + v * dt, v + a * dt
    I += Ki * e * dt
print(f"{y:.3f}")              # 0.833

The plant 1/((s+1)(s+2)) is a textbook example in normalised units, not a measured machine. Every curve and number is simulated from it with the same Python loop shown on the steps (Euler steps of 0.1 ms); the final values and overshoots agree with the closed-form results. The Python on the run steps is plain Python 3 with no libraries. python-control can check the same loops: control.feedback(C * G) with C = control.tf([10, 5], [1, 0]) for PI.