ENع
→Motor speed control
الدرس 51 · Control in the real world

DC motor speed control

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

18 دقيقة11 خطوة5 أسئلةAdvanced
عن هذا الدرس

One whole design, start to finish: model a small DC motor from its two equations, turn them into a transfer function, set specs, then tune P, PI and PID. The textbook PID meets every spec on paper, then turns out to need 10 100 V from a 24 V driver. A PI tuned for the volts you actually have meets the specs for real and shrugs off a drag on the shaft.

ستتعلّم

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

شكل 51 · تفاعلي
01 / 11

Hold a motor at 1 rad/s

A small DC motor spins a flywheel. Our job: hold it at 1 rad/s (radians per second, about 9.5 turns a minute), even when something drags on the shaft. We go the whole way: model, tune, then the snags textbooks skip.

setpoint   1 rad/s  (1 rad/s = 60/2π ≈ 9.5 rpm)
plant      DC motor + flywheel
actuator   driver, −24 to +24 V
sensor     encoder on the shaft
disturbance  a drag torque on the load

Model → transfer function → specs →
tune → check what real hardware allows.
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. Hold a motor at 1 rad/s

    A small DC motor spins a flywheel. Our job: hold it at 1 rad/s (radians per second, about 9.5 turns a minute), even when something drags on the shaft. We go the whole way: model, tune, then the snags textbooks skip.

    setpoint   1 rad/s  (1 rad/s = 60/2π ≈ 9.5 rpm)
    plant      DC motor + flywheel
    actuator   driver, −24 to +24 V
    sensor     encoder on the shaft
    disturbance  a drag torque on the load
    
    Model → transfer function → specs →
    tune → check what real hardware allows.
  2. Two equations, one motor

    Voltage V drives current i through the winding (R = 1 Ω, L = 0.5 H); the spinning rotor pushes back with K·ω. Current makes torque K·i, which turns the rotor (inertia J = 0.01 kg·m²) against friction b·ω (b = 0.1 N·m·s).

    electrical   L·di/dt = V − R·i − K·ω
    mechanical   J·dω/dt = K·i − b·ω − T_load
    
    J = 0.01 kg·m²   b = 0.1 N·m·s
    K = 0.01 N·m/A (= V·s/rad)
    R = 1 Ω          L = 0.5 H
    
    K·ω is the back-emf: a spinning motor
    is also a generator.
  3. The transfer function

    Laplace-transform both and remove i: ω/V = 0.01 / (0.005s² + 0.06s + 0.1001). Its poles (the motor's natural decay rates, 1/0.5 s and 1/0.1 s) are −2.0 and −10.0: overdamped, no overshoot. One volt gives 0.0999 rad/s, so we fix 10.01 V.

    ω(s)      K                    0.01
    ──── = ───────────────── = ──────────────────────
    V(s)   (Js+b)(Ls+R) + K²   0.005s² + 0.06s + 0.1001
    
    poles   s = −2.0, −10.0   (time constants 0.5 s, 0.1 s)
    DC gain 0.0999 rad/s per volt
    open loop  V = 1 / 0.0999 = 10.01 V
  4. A drag on the shaft

    At 2.5 s a brake puts 0.01 N·m of drag on the flywheel. The voltage stays at 10.01 V because nothing measures the speed, so the motor slows to 0.90 rad/s and stays there. That 10 % loss is a disturbance.

    t = 2.5 s   T_load 0 → 0.01 N·m
    V stays 10.01 V
    
    steady drop = T_load·R / (R·b + K²)
                = 0.01 / 0.1001 = 0.0999 rad/s
    speed at 4 s   0.90 rad/s
  5. Measure, compare, set specs

    An encoder measures the shaft speed and the controller computes the error e = 1 − ω every millisecond. Our specs for a 1 rad/s step: settle within 2 s, overshoot under 5 %, steady error under 1 %.

    every 1 ms:
      read ω from the encoder
      e = setpoint − ω = 1 − ω
      compute V, send it to the driver
    
    specs (1 rad/s step)
      settling time (2 %)   < 2 s
      overshoot             < 5 %
      steady-state error    < 1 %
  6. Proportional only

    Try V = 100·e. The speed overshoots by 25.3 % and settles at 0.909 rad/s, 9.1 % short: a P controller needs some error to make any voltage. It fails two specs. More gain shrinks the error but adds overshoot.

    V = 100·e
    
    final speed = 100·0.0999 / (1 + 100·0.0999)
                = 0.909 rad/s
    steady error  9.1 %      spec < 1 %   ✗
    overshoot     25.3 %     spec < 5 %   ✗
    
    characteristic eq.  s² + 12s + 220.02
  7. Add integral action

    Add 200 × the running total of error × time. While any error is left the total keeps growing, so the steady error goes to zero. But the extra push makes the overshoot worse: 30.9 %.

    V = 100·e + 200·∫e dt
    
    steady error  0 %        spec < 1 %   ✓
    overshoot     30.9 %     spec < 5 %   ✗
    settling      0.78 s     spec < 2 s   ✓
    
    The integral term makes the loop type 1:
    zero error for a constant setpoint.
  8. Add derivative: done on paper

    Add 10 × the rate of change of the error, a brake on fast swings. Overshoot drops to 1.0 % and the speed settles in 0.26 s with no error. Every spec is met. This is where most textbook examples stop.

    # textbook PID   prints 1.0 10100.2: 1 kHz digital loop, motor by RK4
    J, b, K, R, L, dt = 0.01, 0.1, 0.01, 1.0, 0.5, 0.001
    f = lambda w, i, V: ((K*i - b*w)/J, (V - R*i - K*w)/L)
    w = i = I = e_old = 0.0; top = Vtop = 0.0
    for n in range(2500):                 # 2.5 s
        e = 1.0 - w; I += e*dt
        V = 100*e + 200*I + 10*(e - e_old)/dt; e_old = e
        a = f(w, i, V); c = f(w + dt/2*a[0], i + dt/2*a[1], V)
        d = f(w + dt/2*c[0], i + dt/2*c[1], V); g = f(w + dt*d[0], i + dt*d[1], V)
        top, Vtop = max(top, w), max(Vtop, V)
        w, i = (w + dt/6*(a[0] + 2*c[0] + 2*d[0] + g[0]), i + dt/6*(a[1] + 2*c[1] + 2*d[1] + g[1]))
    print(round((top - 1)*100, 1), round(Vtop, 1))
  9. Now look at the voltage

    The setpoint jumps, so the error's rate of change is huge for one sample: the PID asks for 10 100 V for 1 ms (derivative kick), then −102 V to brake the surge. Holding speed takes 10.0 V; our driver gives 24 V at most.

    t = 0      e jumps 0 → 1
               D = (1 − 0) / 0.001 = 1000 per s
               V = 100 + 0.2 + 10·1000 = 10 100 V
    t = 2 ms   V = −102 V  (the D term brakes the surge)
    steady     V ≈ 10.0 V  (no drag)
    
    driver limit  ±24 V
    The paper design assumes volts we do not have.
  10. Tune for the volts you have

    Drop the derivative and use V = 20·e + 40·∫e. Ki/Kp = 2 puts the PI zero at −2, cancelling the slow motor pole. Overshoot 1.7 %, settling 0.58 s, peak 21.2 V: every spec, inside 24 V.

    # tuned PI   prints 1.7 21.2: 1 kHz digital loop, motor by RK4
    J, b, K, R, L, dt = 0.01, 0.1, 0.01, 1.0, 0.5, 0.001
    f = lambda w, i, V: ((K*i - b*w)/J, (V - R*i - K*w)/L)
    w = i = I = e_old = 0.0; top = Vtop = 0.0
    for n in range(2500):                 # 2.5 s
        e = 1.0 - w; I += e*dt
        V = 20*e + 40*I
        a = f(w, i, V); c = f(w + dt/2*a[0], i + dt/2*a[1], V)
        d = f(w + dt/2*c[0], i + dt/2*c[1], V); g = f(w + dt*d[0], i + dt*d[1], V)
        top, Vtop = max(top, w), max(Vtop, V)
        w, i = (w + dt/6*(a[0] + 2*c[0] + 2*d[0] + g[0]), i + dt/6*(a[1] + 2*c[1] + 2*d[1] + g[1]))
    print(round((top - 1)*100, 1), round(Vtop, 1))
  11. The drag again

    The same 0.01 N·m drag hits at 2.5 s. The speed dips to 0.932 rad/s, the integral raises the voltage to 11.0 V, and it is back within 1 % after 0.59 s. Open loop lost 10 % for good.

    drag at 2.5 s, 0.01 N·m
    
                   open loop   tuned PI
    lowest speed   0.90        0.932
    voltage after  10.01 V     11.0 V
    speed at 4 s   0.90        1.000
    
    The integral found the extra 1 V by itself.

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