ENع
←Why feedback
Lesson 04 · What control is

Why feedback: rejecting disturbances and coping with change

12 min10 steps5 questionsBeginner
About this lesson

Feedback is worth the trouble for two reasons. It fights disturbances, pushes from outside that nobody measures, and it copes when the thing being controlled changes. Follow one cruise control up a hill and then towing a trailer, with the throttle fixed (open loop) and with the speedometer fed back to a three-line Python rule (closed loop).

You'll learn to

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

Fig 4 · Interactive
01 / 10

Cruise control at 100 km/h

Cruise control holds a car at a speed the driver picks, here 100 km/h. In the words of “Parts of a loop”: the car is the plant, the engine is the actuator and the speedometer is the sensor.

goal (setpoint)   100 km/h
plant             the car (output: speed)
actuator          engine, throttle 0 to 100 %
sensor            speedometer

The car's speed follows the throttle with
a time constant of 20 s: about how long
it takes to get two-thirds of the way.
Loading figure…
or ← →
Read the lesson step by step
  1. Cruise control at 100 km/h

    Cruise control holds a car at a speed the driver picks, here 100 km/h. In the words of “Parts of a loop”: the car is the plant, the engine is the actuator and the speedometer is the sensor.

    goal (setpoint)   100 km/h
    plant             the car (output: speed)
    actuator          engine, throttle 0 to 100 %
    sensor            speedometer
    
    The car's speed follows the throttle with
    a time constant of 20 s: about how long
    it takes to get two-thirds of the way.
  2. Open loop: 50 % and forget

    On a flat road, 50 % throttle holds exactly 100 km/h. So we fix the throttle at 50 % and never look again. That is open-loop control, as in “Open loop versus closed loop”, and on this flat road it works perfectly.

    throttle   50 %, worked out once
    flat road  2 km/h per % × 50 % = 100 km/h
    
    Open loop is cheap and simple. It is only
    right while the world matches the one we
    worked the number out for.
  3. A hill pulls the car back

    At 20 s the road tilts up. Gravity now pulls the car back: a disturbance, a push from outside that nobody asked for. The throttle stays at 50 %, so the car slows to about 80.0 km/h.

    # open loop on the hill
    import math
    TAU, K = 20, 2         # s, km/h per %
    speed, dt = 100.0, 0.05
    for n in range(2400):        # 120 s
        gas = 50          # throttle, %
        hill = 10 if n * dt >= 20 else 0
        target = K * (gas - hill)
        speed = target + (speed - target) * math.exp(-dt / TAU)
    print(round(speed, 1))     # 80.1
  4. Close the loop

    Now close the loop, as in “Open loop versus closed loop”: the speedometer feeds back. The rule starts at 50 % and adds 5 % throttle per km/h of error, the gap between 100 km/h and the speed. On the flat, error is zero.

    error = 100 - speed     # 0 on the flat
    gas   = 50 + 5 * error   # 50 %
    gas   = min(max(gas, 0), 100)
    
    gas is the throttle, in %, kept between
    0 and 100.
    
    Same starting point as open loop, plus a
    correction that grows with the error.
  5. Feedback climbs the hill

    Same hill, same moment. The speed dips, the error grows, and the throttle opens up to 59.1 %. Within about 7 seconds the car settles at 98.2 km/h. Open loop lost 20.0 km/h; feedback lost 1.8.

    # closed loop on the hill
    import math
    TAU, K = 20, 2         # s, km/h per %
    speed, dt = 100.0, 0.05
    for n in range(2400):        # 120 s
        error = 100 - speed
        gas = min(max(50 + 5 * error, 0), 100)
        hill = 10 if n * dt >= 20 else 0
        target = K * (gas - hill)
        speed = target + (speed - target) * math.exp(-dt / TAU)
    print(round(speed, 1))     # 98.2
  6. It never saw the hill

    No sensor measures the slope. The controller only sees the speed falling, and that is enough. Each km/h lost asks for 5 % more throttle, so the loss shrinks about 11 times: from 20.0 to 1.8 km/h.

                     open loop   closed loop
    throttle         50 %        50 → 59.1 %
    settles at       80.0        98.2 km/h
    
    loss shrinks by 1 + 2 × 5 = 11
    (2 km/h per % × 5 % per km/h: the
     loop gain, met again in later lessons)
  7. Now the car itself changes

    Next trip, the car tows a trailer on a flat road. Nothing pushes from outside this time: the plant itself is different. A quarter more drag (and weight) means the same throttle now gives 20 % less speed.

    bare car        2 km/h per % throttle
    with trailer    1.6 km/h per % throttle (20 % less)
    
    The numbers we tuned for were for a car
    that no longer exists. Real plants change
    too: load, wear, tyres, temperature.
  8. Open loop trusts old numbers

    The open-loop controller still sends 50 %, the right number for a car without a trailer. With the trailer, 50 % only holds 80.0 km/h. Its whole accuracy rested on knowing the car exactly.

    # open loop with the trailer
    import math
    TAU, K = 20, 1.6         # s, km/h per %
    speed, dt = 100.0, 0.05
    for n in range(2400):        # 120 s
        gas = 50          # throttle, %
        target = K * (gas)
        speed = target + (speed - target) * math.exp(-dt / TAU)
    print(round(speed, 1))     # 80.0
  9. Feedback copes with the change

    The same three-line rule, not retuned. The speedometer shows the car falling short, so the throttle rises to 61.1 %. The car holds 97.8 km/h. A 20 % change in the car became a 2.2 % change in speed.

    # closed loop with the trailer
    import math
    TAU, K = 20, 1.6         # s, km/h per %
    speed, dt = 100.0, 0.05
    for n in range(2400):        # 120 s
        error = 100 - speed
        gas = min(max(50 + 5 * error, 0), 100)
        target = K * (gas)
        speed = target + (speed - target) * math.exp(-dt / TAU)
    print(round(speed, 1))     # 97.8
  10. Why feedback is worth it

    Feedback costs a sensor and a rule, and still leaves a small error. In return it fights pushes it cannot see and copes with a plant that is not what we assumed. Those two gifts are why almost every controller uses it.

                     hill        trailer
    open loop        80.0        80.0 km/h
    closed loop      98.2        97.8 km/h
    
    feedback costs   a sensor, a rule, wiring
    it gives         disturbance rejection
                     and tolerance of change
    still left       a small error

Quiz Unlocks after the last step.