The PID controller
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
A PID controller adds three forces: one for the error now (P), one for the error added up over time (I) and one for how fast the output is moving (D). Follow a cart on a spring through one step command. P alone swings and stops short. With all three terms the cart arrives fast, barely overshoots and stays on target. The three gains also set the closed-loop poles.
A cart on a spring
The plant: a 1 kg cart on a spring (20 N/m) with a damper (10 N·s/m), pushed by a force u. So G(s) = 1/(s² + 10s + 20). We ask it to move 1 m; holding it there takes 20 N against the spring.
plant m·y'' + b·y' + k·y = u
m = 1 kg, b = 10 N·s/m, k = 20 N/m
G(s) = Y/U = 1 / (s² + 10s + 20)
command r = 1 m (a unit step at t = 0)
to hold y = 1 m at rest the spring pulls back
with k·y = 20 N, so the controller must keep
pushing with u = 20 N for ever.اقرأ الدرس خطوة بخطوة
A cart on a spring
The plant: a 1 kg cart on a spring (20 N/m) with a damper (10 N·s/m), pushed by a force u. So G(s) = 1/(s² + 10s + 20). We ask it to move 1 m; holding it there takes 20 N against the spring.
plant m·y'' + b·y' + k·y = u m = 1 kg, b = 10 N·s/m, k = 20 N/m G(s) = Y/U = 1 / (s² + 10s + 20) command r = 1 m (a unit step at t = 0) to hold y = 1 m at rest the spring pulls back with k·y = 20 N, so the controller must keep pushing with u = 20 N for ever.P alone: swing and offset
With proportional control alone, u = 300·e. The cart swings to 1.31 m and settles at 0.94 m, short of 1 m: P pushes only while an error remains, so some error must stay to hold the spring (see "Proportional control and its offset").
Kp, Ki, Kd, dt = 300, 0, 0, 1e-4 y = v = I = 0.0 for n in range(15000): # 1.5 s e = 1.0 - y # P: the error now I += e * dt # I: the error so far u = Kp*e + Ki*I - Kd*v # D: brake on the speed a = u - 10*v - 20*y # cart: y'' = u - 10y' - 20y v += a * dt y += v * dt print(round(y, 2)) # 0.94 resting point: Kp·e = k·y 300·(1 - y) = 20·y → y = 300/320 = 0.9375 m peak 1.31 m at 0.18 s (40 % over its final value)Three terms, one law
PID joins the three terms from "Adding integral and derivative action": u = Kp·e + Ki·∫e dt + Kd·de/dt (our D uses y, step 7). P sees the error now, I the error so far, D how fast it changes. Gains: 300, 200, 20.
u(t) = Kp·e(t) + Ki·∫₀ᵗ e dτ + Kd·de/dt P the present error now I the past error added up so far D the future trend: where it is heading Kp = 300 N/m Ki = 200 N/(m·s) Kd = 20 N·s/m the card runs the same law once every dt: e, the running sum I, the slope D, then uC(s): one pole, two zeros
In Laplace form C(s) = Kp + Ki/s + Kd·s = (20s² + 300s + 200)/s. That is a pole at s = 0, the integrator, plus two zeros, here at −0.70 and −14.30. Three gains place two zeros and the overall gain.
# zeros of C(s) = (Kd s² + Kp s + Ki) / s import cmath Kp, Ki, Kd = 300, 200, 20 d = cmath.sqrt(Kp**2 - 4*Kd*Ki) z = [(-Kp + d) / (2*Kd), (-Kp - d) / (2*Kd)] print(f"{z[0].real:.2f} {z[1].real:.2f}") # -0.70 -14.30 # pole at s = 0: the integrator. It makes the # loop type 1, so a step leaves no error.P: the error now
P pushes in proportion to the error right now. At t = 0 the error is the full 1 m, so P pushes 300 N, the biggest kick of the run. As the cart closes in, the error shrinks and P fades towards zero.
uP = Kp·e = 300 · (1 - y) t = 0 e = 1.000 m uP = 300 N y → 1 e → 0 uP → 0 P alone cannot hold the cart: once e = 0 it pushes nothing. That job goes to I.I: the error so far
I adds up the error over time, so it keeps growing while any error is left. It ends at 19.8 N, heading for exactly the 20 N the spring needs. With I holding that force, P no longer needs an error.
uI = Ki·∫e dt = 200 · (area under e) while e > 0 the area grows, uI climbs when e = 0 the area stops growing, uI holds t = 1.5 s uI = 19.8 N (→ 20 N = k · 1 m) The pole at s = 0 is what removes the offset.D: brake on the trend
D reacts to how fast the cart moves: −20 × its speed. Racing towards the target, D pushes back, down to −142 N at 0.060 s, so the cart barely overshoots. It uses dy/dt, not de/dt, so the step command makes no spike.
uD = -Kd·dy/dt = -20 · speed most negative -142 N at t = 0.060 s at rest 0 N why dy/dt, not de/dt? e = r - y jumps when r steps, so de/dt would be an impulse ("derivative kick"). Since r is constant after the step, -dy/dt = de/dt there.Add them, push the cart
The three terms add into one force, u = P + I + D, and that single force pushes the cart. Early on P dominates, D brakes the rush, and at the end I alone holds the 20 N.
Kp, Ki, Kd, dt = 300, 200, 20, 1e-4 y = v = I = 0.0 for n in range(15000): # 1.5 s e = 1.0 - y # P: the error now I += e * dt # I: the error so far u = Kp*e + Ki*I - Kd*v # D: brake on the speed a = u - 10*v - 20*y # cart: y'' = u - 10y' - 20y v += a * dt y += v * dt print(round(y, 3), round(Ki*I, 1)) # 0.999 19.8PID against P alone
The result: the PID cart peaks at only 1.005 m (0.5% overshoot), stays within 2% of 1 m after 0.24 s and ends on target. P alone swung to 1.31 m and stopped at 0.94 m.
P only PID peak 1.31 m 1.005 m final 0.94 m 1.000 m settles (2%) 0.77 s 0.24 s I removed the offset, D removed the swing, P kept it fast.Three gains, three poles
Closed-loop poles solve s³ + (10 + Kd)s² + (20 + Kp)s + Ki = 0, here s³ + 30s² + 320s + 200: −0.67 and −14.67 ± 9.24j. Each gain sets one coefficient, so the three gains can place all three poles.
1 + C(s)·G(s) = 0 with derivative on y: s(s² + 10s + 20) + Kd s² + Kp s + Ki = 0 s³ + (10+Kd)s² + (20+Kp)s + Ki = 0 s³ + 30s² + 320s + 200 = 0 poles -0.67 -14.67 ± 9.24j P alone: s² + 10s + 320, poles -5 ± 17.18j (lightly damped: the swing you saw). The slow pole at -0.67 sits next to the zero of Kp s + Ki at -0.67, so it barely shows in y.Real PID: forms and limits
Industry often writes Kp(1 + 1/(Ti·s) + Td·s): here Ti = 1.50 s, Td = 0.0667 s. Real controllers also filter D against sensor noise and stop I growing when the motor is at its limit. "Ziegler-Nichols tuning" picks gains by rule.
standard (ISA) form Kp·(1 + 1/(Ti s) + Td s) Ti = Kp / Ki = 1.50 s (integral time) Td = Kd / Kp = 0.0667 s (derivative time) in practice D is low-pass filtered: Kd s / (1 + Td s / N) I is frozen when u saturates (anti-windup) D often acts on y, as here choosing the gains by rule: next lesson, "Ziegler-Nichols tuning".
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01With P control alone (Kp = 300), the cart settles at 0.94 m instead of 1 m. Which term removes that offset?
The integral keeps growing while any error is left. It ends up holding the 20 N the spring needs (19.8 N at 1.5 s, heading for 20), so no error is needed. A bigger Kp only shrinks the offset; it never removes it.
02What is the transfer function of the ideal parallel PID controller?
C(s) = Kp + Ki/s + Kd·s. Over a common denominator that is (Kd s² + Kp s + Ki)/s: a pole at the origin (the integrator) and two zeros.
03Why does the D term in the figure use −Kd·dy/dt instead of Kd·de/dt?
After the step the command is constant, so de/dt = −dy/dt anyway. Acting on y only removes the impulse at the moment the command changes. The closed-loop poles are the same either way.
04For the plant 1/(s² + 10s + 20) with a PID controller (D on y), what is the closed-loop characteristic equation?
Multiply out s(s² + 10s + 20) + Kd s² + Kp s + Ki = 0. Each gain sets one coefficient, so the three gains can place all three poles of this loop.
05A PID controller has Kp = 300, Ki = 200 and Kd = 20. What are Ti and Td in the standard form Kp(1 + 1/(Ti s) + Td s)?
Ti = Kp/Ki = 300/200 = 1.5 s and Td = Kd/Kp = 20/300 = 0.0667 s.
المسرد
- PID controller
- A controller whose output is the sum of three terms: proportional to the error, proportional to the integral of the error, and proportional to the rate of change (of the error or of the output).
- Proportional term (P)
- Kp·e: pushes in proportion to the error right now. Alone it usually leaves a steady-state error.
- Integral term (I)
- Ki·∫e dt: the error added up over time. It keeps changing until the error is zero, which removes steady-state error to a step.
- Derivative term (D)
- Kd·de/dt, or −Kd·dy/dt: reacts to how fast things change, adding damping. Real controllers low-pass filter it against noise.
- Derivative kick
- The spike a derivative of the error produces when the command steps. Taking the derivative of the measured output instead avoids it.
- Integral windup
- When the actuator is at its limit, the integral keeps growing and later causes a large overshoot. Anti-windup stops the integral while the actuator is saturated.
- Standard (ISA) form
- Kp(1 + 1/(Ti s) + Td s), with integral time Ti = Kp/Ki and derivative time Td = Kd/Kp.
الملاحظات والمصادر
- The cart (1 kg, 20 N/m, 10 N·s/m) and the gains are round illustrative numbers, not a measured machine. Every curve is integrated from the closed loop (RK4, 0.1 ms steps) and every number in the text is measured on those curves.
- Here P and I act on the error but D acts on the measured position (often called PI-D). The closed-loop poles are the same as for the textbook form Kp + Ki/s + Kd·s; only the zeros differ, and the command step no longer produces an infinite derivative spike.
- The slow closed-loop pole at −0.67 nearly cancels the zero at −Ki/Kp = −0.67, so it hardly shows in the step response. A load pushing on the cart would still excite it: the integral then removes the resulting error slowly.
- The Python is plain Python 3 with a simple Euler loop at 0.1 ms; it prints the same numbers as the RK4 model to the digits shown. With python-control, ct.step_response(ct.tf([300, 200], [1, 30, 320, 200])) gives the same PID curve.
- N. S. Nise, Control Systems Engineering, 8th ed., Wiley (ch. 9, design via root locus: PI, PD and PID)
- K. Ogata, Modern Control Engineering, 5th ed., Pearson (ch. 8, PID controllers and modified PID controllers)
- G. F. Franklin, J. D. Powell, A. Emami-Naeini, Feedback Control of Dynamic Systems, 8th ed., Pearson (ch. 4)
- K. J. Åström and R. M. Murray, Feedback Systems, 2nd ed., ch. 11 PID Control (windup, filtering the derivative, setpoint weighting)
- MIT OpenCourseWare 16.06 Principles of Automatic Control (S. Hall)
- MIT OpenCourseWare 6.302 Feedback Systems (Roberge, Dawson, Lundberg)
- python-control: control.step_response
اختبار يتاح بعد الخطوة الأخيرة.