Lab 02: Vehicle Cruise Control

Overview

A car at highway speed is a mass pushed by the engine against aerodynamic drag, rolling resistance and gravity on grades. We build the model from physics, identify it from a logged throttle step, and treat a hill as a disturbance to see why P control leaves a speed deficit and PI removes it. The PI zero is then placed on the root locus, a lag compensator is compared with PI, and a steep hill saturates the throttle and winds up the integrator.

A sedan on a highway grade with the forces acting on it, and the cruise-control loop with the PI controller, throttle saturation, engine lag, vehicle dynamics and wheel-speed sensor

The cruise-control problem of lab 02: the forces on the car and the block diagram of the loop.

The system

The demos use a mid-size sedan and the homework a mid-size SUV.

quantity demo: mid-size sedan homework: mid-size SUV basis
mass $m$ / effective mass $m_{eff}$ 1550 / 1610 kg 2050 / 2130 kg representative values
drag coefficient $C_d$, frontal area $A$ 0.29, 2.30 m² 0.35, 2.80 m² representative
rolling coefficient $C_{rr}$ 0.010 0.011 representative (highway tyres)
$F_{max}$ (full throttle, top gear) 1600 N 2200 N torque × overall ratio / wheel radius, representative
engine lag $\tau_e$, delay 0.6 s, 0.1 s about 0.8 s, identify from the log representative
cruise speed $v_0$ 27 m/s 25 m/s
linearized $b$, $K$, $\tau$ 21.6 N s/m, 0.740 (m/s)/%, 74.5 s computed in homework Problem 1a computed
sensors (10 Hz) wheel speed in 0.1 km/h steps with 0.02 m/s noise; GPS speed with 0.12 m/s noise same representative

The car obeys

$$ \begin{aligned}m_{eff}\,\dot v&=F-\tfrac12 \rho C_d A v^2-C_{rr} m g \cos\vartheta-m g \sin\vartheta-F_{gust},\\\tau_e \dot F&=F_{max}\,u/100-F,\end{aligned} $$

where the throttle $u$ (0-100 %) reaches the engine one 0.1 s loop sample after it is computed and after the 0.1 s actuation delay, so the sedan has 0.8 s of engine lag and delay in all. Linearized about $v_0$ on a flat road,

$$ \begin{aligned}G(s) &= \frac{K}{(\tau s + 1)(\tau_e s + 1)},\\b &= \rho C_d A v_0, \quad K = \frac{F_{max}}{100\, b}, \quad \tau = \frac{m_{eff}}{b},\end{aligned} $$

and a grade enters at the plant input as $d = -100\, m g \sin\vartheta / F_{max}$ in % throttle. The logs were simulated from the nonlinear model above with wind-gust forces of 15 N rms, and they are not measurements from a real vehicle.

step course tool lecture
physics model and linearization against a logged throttle step (demo 1) modeling, first-order step response L3, L6-L7
grade as an input disturbance, speed deficit under P control (demo 2) block diagrams, steady-state error L2, L12
P-gain limit from the root locus with a Padé delay (demo 2) root locus L13-L15
PI zero placement, phase margin against hill recovery, lag against PI (demo 3) root-locus design, lag compensator L13-L18
9 % hill: throttle saturation, windup, clamping anti-windup (demo 4) PID implementation L19
margins of the final loop, identified against true model (demo 4) Bode plot, gain and phase margins L20-L22, L26

Demo 1: a cruise-control model from physics and from a throttle step

Linearized about the cruise speed, the car is a first-order lag with a time constant of more than a minute, in series with a short engine lag. Throttle sets the engine force $F = F_{max} u/100$ after the lag $\tau_e$, and because drag $\tfrac12\rho C_d A v^2$ grows with speed, the car settles where the force and the road load balance. About $v_0$ the drag changes by $b\,\delta v$ with $b = \rho C_d A v_0$, which gives

$$ \begin{aligned}G(s) &= \frac{\delta V}{\delta U} = \frac{K}{(\tau s + 1)(\tau_e s + 1)},\\K &= \frac{F_{max}/100}{b}, \quad \tau = \frac{m_{eff}}{b}.\end{aligned} $$

