ENع
→Ziegler-Nichols
الدرس 40 · PID control and compensators

Ziegler-Nichols tuning

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

16 دقيقة10 خطوات5 أسئلةAdvanced
عن هذا الدرس

Tune a PID controller with one experiment instead of a model. Switch off integral and derivative action, raise the gain until a servo swings with constant amplitude, time one swing, and read the three settings off Ziegler and Nichols' table. Then check the result with a simulated step response, see why the rule aims for quarter-amplitude decay, and refine it by hand.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 40 · تفاعلي
01 / 10

Three knobs, no model

A PID controller has three knobs: the gain Kp, the integral time Ti and the derivative time Td. Tuning means choosing them. Ziegler and Nichols, in 1942, gave a recipe that needs one experiment on the loop, not a model.

controller   u = Kp·(e + (1/Ti)∫e dt + Td·de/dt)
             (see the lesson "The PID controller")
plant        G(s) = 1 / (s(s + 1)(s + 5))
feedback     unity: e = command - y

Kp  how hard to push on the error now
Ti  how fast to add up past error
Td  how strongly to react to its trend

The question: which three numbers?
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. Three knobs, no model

    A PID controller has three knobs: the gain Kp, the integral time Ti and the derivative time Td. Tuning means choosing them. Ziegler and Nichols, in 1942, gave a recipe that needs one experiment on the loop, not a model.

    controller   u = Kp·(e + (1/Ti)∫e dt + Td·de/dt)
                 (see the lesson "The PID controller")
    plant        G(s) = 1 / (s(s + 1)(s + 5))
    feedback     unity: e = command - y
    
    Kp  how hard to push on the error now
    Ti  how fast to add up past error
    Td  how strongly to react to its trend
    
    The question: which three numbers?
  2. Start with P only

    Switch off the integral and derivative parts (Ti = ∞, Td = 0), so the controller is just a gain. With Kp = 10 the output overshoots by 49% and settles within 2% after 12.7 s.

    Ti = ∞   no integral action
    Td = 0   no derivative action
    u = Kp·e (proportional only)
    
    Kp = 10
      overshoot   49 %
      settling    12.7 s (2 % band)
    
    The plant has a pole at s = 0, so even P
    alone ends with zero error on a step.
  3. Turn the gain up

    Raise Kp slowly. The swings grow and take longer to die away: at Kp = 20 the overshoot is 76% and settling takes 29 s. On the s-plane the complex pair of poles slides towards the imaginary axis.

    P-only closed loop:
      s³ + 6s² + 5s + Kp = 0
    
    Kp = 10   overshoot 49 %
    Kp = 20   overshoot 76 %, ζ of the pair 0.07
    
    more gain, less damping: the pair moves
    along the root locus towards jω
  4. The edge: ultimate gain

    At Kp = 30 the output swings for ever with a constant size, between 0.06 and 1.94. The pair sits on the imaginary axis at ±2.24j. This gain is the ultimate gain, Ku = 30. Any higher and the swings grow.

    # Routh array for s³ + 6s² + 5s + K
    #   s³ | 1        5
    #   s² | 6        K
    #   s¹ | (30-K)/6
    #   s⁰ | K
    # the s¹ row is zero at K = 30: the edge
    import math
    Ku = 6 * 5               # s¹ row: (6·5 - K)/6 = 0
    w = math.sqrt(Ku / 6)    # from 6s² + Ku = 0
    print(Ku, round(w, 2))   # 30 2.24
  5. Time one swing: Pu

    Time one full swing: peaks at 1.57 s and 4.37 s, so the ultimate period Pu = 2.81 s. It matches 2π/√5 = 2.81 s from the poles. Ku and Pu are the only two numbers the recipe needs.

    # the period from the poles ±j√5
    import math
    w = math.sqrt(5)              # rad/s
    Pu = 2 * math.pi / w
    print(round(Pu, 2))           # 2.81
    
    # on the plot: peaks at 1.57 s and 4.37 s
    # 4.37 - 1.57 = 2.81 s
  6. Read the table

    The Ziegler-Nichols table turns Ku and Pu into settings. For a full PID: Kp = 0.6 Ku = 18, Ti = 0.5 Pu = 1.405 s and Td = 0.125 Pu = 0.351 s. Simpler P and PI rows exist too.

    # Ziegler-Nichols, closed-loop method
    #         Kp         Ti         Td
    # P       0.5 Ku     -          -
    # PI      0.45 Ku    Pu / 1.2   -
    # PID     0.6 Ku     0.5 Pu     0.125 Pu
    import math
    Ku, Pu = 30, 2 * math.pi / math.sqrt(5)
    Kp, Ti, Td = 0.6 * Ku, 0.5 * Pu, 0.125 * Pu
    print(Kp, round(Ti, 3), round(Td, 3))   # 18.0 1.405 0.351
  7. Set the three knobs

    Dial in Kp = 18, Ti = 1.40 s and Td = 0.35 s. The integral adds a pole, and the controller brings two zeros. Because Ti = 4·Td they land together at s = −1.42. The poles move back into the left half-plane.

    C(s) = Kp(Ti·Td·s² + Ti·s + 1) / (Ti·s)
         = 6.322·(s + 1.4235)² / s
    
    zeros   Td·s² + s + 1/Ti = 0
            Ti = 4·Td → double zero at -1/(2·Td)
            = -1.42
    
    closed loop
      s⁴ + 6s³ + 11.322s² + 18s + 12.812 = 0
      pair -0.37 ± 1.62j (ζ 0.22), all four stable
  8. Check the step response

    Now the step, integrated from the tuned loop. The output peaks at 1.67 s with 62% overshoot and stays within 2% after 10.0 s. Stable and fast, but that first swing is large.

    # step response of the Z-N tuned loop, RK4
    import math
    Pu = 2 * math.pi / math.sqrt(5)
    Kp, Ti, Td = 18, 0.5 * Pu, 0.125 * Pu
    y, v, a, z = 0.0, 0.0, Kp * Td, 0.0   # kick from d/dt of the step
    def f(y, v, a, z):
        u = Kp * ((1 - y) + z / Ti - Td * v)
        return v, a, u - 6 * a - 5 * v, 1 - y
    dt, top = 0.001, 0.0
    for n in range(20000):
        s = (y, v, a, z)
        k1 = f(*s)
        k2 = f(*[x + dt / 2 * d for x, d in zip(s, k1)])
        k3 = f(*[x + dt / 2 * d for x, d in zip(s, k2)])
        k4 = f(*[x + dt * d for x, d in zip(s, k3)])
        y, v, a, z = [x + dt / 6 * (p + 2 * q + 2 * r + w) for x, p, q, r, w in zip(s, k1, k2, k3, k4)]
        top = max(top, y)
    print(round(100 * (top - 1)))   # 62
  9. Quarter decay, by design

    This is what the rule aims for. The first overshoot is 0.618, the next 0.147: each swing about a quarter of the one before (0.24). Ziegler and Nichols chose that for fast process plants. Most loops want calmer.

    first overshoot    0.618
    second overshoot   0.147
    ratio              0.24   (about 1/4)
    
    "quarter-amplitude decay": the target the
    rule was built for. It gives a quick answer
    to disturbances but a lively step response
    and small safety margins.
    
    Treat Z-N settings as a starting point.
  10. Refine by hand

    Keep Kp = 18 but lengthen Ti to 3.077 s and Td to 0.769 s. The double zero moves to −0.65 and the overshoot falls to 19%, settling in 5.1 s. Z-N got us close in one experiment; judgment finishes the job.

              Z-N          refined
    Kp        18           18
    Ti        1.405 s      3.077 s
    Td        0.351 s      0.769 s
    zeros     -1.42 (×2)    -0.65 (×2)
    overshoot 62 %         19 %
    settling  10.0 s       5.1 s
    
    Z-N found the right neighbourhood without
    a model; small moves from there tune it.

اختبار يتاح بعد الخطوة الأخيرة.