Cruise control for a car
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
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.
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.
اقرأ الدرس خطوة بخطوة
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.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”.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.8A 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.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 offProportional: 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.88Add 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”.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.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.36The 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”.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
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01The car model is G(s) = 1/(1000s + 50). What is its time constant?
Write it as (1/50) / ((1000/50)s + 1): the time constant is m/b = 1000/50 = 20 s, and the steady-state gain is 1/b = 0.02 m/s per newton.
02With force = 350 × error and no integral, why does the car settle at 21.9 m/s instead of 25 m/s?
At steady speed the engine must balance drag (b·v). With u = Kp·e, a non-zero force means a non-zero error: v = Kp·25/(b + Kp) = 21.875 m/s.
03The PI loop's characteristic polynomial is 1000s² + (50 + Kp)s + Ki. Which gains put both poles at s = −0.2?
(s + 0.2)² = s² + 0.4s + 0.04. Matching after dividing by 1000: (50 + Kp)/1000 = 0.4 gives Kp = 350, and Ki/1000 = 0.04 gives Ki = 40.
04Both closed-loop poles are real and equal, yet the speed overshoots 25 m/s. Why?
The setpoint response is (350s + 40) / (1000(s + 0.2)²). Its zero gives a 7.3 % overshoot; the hill response has no zero, so its dip is exactly −(D/m)·t·e^(−0.2t).
05Why does the integral start at 1000 N when cruise control is switched on at 20 m/s?
1000 N is the force that was already holding 20 m/s (b × 20). Starting the integral there makes the hand-over bumpless; starting at 0 would cut the force by 1000 N the moment cruise engages.
المسرد
- Transfer function
- The rule, written in the Laplace variable s, that turns a system's input into its output. For the car (the plant, the thing being controlled) G(s) = 1/(1000s + 50) turns engine force into speed.
- Pole
- A value of s that makes the bottom of a transfer function zero. Where the poles sit decides how fast a system settles and whether it wobbles.
- Zero
- A value of s that makes the top of a transfer function zero. The PI controller adds one at −Ki/Kp, which speeds up the rise and adds a little overshoot.
- Time constant
- How long a first-order system takes to cover about 63 % of a change. For the car it is m/b = 20 s.
- Steady-state error
- The error left once everything has settled. Proportional control leaves one here; integral action drives it to zero.
- Integral action
- A controller term that adds up the error over time, so it keeps pushing until no error is left.
- Pole placement
- Choosing controller gains so the closed-loop characteristic polynomial has the roots (poles) you want.
- Bumpless transfer
- Starting a controller's internal state so its first output matches what the actuator was already doing: no jolt.
الملاحظات والمصادر
- The car is a simple linear model with illustrative numbers: 1000 kg, drag and rolling loss of 50 N per m/s, engine force 0 to 3000 N. Every curve and number in the figure is computed from that model. Its transfer function G(s) and 20 s time constant are explained in “The transfer function of a system” and “First-order response and the time constant”; what happens when the engine hits its limit is in “Actuator limits and integrator windup”.
- Real aerodynamic drag grows with the square of speed (½·ρ·Cd·A·v²). The straight-line b·v is a linearisation that holds near the cruising speed; the lesson “Linearising a nonlinear system” shows how to get it.
- With both closed-loop poles at −0.2 the PI loop alone would not overshoot, but the controller's zero at −Ki/Kp = −0.114 speeds up the rise and adds 7.3 % overshoot. The hill response has no such zero, so its dip is exactly −(D/m)·t·e^(−0.2t). Poles and zeros are taught in “Poles and zeros on the s-plane”; why the hill leaves no lasting error is in “Steady-state error from disturbances”.
- The Python on each step is plain Python 3 with the math module. It updates the controller every 0.01 s and moves the car forward with the exact solution of its equation between updates, just as the figure does.
- K. J. Åström and R. M. Murray, Feedback Systems: An Introduction for Scientists and Engineers, 2nd ed. (free online; §4.1 cruise control)
- python-control documentation, cruise control example (Murray and Åström): vehicle model, PI design by pole placement, anti-windup
- G. F. Franklin, J. D. Powell, A. Emami-Naeini, Feedback Control of Dynamic Systems, 8th ed., Pearson (ch. 2 cruise model; ch. 4 PID)
- N. S. Nise, Control Systems Engineering, 8th ed., Wiley (ch. 9, PI compensation)
- K. Ogata, Modern Control Engineering, 5th ed., Pearson (ch. 8, PID controllers)
- MIT OpenCourseWare 16.06 Principles of Automatic Control (S. Hall)
- MIT OpenCourseWare 6.302 Feedback Systems (Roberge, Dawson, Lundberg)
اختبار يتاح بعد الخطوة الأخيرة.