At 27 m/s the physics predicts $b = 21.6$ N s/m, $K = 0.740$ (m/s)/% and $\tau = 74.5$ s, with a trim throttle of 27.7 %. A first-order-plus-dead-time fit to the wheel-speed log of a 28 % to 33 % throttle step gives $K = 0.653$ (m/s)/%, $\tau = 66.2$ s and $\theta = 2.41$ s, and the GPS speed gives nearly the same $K$ and $\tau$ with a larger residual (0.147 m/s against 0.084 m/s).

The step moved the car from about 27.2 to 30.5 m/s. Drag is quadratic in speed, so its effective slope over the step is the chord $\tfrac12\rho C_d A(v_0 + v_1)$, which is larger than the tangent at 27 m/s: the car looks stiffer than the tangent model predicts. The chord model ($K = 0.693$, $\tau = 69.7$ s) explains most of the gap of about 12 %, and wind gusts during the test, a slow random force that the car integrates, account for the remaining few percent. The fitted dead time of 2.4 s is poorly determined by a test whose time constant is over a minute and is much longer than the 0.8 s of engine lag and delay in the simulated car (the 0.6 s lag, the 0.1 s delay and one 0.1 s loop sample), so a design based on it is conservative. The data and the fit are fixed, so this demo is shown as computed by the lab script.

Wheel and GPS speed during a throttle step from 28 to 33 percent, the FOPDT fit and the physics model from the tangent at 27 m/s

The throttle step log with the FOPDT fit to the wheel speed and the physics model linearized at 27 m/s.

Demo 2: a hill is a disturbance that P control cannot fully reject

When the road tilts up, gravity pulls back with $m g \sin\vartheta$. In the block diagram this force enters at the plant input, like a throttle reduction. A proportional cruise controller answers with more throttle, but only in proportion to the speed error, so the car settles below the set speed. With trim throttle $u_0$ and $u = u_0 + K_p(r - v)$, the grade adds $d = -100\, m g \sin\vartheta / F_{max}$ at the plant input, and

$$ \begin{aligned}V &= \frac{K_p G}{1 + K_p G}\, R + \frac{G}{1 + K_p G}\, D,\\\Delta v_{ss} &= \frac{K |d|}{1 + K K_p}.\end{aligned} $$

A 3 % grade is worth $d = -28.5$ % throttle. A higher $K_p$ shrinks the deficit, and the root locus of $K_p G(s)$, with a first-order Padé model of the fitted dead time, shows how far the gain can go: $K_p = 22.6$ %/(m/s) gives a dominant pair with $\zeta = 0.7$, a phase margin of 63° and a gain margin of 2.97, and leaves a 1.2 m/s deficit on a 3 % grade.

The interactive version takes $K_p$ and the grade. The noise and gust sequence is the one of the demo’s $\zeta = 0.7$ run, so at $K_p = 5$ the simulated drop is 4.49 m/s instead of the 4.60 m/s of the class figure, which used a different random seed for that gain.

Interactive: P cruise control on a grade

The button loads Python (Pyodide with numpy, scipy, matplotlib and python-control, about 40 MB on the first visit, cached afterwards) into this page; after that, changing a parameter re-runs the computation and redraws the figures. Until then the figures and numbers below are the output of the original demo script with the default parameters.

22.58 gives ζ = 0.7 on the Padé model
Static view: pre-rendered figures from the original script.
Printed by the original demo script (default parameters)
3 % grade: m g sin = 456 N = -28.5 % throttle; identified K = 0.653 (m/s)/%
Kp for zeta = 0.7: 22.6 %/(m/s), poles [-0.311+0.317j -0.311-0.317j]; PM = 63 deg, GM = 2.97
Kp =   5.0: speed drop predicted 4.36 m/s, simulated 4.60 m/s
Kp =  10.0: speed drop predicted 2.47 m/s, simulated 2.48 m/s
Kp =  22.6: speed drop predicted 1.18 m/s, simulated 1.17 m/s
Root locus of Kp G(s) with a Padé(1) delay model and the poles for zeta = 0.7
Root locus of Kp G(s) with a Padé(1) delay model and the poles for zeta = 0.7 (pre-rendered by the original script)
P cruise control on a 3 % grade for Kp = 5, 10 and 22.6
P cruise control on a 3 % grade for Kp = 5, 10 and 22.6 (pre-rendered by the original script)
Python output
(appears after the first live run)
Show code
Loading the source...

