ENع
←Cruise control
Lesson 53 · Control in the real world

Cruise control for a car

18 min11 steps5 questionsAdvanced
About this lesson

One whole design, from model to tuned loop. Model a 1000 kg car with Newton's law, see open loop lose 7.8 m/s on a 4 % hill, see proportional control leave a gap, then add integral action, place both closed-loop poles at −0.2 to pick Kp = 350 and Ki = 40, switch on without a jolt and check the engine limit. Every curve is simulated from the model.

You'll learn to

Tick what you feel confident about. These self-checks do not affect your lesson score.

Fig 53 · Interactive
01 / 11

Hold 25 m/s by itself

A 1000 kg car cruises at 20 m/s. The driver switches on cruise control and sets 25 m/s (90 km/h). From now on a controller must move the car there and hold it, flat road or hill.

car mass        1000 kg
speed now       20 m/s (72 km/h)
set speed       25 m/s (90 km/h)

The design: model the car, try open loop,
close the loop, add integral action, pick
the gains, then check the practical bits.
Loading figure…
or ← →
Read the lesson step by step
  1. Hold 25 m/s by itself

    A 1000 kg car cruises at 20 m/s. The driver switches on cruise control and sets 25 m/s (90 km/h). From now on a controller must move the car there and hold it, flat road or hill.

    car mass        1000 kg
    speed now       20 m/s (72 km/h)
    set speed       25 m/s (90 km/h)
    
    The design: model the car, try open loop,
    close the loop, add integral action, pick
    the gains, then check the practical bits.
  2. Model the car first

    Newton along the road: m·dv/dt = u − b·v − m·g·sinθ. Engine force u pushes; drag b·v and the hill pull back. The transfer function, the rule from force in to speed out, is G(s) = 1/(1000s + 50): time constant 20 s.

    m dv/dt = u - b v - m g sin(theta)
    
    m = 1000 kg   b = 50 N per m/s
    G(s) = V(s)/U(s) = 1 / (1000 s + 50)
         = 0.001 / (s + 0.05)
    time constant  m/b = 20 s
    gain           1/b = 0.02 m/s per N
    
    Drag is really closer to v², so b is a
    straight-line fit near cruising speed.
    
    Lessons: “The transfer function of a system”,
    “First-order response and the time constant”,
    “Linearising a nonlinear system”.
  3. Open loop: a fixed push

    Holding 25 m/s on the flat needs b × 25 = 1250 N, so fix the engine there. The car creeps up with its own 20-second time constant and reaches 24.8 m/s after a minute. The controller never reads the speed.

    # open loop: the force is decided once
    import math
    m, b, dt = 1000, 50, 0.01
    v, force = 20.0, 1250.0
    for n in range(6000):        # 60 s
        target = force / b
        v = target + (v - target) * math.exp(-dt * b / m)
    print(round(v, 1))           # 24.8
  4. A 4 % hill

    At 60 s the road climbs 4 %. Gravity pulls back with m·g·sinθ = 392 N. Nothing tells the fixed force, so the car slows towards 25 − 392/50 = 17.2 m/s, a loss of 7.8 m/s.

    t = 60 s   grade 4 %  (tan theta = 0.04)
    hill force  m g sin(theta) = 392 N
    engine      still 1250 N
    speed at 150 s   17.2 m/s
    heads for   25 - 392/50 = 17.2 m/s
    
    A load the model did not include, and
    open loop cannot see it.
  5. Measure speed, close the loop

    Start again at 20 m/s, now with a speed sensor on the wheels. Its reading goes back to the controller, which works out the error: 25 − 20 = 5 m/s too slow. That return path is feedback.

    sensor     wheel-speed sensor
    reading    20.0 m/s -> controller
    error      goal - speed = 25 - 20 = +5 m/s
    
    error > 0  too slow: push harder
    error < 0  too fast: ease off
  6. Proportional: a gap remains

    Try force = 350 × error. Holding a steady speed still takes 1094 N, and that force needs an error: the car levels off at 21.9 m/s, 3.1 short. On the hill the gap grows to 4.1 m/s.

    # P control: force = Kp * error
    import math
    m, b, dt, Kp = 1000, 50, 0.01, 350
    v = 20.0
    for n in range(6000):        # 60 s
        force = Kp * (25.0 - v)
        target = force / b
        v = target + (v - target) * math.exp(-dt * b / m)
    print(round(v, 1))           # 21.9
    
    steady: v = Kp*25/(b + Kp) = 21.88
  7. Add integral, place poles

    An integral term keeps adding force while any error is left. The loop's poles are the roots of 1000s² + (50 + Kp)s + Ki; they set how fast it settles. Both at s = −0.2 (no wobble) gives Kp = 350, Ki = 40.

    C(s) = Kp + Ki/s,  G(s) = 1/(m s + b)
    1 + C G = 0  ->  m s^2 + (b + Kp) s + Ki = 0
    want (s + 0.2)^2 = s^2 + 0.4 s + 0.04
    
    Kp = 0.4 m - b  = 350 N per m/s
    Ki = 0.04 m     = 40 N per m
    
    zeta = 1, w0 = 0.2 rad/s (critically damped
    poles). The PI zero at -Ki/Kp = -0.11
    will still add a little overshoot.
    
    pole: a root of the bottom of a transfer
          function; zero: a root of the top.
    Lesson: “Poles and zeros on the s-plane”.
  8. Switch on without a jolt

    A practical detail: the integral starts at 1000 N, the force already holding 20 m/s, so switching on causes no lurch. The first command is 350 × 5 + 1000 = 2750 N, inside the engine's 0 to 3000 N.

    integral at switch-on = b * 20 = 1000 N
    first force = 350 * 5 + 1000 = 2750 N
    engine range          0 to 3000 N
    
    Start the integral at 0 instead and the
    engine force drops by 1000 N the moment
    cruise engages: a lurch the driver feels.
  9. PI reaches 25 m/s

    Measure, compare, push, a hundred times a second. The car peaks at 25.36 m/s after 12 s (7.3 % overshoot, added by the PI zero) and settles within 2 % in 24 s. No error is left.

    # PI control, poles at -0.2
    import math
    m, b, dt, Kp, Ki = 1000, 50, 0.01, 350, 40
    v, integral, top = 20.0, 1000.0, 0.0
    for n in range(6000):        # 60 s
        error = 25.0 - v
        force = Kp * error + integral
        integral += Ki * error * dt
        target = force / b
        v = target + (v - target) * math.exp(-dt * b / m)
        top = max(top, v)
    print(round(top, 2))         # 25.36
  10. The hill, rejected

    The same 392 N hill. The speed dips 0.72 m/s, lowest 5 s in, and is back within 0.1 m/s after 22 s. The integral has climbed to 1642 N: 1250 for drag plus 392 for gravity.

    hill at 60 s, 392 N
    
                 P only     PI
    flat         21.9 m/s   25.00 m/s
    hill (150 s)  20.9 m/s   25.00 m/s
    lowest       -          24.28 m/s
    force        -          1642 N
    
    exact: dip = -(D/m) t e^(-0.2t),
    largest at t = 1/0.2 = 5 s
    
    Lesson: “Steady-state error from
    disturbances”.
  11. What the textbook skips

    This run peaked at 2750 N, under the 3000 N limit, so the linear design held. A jump from 20 to 30 m/s would ask for 4500 N: the engine hits its limit and the integral winds up. See “Actuator limits and integrator windup”.

    peak force here   2750 N  (limit 3000 N)
    10 m/s request    350 * 10 + 1000 = 4500 N
    
    Also real:
    - drag is ~v^2: gains tuned at 25 m/s
    - mass changes with passengers and load
    - no derivative term: a first-order car
      does not need one, and D would amplify
      the sensor's noise
    - engine braking is limited: steep descents
      need the real brakes

Quiz Unlocks after the last step.