The deficit falls like $1/(1 + K K_p)$ but never reaches zero, and $K_p$ cannot grow much beyond the $\zeta = 0.7$ value without ringing and without passing more sensor noise to the throttle. At large gains on steep grades the throttle also saturates, and the linear prediction no longer holds.

Demo 3: where to put the PI zero, and lag against PI

An integrator, $C(s) = K_c (s + z)/s$, removes the speed deficit on a hill, and the zero location $z$ is the design choice. Cancelling the slow vehicle pole with $z = 1/\tau$ looks tidy, but the grade enters before the plant, so the cancelled pole still appears in the disturbance response as a recovery that takes about two minutes. Moving $z$ to the left speeds the recovery and costs phase margin. The disturbance-to-speed transfer function is

$$ \frac{V}{D} = \frac{G}{1 + C G}, $$

whose DC gain is zero with the PI (a type 1 loop). The closed-loop pole that sits near $-z$ sets the tail of the recovery, roughly $e^{-z t}$. A lag compensator $K_c (s + z)/(s + p)$ is an almost-PI: it raises the low-frequency gain by $z/p$ but keeps an error,

$$ e_{ss} = \frac{K |d|}{1 + K K_c z/p}. $$

The demo keeps the P gain $K_c = 22.6$ %/(m/s) and sweeps $z$ from $1/\tau = 0.0151$ rad/s to 0.2 rad/s. The phase margin with the exact delay falls from 59° to 19°, while the recovery of the linear model to within 0.2 m/s after a 3 % grade falls from 126 s to 14 s. The largest zero with $PM \ge 50°$ is $z = 0.0494$ rad/s, which gives $K_i = K_c z = 1.114$ %/m.

Recovery time and phase margin against the PI zero location, with the cancelling zero and the design zero marked

PI zero sweep at fixed Kc on the linear model: faster hill recovery costs phase margin.

The interactive version takes the zero, the gain and the grade, and switches between PI and a lag with $p = z/10$. It draws the root locus with the closed-loop poles at $K_c$, and drives the nonlinear sedan up the grade with the same noise and gust sequence as the class figure.

Interactive: PI zero placement and the lag compensator

The button loads Python (Pyodide with numpy, scipy, matplotlib and python-control, about 40 MB on the first visit, cached afterwards) into this page; after that, changing a parameter re-runs the computation and redraws the figures. Until then the figures and numbers below are the output of the original demo script with the default parameters.

1/τ = 0.0151 cancels the slow vehicle pole
Static view: pre-rendered figures from the original script.
Printed by the original demo script (default parameters)
Kc = 22.6 %/(m/s) (P design, zeta = 0.7); slow plant pole 1/tau = 0.0151 rad/s
   z [rad/s]  PM [deg]  slowest pole  max drop [m/s]  recovery to 0.2 m/s [s]
     0.0151     59.2     -0.0151        1.08         125.7
     0.0232     57.1     -0.0242        1.04          82.0
     0.0357     53.7     -0.0397        1.00          53.6
     0.0550     48.7     -0.0692        0.96          35.4
     0.0845     41.3     -0.1413        0.91          24.2
     0.1300     31.4     -0.1444        0.86          17.7
     0.2000     19.1     -0.0788        0.80          13.6
design: largest z with PM >= 50 deg -> z = 0.0494 rad/s, Ki = Kc z = 1.114 %/m
P              : max drop 1.29 m/s, error at 300 s 1.23 m/s, recovery to 0.2 m/s never
lag (z/p = 10) : max drop 0.98 m/s, error at 300 s 0.16 m/s, recovery to 0.2 m/s 256 s
PI, z = 1/tau  : max drop 1.08 m/s, error at 300 s 0.07 m/s, recovery to 0.2 m/s 117 s
PI, design z   : max drop 0.97 m/s, error at 300 s 0.04 m/s, recovery to 0.2 m/s 43 s
lag predicted e_ss = 0.13 m/s
Root loci for the cancelling zero, the design zero and a zero too far left, with the poles at Kc
Root loci for the cancelling zero, the design zero and a zero too far left, with the poles at Kc (pre-rendered by the original script)
P, lag and PI on the nonlinear car, 3 % grade at t = 20 s
P, lag and PI on the nonlinear car, 3 % grade at t = 20 s (pre-rendered by the original script)
Python output
(appears after the first live run)
Show code
Loading the source...

The table and the sweep figure come from the linear model, and the last five lines from the nonlinear car, which is why the design zero recovers in 39.2 s in the sweep and in 43 s on the car. With the cancelling zero the slowest closed-loop pole stays at $-0.0151$ rad/s, and the car needs 117 s to come back within 0.2 m/s. The lag removes most of the deficit but creeps toward its 0.13 m/s steady error over several minutes.

Demo 4: a steep hill saturates the throttle and the integrator winds up

On a 9 % grade the sedan needs more force than the engine delivers in top gear, so the throttle sits at 100 % and the speed drops whatever the controller commands. The throttle needed on a grade is

$$ u = u_0 + \frac{100\, m g \sin\vartheta}{F_{max}}, $$

which is 113 % at 27 m/s on 9 %. While the throttle is saturated the loop is open, and a plain PI integrator, $\dot I = K_i e$, keeps accumulating the error during the climb. At the crest the integrator holds far too much, and the car overshoots the set speed for a long time. Clamping anti-windup stops integrating while the throttle is saturated and the error pushes further into saturation. The PI is the demo 3 design with the zero rounded to 0.05 rad/s ($K_p = 22.6$ %/(m/s), $K_i = 1.13$ %/m).

The interactive version takes the grade of the 60 s climb (5 s ramps, crest at $t = 85$ s) and runs the PI with and without anti-windup; the checkbox selects the run that is highlighted and summarized.

Interactive: a steep hill, windup and anti-windup

The button loads Python (Pyodide with numpy, scipy, matplotlib and python-control, about 40 MB on the first visit, cached afterwards) into this page; after that, changing a parameter re-runs the computation and redraws the figures. Until then the figures and numbers below are the output of the original demo script with the default parameters.

above about 7.6 % the throttle saturates
Static view: pre-rendered figures from the original script.
Printed by the original demo script (default parameters)
PI: Kp = 22.6 %/(m/s), Ki = 1.13 %/m
9 % grade needs 113 % throttle at 27 m/s (limit 100 %)
anti-windup True : min speed 20.49 m/s, overshoot after crest 0.65 m/s, back within 0.3 m/s 30 s after crest, throttle at 100 % for 59 s
anti-windup False: min speed 20.49 m/s, overshoot after crest 10.13 m/s, back within 0.3 m/s 85 s after crest, throttle at 100 % for 76 s
A 60 s climb at 9 % with the PI, with and without anti-windup
A 60 s climb at 9 % with the PI, with and without anti-windup (pre-rendered by the original script)
Python output
(appears after the first live run)
Show code
Loading the source...

The demo ends with the margins of the final loop $L = C G$. On the identified FOPDT model with its 2.41 s dead time the PI has $\omega_c = 0.228$ rad/s, $PM = 50.0°$, $GM = 2.81$ (9.0 dB) and a delay margin of 3.83 s. On the true car linearized at 27 m/s, with the 0.6 s engine lag and the 0.1 s delay, the same controller has $PM = 71.9°$ and $GM = 44.7$ (33.0 dB). These margins leave out the 0.1 s loop sample, which the fitted dead time already contains; with it the true car has $PM = 70.6°$ and $GM = 22.9$. Either way the identified dead time is much longer than the car’s lag and delay, so the design on the identified model is conservative. This figure does not depend on the grade and is shown as computed by the lab script.

Bode plot of the PI loop gain on the identified FOPDT model and on the true car linearized at 27 m/s

Loop gain of the cruise PI on the identified model and on the linearized true car.

Homework: cruise control of a mid-size SUV (100 points)

The homework tunes the cruise controller of a mid-size SUV, a heavier vehicle with more drag than the demo sedan, cruising at 25 m/s. It starts from two simulated logs, a flat-road throttle step from 26 % to 32 % and a run under P cruise control in which the road turns into an uphill grade of unknown size. The full problem statements are in homework.md, and the starter script hw_starter.py is in the lab folder of the lab materials on GitHub; the logs are in its data/ folder. Clone the repository, or download it as a zip file.

  1. Physics against data (15 points; L3, L6-L7)
  2. A hill as a disturbance (15 points; L2, L12)
  3. Root-locus design of the PI zero (25 points; L13-L17, L19)
  4. Lag compensator against PI (15 points; L18)
  5. A steep hill: saturation and windup (15 points; L19, L26)
  6. Engineering judgement (15 points)