electronics engineering
Course handbook · Edition with space for notes
Automotive
Driver assistance and the electronics of modern cars: a complete course on ACC (adaptive cruise control) from radar and camera to the wheel torque, with tested Python and C code, plus news on assisted driving in China.
- 7Topics
- 0Solved exercises
- 32Formula sheet
Free handbook generated from the lessons of the site and updated often, every time a lesson or an exercise changes: the latest version is always at www.electronics-engineering.com/handbook/automotive. Links work in the PDF too.
1Function, requirements and AUTOSAR architecture
ACC (Adaptive Cruise Control) keeps the speed chosen by the driver and, when a slower vehicle is ahead, follows it at a distance proportional to speed. It sounds simple, but behind it there is a complete chain: sensors, data fusion, choice of the target, planning of the manoeuvre and control of the torque at the wheels. This is the first of seven lessons that build a real ACC, from the radar to the brakes, with Python and C code that works and has been tested on test scenarios. Here we look at what the function must do, the requirements of the standards, the state machine and how the software is organised in AUTOSAR.
What an ACC does
The driver sets a speed
and a time gap
. The system works in two ways:
- speed control: free road, the car holds
like an ordinary cruise control; - following: a slower vehicle is ahead, the car follows it at the distance
, where
is the distance at standstill (about 4 m) and
our speed.
The time gap is the time we would need to reach the point where the vehicle ahead is now: with
s at 100 km/h (27.8 m/s) the desired distance is
m. The driver picks it with a button among four values: short 1.0 s, middle 1.4 s, long 1.8 s, extra long 2.2 s. Every start begins at “long”.
With stop & go (Full Speed Range ACC) the function works down to standstill: it stops behind the vehicle ahead, holds the car with the brakes, drives off by itself after a short stop and asks the driver to confirm after a long one.
ACC is an assistance system, not emergency braking: it decelerates by a few m/s² at most and the driver remains responsible. Sudden obstacles are the job of another function, AEB (automatic emergency braking), which shares requirements and sensors.
The requirements of the standards
The reference standards are ISO 15622 (ACC) and ISO 22179 (full speed range ACC, with stop & go). They set comfort and safety limits that the software must respect in every case:
| Quantity | at 20 m/s and above | at 5 m/s and below |
|---|---|---|
| maximum acceleration | 2.0 m/s² | 4.0 m/s² |
| maximum deceleration (average over 2 s) | 3.5 m/s² | 5.0 m/s² |
| maximum jerk when braking | 2.5 m/s³ | 5.0 m/s³ |
| minimum steady-state time gap | 0.8 s | 0.8 s |
Between 5 and 20 m/s the limits are interpolated linearly. The standard also requires at least one time gap setting between 1.5 and 2.2 s (our “long” and “extra long”), that the driver can always override (accelerator and brake pedal) and that the function signals when it cannot handle a situation.
The functional chain

,
; the Kalman filter (KF) fuses them into objects with state
and covariance
; the predicted path (PATH) comes from yaw rate
, speed and lane lines; target selection (TS) chooses the vehicle to follow; the planner (PLN) computes the acceleration request
; the torque controller (TQ) splits it between powertrain (PT) and brakes (ESC). The vehicle closes the loop back to the sensors.Each block has a lesson:
- this one: requirements, state machine, architecture;
- sensors and configurations (camera only, camera and radar, several cameras and several radars);
- fusion: tracking with the Kalman filter, association, track management;
- target selection: predicted path, probability of being in the lane, cut-ins and false positives;
- planning and longitudinal control: following, string stability, elastic approach, overtaking preboost, stop & go;
- from the acceleration request to the wheel torque: vehicle physics, three powertrain/brake zones, grade and mass estimation;
- integration: the complete system tested on scenarios with measurable criteria.
The function state machine
The state machine decides when ACC actually controls the vehicle. It is the most safety-related part: a mistake here means a car that brakes or accelerates when the driver does not expect it.

) or RES; OVERRIDE when the driver presses the accelerator beyond the threshold α; back to STANDBY with the brake, CANCEL or (without stop & go) below
; FAULT if a sensor or the ESC is no longer available for at least 0.2 s. In FAULT and on exit the request goes back to zero with a ramp, never with a step.| State | What happens | Output to the controller |
|---|---|---|
| OFF | function off | none |
| STANDBY | ready, not in control | ramp to 0 |
| ACTIVE | holds | planner |
| OVERRIDE | the driver accelerates | positive values only: ACC does not brake |
| STANDSTILL | stopped behind a vehicle (stop & go) | held by the brakes; automatic drive-off within 3 s |
| WAIT | stopped for more than 3 s | held; drives off with RES or a touch of the accelerator |
| FAULT | a needed condition is lost | ramp to 0 with jerk ≤ 2 m/s³, driver warning |
A few details make the difference between an exercise and a real function:
- set speed: SET takes the current speed rounded to the km/h (never below 30 km/h); in ACTIVE, SET and RES lower or raise it by 1 km/h;
- fault debounce: a sensor blind for a single cycle does not switch the function off, one blind for 0.2 s does;
- no steps on exit: when the function is disengaged while braking, the request goes back to zero with limited jerk, so that the driver has time to take over;
- long stop: after 180 s in WAIT the electric parking brake (EPB) replaces the service brakes and the function goes to STANDBY.
The Python code of the state machine is in acc_sim.py (class AccStateMachine), the C code in acc.c (function AccSm_Run); lesson 7 tests them one by one.
The AUTOSAR architecture
In cars the ECU software follows the AUTOSAR standard. In the Classic platform, used on microcontrollers with a real-time operating system, the application software is divided into software components (SWC) that communicate only through ports; the RTE (Run-Time Environment) connects the ports and triggers the functions of the components, called runnables, at fixed intervals or when data arrive. Below are the basic software modules (BSW) for bus communication, operating system, diagnostics and memory.

A runnable never calls another component directly: it reads and writes through the RTE. This is how the longitudinal control runnable (executed every 20 ms) looks in our C code:
/* SwcLongCtrl, runnable at 20 ms (TimingEvent) */
void SwcLongCtrl_Run20ms(void)
{
float a_req, v, a_imu, t_pt, t_br;
boolean hold;
Rte_Read_AccelRequest_Value(&a_req); /* from component SwcAccSm */
Rte_Read_StandstillHold_Value(&hold);
Rte_Read_VehicleSpeed_Value(&v); /* from the ESC, on CAN */
Rte_Read_LongAccelImu_Value(&a_imu);
LongCtrl_Run(&ctrl, a_req, v, a_imu, hold, &t_pt, &t_br);
Rte_Write_PowertrainTorqueReq_Value(t_pt); /* to the engine ECU */
Rte_Write_BrakeTorqueReq_Value(t_br); /* to the ESC */
}All the logic is in LongCtrl_Run, which knows nothing about buses or operating systems: it is tested on a PC exactly as it runs in the ECU. The same principle applies to all the code of these lessons.
On which ECUs

There is a reason for this split: torque control sits close to the actuators (ESC), where the fast wheel signals are and where ABS and ESP already run; the ACC function sits where the sensor data arrive. In vehicles with a powerful central computer (zonal architecture) fusion and planning often run on AUTOSAR Adaptive, on Linux or a similar system, and talk to the rest through services (ara::com); torque control stays on a microcontroller in Classic.
Signal protection and functional safety
A wrong acceleration request can make the car brake or accelerate for no reason: it is a hazard that ISO 26262 classifies, depending on the manufacturer’s analysis, typically up to ASIL B. Therefore:
- the request travels with E2E protection (CRC over the content, a counter that changes with every message): the receiver detects corrupted, repeated or lost messages;
- the receiver has a timeout: if the request does not arrive for more than a few cycles, the function goes to FAULT and the request returns to zero with a ramp;
- the ESC limits the request to the values of the standard anyway (deceleration and jerk), whatever arrives;
- errors go to the diagnostic event manager (Dem) and the function inhibition manager (FiM) disables ACC when a needed sensor is degraded (blinded camera, dirty radar).
The timing budget

The dominant delay is not the software but the actuator: the engine responds with a time constant of about 0.25 s plus a dead time, the brakes faster (about 0.12 s), but only after the pads have reached the disc. Every delay in the loop takes away phase margin (we saw it in the lesson on implementing digital controllers) and in lesson 5 we will see that it worsens the string stability of a line of vehicles: it is one of the reasons why the minimum time gap is 0.8 s and not less.
The code that comes with the lessons
All the lessons use the same code, which really works:
acc_sim.py: the whole chain in Python (numpy only): vehicle model with engine, brakes, wind, grade and payload; radar and camera; Kalman tracker; path prediction; target selection with state machine; planner; torque control; function state machine. Each block is a class with astep()method, like a runnable;make_plots.py: all the charts of these lessons, computed with the simulation;test_scenarios.py: 14 test scenarios with measurable criteria (lesson 7), all passed;acc.h,acc.c,test_acc.c: the same chain in C99 as AUTOSAR components, compiled without warnings and tested on 13 scenarios with the same results as the Python version.
Download the complete code (zip, 42 kB), with instructions to run it.
In the next lesson we start from the first block: what a camera and a radar see, how precisely, and why configurations with several sensors are not only about seeing further.
2Sensors and configurations
An ACC is as good as what it sees. Following a vehicle requires three numbers: the distance
, the relative speed
and the lateral position
, which says whether the vehicle is in our lane. Camera and radar measure these numbers in very different ways, with errors that grow with distance in different ways: this is why configurations with several sensors are not only about seeing further, but about covering the weak points of each one. In this lesson we derive the measurement errors from geometry and physics, and we will use them in the next one for fusion.
The configurations

| Configuration | Sensors | Strengths | Limits |
|---|---|---|---|
| 1V | one camera | cost, classifies objects, sees the lines | imprecise distance far away, blind with low sun, fog, darkness |
| 1R1V | front radar + camera | precise distance and speed, works in rain and darkness | radar angle less precise, ambiguous stationary objects |
| 1V3R, 1V5R | + corner radars | sees vehicles entering the lane (cut-ins) earlier, lane change | more data to fuse and calibrate |
| nV nR (+ lidar) | cameras around the car, several radars | 360° view, redundancy | computation, cost, complexity |
1R1V is the most common case in series production cars: radar and camera complement each other. “Vision only” solutions use several cameras and neural networks that estimate distance; they are feasible, but distance accuracy remains the weak point, as the numbers will show.
The camera: distance from the road plane
A camera sees an image, not a distance. The most common way to get it with a single camera is the point where the vehicle touches the road.

above the road, with focal length
(in pixels). The point where the wheels of the vehicle touch the road, at distance
, appears in the image
pixels below the horizon. The two similar triangles give
.Proof. The ray from the camera to the contact point drops by
over a distance
; on the image plane, at distance
from the optical centre, the same ray drops by
. The two triangles are similar, so
, that is
![]()
Now the error. If the contact point is estimated with an error of
pixels, the distance error is the derivative times the error (first-order propagation):
![Rendered by QuickLaTeX.com \[ \sigma_Z = \left|\frac{dZ}{d\Delta y}\right| \sigma_y = \frac{f H}{\Delta y^2}\,\sigma_y = \frac{Z^2}{f H}\,\sigma_y. \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-a6034578325c27f8e8d4977ff2d13d98_l3.png)
The error grows with the square of the distance. With
px,
m and one pixel of error: 1.6 m at 50 m, 6.4 m at 100 m, 14 m at 150 m. At 100 m the camera cannot tell whether the vehicle is at 94 or 106 m, let alone how fast it is approaching: differentiating such a noisy distance gives an unusable relative speed. Moreover, the formula only holds on a flat road: a slope or the pitch of the car under braking (one degree of pitch moves the horizon by 21 pixels) distort
.
There is a second way, the apparent width: a car of width
appears
pixels wide. But
is unknown (a small car is 1.6 m, a truck 2.5 m): a 10% error on
is a 10% error on the distance.
Time to collision without knowing the distance
The camera, however, has a weapon the radar does not have. Differentiating
with respect to time:
![]()
The ratio between the width in the image and its growth rate is the time to collision (TTC), and it depends neither on
nor on
. Camera-only emergency braking functions use exactly this: for safety what matters is how much time is left, not how many metres.
The lateral position, instead, the camera measures well: an object at column
from the image centre is at
, with an error of about
: 12 cm at 100 m. The camera also sees the lane lines, which we will need in lesson 4 to predict where our car will go.
The FMCW radar
The 77 GHz automotive radar transmits frequency ramps (chirps) and compares the echo with the transmitted signal. We saw how it works in detail in the lesson on the FMCW automotive radar; here we need three formulas and where they come from.

, so at every instant the two frequencies differ by the beat frequency
, with
the slope of the ramp. The motion of the target adds the Doppler shift
.- range:
, so
. The resolution (the smallest range difference between two separable targets) is
, with
the frequency sweep: with
GHz, 15 cm; - radial speed: the echo of a target moving at speed
is shifted by
; at 77 GHz
mm. The radar measures the relative speed directly, without differentiating the distance, with errors of a few cm/s; - angle: with several receiving antennas (and several transmitting ones, MIMO) the phase difference between two antennas at distance
is
. Typical accuracy is a few tenths of a degree.
The weak point is precisely the angle: an error
becomes a lateral error
![]()
which grows linearly with distance: with 0.3° (0.0052 rad), 0.26 m at 50 m, 0.52 m at 100 m, 0.79 m at 150 m. A lane is 3.5 m wide: at 150 m the radar struggles to tell which lane a vehicle is in.

The chart is the reason for the 1R1V configuration: the radar is precise where the camera is weak (distance, relative speed) and the camera is precise where the radar is weak (lateral position). Lesson 3 will show that the Kalman filter automatically takes the best of each.
The hard cases
| Situation | Camera | Radar |
|---|---|---|
| low sun, glare, darkness | degrades or blind | not affected |
| heavy rain, fog, snow | degrades a lot | degrades a little (spray, snow on the sensor) |
| stopped vehicle in the lane | recognises it as a vehicle | echo identical to manhole covers, signs, bridges: all stationary |
| tunnel, guard rail | lines often visible | multiple reflections, ghost targets |
| very close vehicle cutting in | often outside the field of view | narrow beam: sees it late, corner radars needed |
| unusual vehicles (trailers, oversized loads) | classification can be wrong | sees them, shape uncertain |
The most important case for ACC is the stopped vehicle. For the radar every stationary object approaches at the speed
of our car: a car stopped in a queue, a manhole cover, the structure of a bridge and a sign all have the same relative speed. Without other information, braking for every stationary echo means braking for nothing (false positive), ignoring them all means not stopping behind a queue. The solutions we will see in lesson 4 are camera confirmation and the memory of objects seen moving. Newer radars (called 4D or imaging) also measure elevation and tell a bridge from a car better, but the problem remains.
What the sensor must give to fusion
Every sensor sends to the ADAS ECU, every cycle, a list of objects with measurements and uncertainties. In the code:
def radar_measure(prm, rng, x, y, vx):
"""Polar measurement of a target at (x, y): (range, azimuth, range rate) or None."""
r, th = sqrt(x * x + y * y), atan2(y, x)
if r > prm.r_max or abs(th) > prm.fov or rng.random() > prm.p_det:
return None # out of the beam or missed detection
rr = vx * cos(th)
return (r + rng.normal(0, prm.sigma_r), th + rng.normal(0, prm.sigma_th), rr + rng.normal(0, prm.sigma_rr))
def camera_sigmas(prm, x):
"""sigma_x = x^2 / (f h) sigma_px (ground plane), sigma_y ~ x / f sigma_px"""
return x * x / (prm.f * prm.h) * prm.sigma_px, max(0.05, x / prm.f * prm.sigma_px * 1.5)Uncertainties are not a detail: the Kalman filter weights every measurement with the inverse of its variance, and a sensor that declares too small an error takes over even when it is wrong. In the next lesson we build the tracker that merges the two lists into a single list of reliable objects.
3Radar and camera fusion
Radar and camera send, each at its own rate, lists of measurements that are noisy, sometimes missing, sometimes false. Fusion turns them into a list of tracked objects: for each one an estimate of position and speed with its uncertainty, updated every cycle. The tool is the Kalman filter, which we introduced in the lesson on the Kalman filter and met again among the discrete observers; here we apply it to several sensors, add the association of measurements to objects and track management, and look at a tuning mistake that makes fusion worse than a single sensor.
Two architectures

- centralised (A): the most precise, because the filter uses every measurement with its true uncertainty; it needs raw or nearly raw, time-stamped measurements;
- track-to-track (B): each sensor ECU already does its own tracking (common with sensors from different suppliers) and the ADAS ECU fuses the tracks. Two tracks of the same object have correlated errors (they share the same motion model), and treating them as independent would make the estimate overconfident. Covariance intersection is safe even without knowing the correlation:
,
, with
chosen to minimise the trace of
.
In the code we use centralised fusion.
The model of relative motion
The state of each object is relative to our car:
. Longitudinally the relative acceleration is
: the target’s
is unknown and we treat it as noise, our own
is known and we use it as an input. Integrating over a step
with constant acceleration (see the kinematics of linear motion):
![]()
and the same laterally, without input. In matrix form
with
![Rendered by QuickLaTeX.com \[ F = \begin{bmatrix}1&T&0&0\\0&1&0&0\\0&0&1&T\\0&0&0&1\end{bmatrix},\quad G = \begin{bmatrix}T^2/2&0\\T&0\\0&T^2/2\\0&T\end{bmatrix},\quad Q = G\,\mathrm{diag}(q_x^2, q_y^2)\,G^T. \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-5c72a73869966fe43ef086161194e36b_l3.png)
and
are the standard deviations of the accelerations the model does not know: how hard the target can brake or accelerate, how quickly it can move sideways. Their value matters a lot, as we will see.
The Kalman filter

and the model
(with the input
) and becomes the prediction
; the measurement
minus the predicted measurement
is the innovation
, which multiplied by the gain
corrects the prediction.For every measurement the filter takes two steps:
- prediction up to the time of the measurement:
,
; - update: innovation
, its covariance
, gain
, then
,
.
Why that gain. After the correction the error is
, with
the prediction error and
the measurement noise, independent. Its covariance is
![]()
(this is the Joseph form, which we also use in the code because it stays symmetric and positive with floating point numbers). We look for the
that minimises the sum of the variances, the trace of
. Expanding and differentiating with respect to
, with
for symmetric
:
![]()
Why two sensors are better than one
The simplest case says it all. Two independent estimates of the same quantity,
with variance
and
with
: their weighted mean
has variance
, minimum for
. Substituting:
![]()
Information (the inverse of the variance) adds up: the fused estimate is always better than the better of the two. And this is exactly what the Kalman filter does, component by component: for the distance it weights mostly the radar, for the lateral position mostly the camera (the formulas of the Gaussian give the same result with Bayes’ theorem).
The measurements of the two sensors
The camera gives
with covariance
derived in lesson 2:
takes the first and third components of the state. The radar measures in polar coordinates
; to use a linear filter the measurement is converted to Cartesian coordinates,
,
, and the covariance is propagated with the Jacobian matrix:
![]()
For a target ahead (
) the error ellipse is narrow in
(
) and wide in
(
). The radial speed
is the third measurement. The sensors are not synchronised (radar at 20 Hz, camera at 15 Hz): the filter predicts each object up to the time of the measurement and uses it right away, in time order.
Associating measurements to objects
Before updating we have to know which measurement belongs to which object.

- validation gate (gating): the Mahalanobis distance
of a correct measurement follows a
distribution with as many degrees of freedom as the components of the measurement. We accept the measurement if
, with
(2 degrees, camera) or 11.34 (3 degrees, radar) for 99%. Unlike the Euclidean distance, the gate widens where the track is uncertain; - global association (Global Nearest Neighbour): among all possible assignments (each track at most one measurement, each measurement at most one track) we pick the one with the most pairs and the smallest sum of distances. With few objects all can be tried; with many the Hungarian algorithm does it in
. In dense traffic or with many false echoes probabilistic methods are used (JPDA, MHT), seen in the lesson on radar tracking.
Managing the tracks
A measurement that is not associated starts a tentative track; it becomes confirmed when it has been associated in at least 3 of the last 5 cycles (M-of-N logic), and it is deleted after 6 cycles without measurements. Only confirmed tracks go to target selection: an isolated echo (a reflection, an insect on the radome) never reaches the planner.
def update(self, z, R, H):
y = z - H @ self.s # innovation
S = H @ self.P @ H.T + R # innovation covariance
K = self.P @ H.T @ np.linalg.inv(S) # Kalman gain
self.s = self.s + K @ y
I_KH = np.eye(4) - K @ H
self.P = I_KH @ self.P @ I_KH.T + K @ R @ K.T # Joseph form
return y, SA mistake that makes fusion worse than one sensor
In the simulation a car ahead, from 30 to 110 m, changes lane at some point. With the first tuning,
m/s², the result was paradoxical: root mean square lateral error 0.32 m fusing radar and camera, 0.11 m with the camera alone. Fusion was worse than the better sensor.
The cause: with many measurements and a small
the filter became overconfident,
cm. During the lane change (a true lateral acceleration of about 1 m/s²) the camera measurements, which were correct, fell outside the validation gate of such a self-assured filter and were discarded: 36 out of 222. Only the radar was left, imprecise sideways, and the track followed the manoeuvre late.

m/s²: top, distance error (radar and fusion 0.03 m, camera 1.1 m); bottom, the estimated lateral position during the lane change between 6 and 10 s. Fusion (green) follows the manoeuvre better than either sensor: error 0.08 m against 0.19 m for the radar and 0.11 m for the camera.With
m/s², a value that covers a real manoeuvre, fusion does its job again: 0.03 m in distance (like the radar) and 0.08 m sideways (better than the camera). The general lesson: process noise is not a smoothing parameter, it is a statement about how much objects can move; if it is too small the filter throws reality away. Series systems often use several models together (IMM, Interacting Multiple Models): a constant velocity one for quiet stretches and a manoeuvre one, weighted according to which explains the measurements better.
The tracker now gives a list of objects with state and covariance. Which one should we follow? That is the problem of the next lesson, and it is where an ACC earns the driver’s trust or loses it.
4Target selection and path prediction
Fusion gives a list of objects: cars in our lane, cars in the neighbouring lanes, guard rails, signs, sometimes a ghost echo. Target selection chooses which one to follow. There are two possible mistakes and they weigh differently: a false positive (braking for a car that is in the next lane) is annoying and dangerous, because whoever follows does not expect it; a false negative (not seeing in time a car that enters our lane) forces hard braking at the last moment. The heart of the problem is predicting where our own car will go, even when the lines on the road are poorly visible.
Where we will go: the predicted path
From the yaw rate
A car driving through a curve of radius
at speed
rotates with angular velocity
, so the curvature is
![]()
The gyroscope measures
always, in any weather. If the curvature stays as it is now, the path is a circle: the point at distance
ahead is at lateral position
. For
, with the expansion
:
![]()
But the curvature changes. Roads are built with transition curves whose curvature varies linearly with distance (clothoids),
. The heading angle is
and, integrating again, the lateral displacement is
![]()
The gyroscope sees
but not
: at the entry of a curve our car still drives straight while the road already turns, and the error grows with
. In the model we treat
as uncertain (standard deviation
m⁻², typical of motorway transition curves) and the gyroscope noise as uncertainty on
: the uncertainty of the path grows quickly with distance.
From the lane lines
The camera gives the centre of the lane as a polynomial
, with a quality
(contrast, both lines visible, line type) and a view range (how far the lines are seen). The lines “see” the curve before we enter it, but they can be missing: road works, snow, worn lines, junctions. Their error grows with distance and becomes huge beyond the view range.
Fusing the two paths
Each point
has two estimates with their standard deviations,
and
. They are combined like two independent measurements (the same proof as in lesson 3): weights inversely proportional to the variances,
. With good lines the camera wins; with poor lines the yaw rate remains, with an uncertainty that honestly says how little we know.

, view range 110 m): the fused path (blue, with the band
) follows the curve, at 110 m 0.73 ± 0.33 m against a true 0.74. Right, poor lines (
, 30 m): the path stays straight but the band widens, ±2.7 m at 110 m. The red square is a car in the right lane.The probability of being on our path

around the predicted path
and an object with lateral offset
. The light blue band represents the uncertainty
, which grows with distance.For an object at distance
and lateral position
, the offset from the path is
. The true offset is uncertain: adding the uncertainty of the object (from the tracker covariance) and that of the path,
. The object is on our path if the true offset lies within the corridor
; with a Gaussian offset of mean
, the probability is the integral of the Gaussian between
and
:
![]()
with
the cumulative distribution function of the standard normal. The half width
m is that of our car plus a margin, not that of the lane: what matters is whether the other vehicle occupies the space we will sweep, not where the lines are.

as a function of the offset
for different total uncertainties. With
m the curve is almost a rectangle: in or out. With
m it does not exceed 0.4 even at the centre: a distant object with an uncertain path cannot become the target. The horizontal lines are the entry (0.6) and exit (0.35) thresholds.This is already a defence against false positives: where we do not know where we will go, no object exceeds the threshold.
False positives and how to avoid them
The classic case: we approach a left curve; a car in the right lane, 95 m ahead, is already in the curve. Relative to our current, straight direction, its displacement brings it right in front of us: a selector that uses only the yaw rate with a fixed uncertainty takes it as the target and brakes.

. With the naive selector (path from the yaw rate only, fixed uncertainty, grey) the probability reaches 0.84 and the car is taken as the target for 2.2 s (shaded area): braking for nothing. With poor lines but honest uncertainty (orange) it reaches 0.44: never a target. With good lines (green) it stays at 0.The defences, all in the code:
- path with honest uncertainty: the uncertainty grows with
and
; with poor lines a distant object does not reach the threshold; - no new targets where the path is too uncertain: if
m at the object’s distance, the object cannot become a candidate (a target already locked is kept, with hysteresis); - confirmation time that grows with uncertainty: a candidate must stay above the threshold for
seconds; - hysteresis: entry with
, exit with
: no target that appears and disappears; - stationary objects: for the radar they are all the same (lesson 2). A stationary object is admitted only if it has been seen moving (a car that stopped in a queue) or if the camera has confirmed it within the last 0.5 s and it is within 80 m;
- confirmed tracks only: isolated echoes never get here (M-of-N logic of lesson 3).
The selection state machine

; it must stay there for
. LOCKED: it is the target the planner follows; if a closer object becomes a confirmed candidate it replaces it (cut-in); if
falls below
it is released (cut-out). HOLD: the target track was lost for a moment; its prediction is kept for
, then NONE.| From | To | Condition |
|---|---|---|
| NONE | CANDIDATE | closest admitted object with |
| CANDIDATE | NONE | the candidate drops below 0.6 or disappears |
| CANDIDATE | LOCKED | it stays above the threshold for |
| LOCKED | LOCKED (new) | a closer object is a candidate for |
| LOCKED | NONE | |
| LOCKED | HOLD | the target track is missing (lost measurements, occlusion) |
| HOLD | LOCKED | the track comes back |
| HOLD | NONE | 0.6 s have passed |
The HOLD state looks like a detail, but without it every time the radar loses the target for a few cycles (it happens, for example, under a bridge) the ACC would accelerate towards the set speed and then brake again. In lesson 7 a 0.4 s loss of radar measurements passes without a single cycle without a target.
The cut-in: predicting who comes in

. The time to line crossing, TLC, is the offset still to cover divided by the lateral speed.Waiting until the car is already in the corridor means reacting late. If an object outside the corridor is moving towards it, we also compute where it will be in
s,
, with an uncertainty increased by the variance of the lateral speed (
), and we use the higher of the current and the predicted probability (the latter multiplied by 0.9: a prediction is worth a little less than a measurement).

, acceleration of our car, selection state. With prediction (violet) the target is locked at 3.92 s, when the car is still 1.57 m from the centre; without (grey) at 4.78 s. Result: peak braking 3.0 m/s² instead of 3.7, minimum distance 34.0 m instead of 31.5.The code
Here is the evaluation of an object in the C version (the Python one is identical):
static bool ts_assess(TgtSel *s, const AccObject *o, const AccPath *path, float v_ego, float t, float *prob, float *sp)
{
float yp, sig, delta, v_abs;
bool stationary, ok;
*prob = 0.0f; *sp = 0.0f;
if (o->x <= 0.5f) return false;
PathPred_At(path, o->x, &yp, sp); /* fused path and its sigma at the object */
delta = o->y - yp;
sig = sqrtf(o->var_y + *sp * *sp);
*prob = InPathProbability(delta, sig, TS_HALF);
if (fabsf(o->vy) > 0.2f && sgnf(o->vy) == -sgnf(delta) && fabsf(delta) > TS_HALF) {
float d_pred = delta + o->vy * TS_T_PRED; /* cut-in: where it will be */
float s_pred = sqrtf(sig * sig + TS_T_PRED * TS_T_PRED * o->var_vy);
*prob = maxf(*prob, 0.9f * InPathProbability(d_pred, s_pred, TS_HALF));
}
v_abs = v_ego + o->vx;
stationary = fabsf(v_abs) < 1.0f && !was_moving(s, o->id, fabsf(v_abs) > 3.0f);
ok = o->confirmed;
if (stationary) /* stationary: camera confirmation and close range */
ok = ok && (t - o->t_cam < 0.5f) && o->x < TS_X_STAT;
return ok;
}Now we know which vehicle to follow, its distance
, its speed
and its acceleration
. In the next lesson we decide how to follow it: how much to accelerate or brake, cycle after cycle.
5Planning, following and stop & go
We have the target: its distance
, its speed
, its acceleration
. Every 20 ms the planner decides which acceleration to request from the car. A single controller is not enough: following in steady state, approaching a much slower vehicle, preparing an overtake and stopping in a queue are different problems with different solutions. The structure we use is that of many series systems, rule-based: each mode proposes an acceleration, the most cautious one wins, then limits and jerk.

to torque control.The constant time gap policy
The desired distance is
: it grows with our speed. The errors the planner uses are
![]()
Why this and not a fixed distance? With a fixed distance a string of cars with ACC amplifies disturbances along the string unless the vehicles communicate; with a time gap this can be avoided, as we prove shortly. The driver chooses
among four values.

(violet) changes by 0.25 s per second and the distance follows it without jerks.The change of
is deliberately slow: a jump from 2.2 to 1.0 s would mean a distance error of 33 m in an instant, and the controller would accelerate all at once.
Steady-state following
The basic mode is a proportional-derivative controller on the distance error, with the target acceleration fed forward:
![]()
Stability. Let us assume for now that the car achieves the requested acceleration immediately (
) and that the target drives at constant speed. Then
and
, that is
![]()
The trace is
, the determinant
: the characteristic polynomial is
![]()
stable for every
,
(the Routh criterion for second order). With
s: natural frequency
rad/s and damping
, that is no overshoot (the second-order response). A slow, calm following is what is wanted: nobody wants a car that reacts to every small change of the vehicle ahead.

String stability
A single stable car is not enough. In a string of cars with ACC each one follows the previous one: if each amplifies the speed variations a little, the last one suffers a huge disturbance (it is the wave that appears out of nowhere in traffic jams). With Laplace transforms (see transfer functions), for car
following car
:
![]()
The string does not amplify disturbances if
at every frequency. With
:
![]()
The worst case is
; dividing by
gives the condition
![]()
With
,
: for
it is 2.14 and fine; for
it is 1.35 and the string amplifies. This is why the gains cannot be fixed: in the code
grows when the time gap gets shorter,
, that is 0.98 for
s.

in decibels for different time gaps with fixed gains (solid lines): for 0.8 and 1.0 s it exceeds 0 dB, the string amplifies. The dashed lines are the same time gaps with
adapted: they stay below 0 dB.
s and fixed gains (left) the wave grows: the first drops to 75.6 km/h, the last to 68.9. With
s (right) it is damped: the last drops only to 79.7 km/h. The actuators have a delay of 0.2 s, which worsens the condition: it is one of the reasons for the 0.8 s minimum of the standard.Approaching a slower vehicle
We arrive at 130 km/h and ahead, at 200 m, there is a car at 80 km/h. The following controller, left alone, waits until the distance error becomes small and then brakes hard: with
m/s the term
is
m/s², limited to
. An experienced driver does something else: stops accelerating, then brakes gently and steadily.
The kinematic deceleration. In relative motion, with the target at constant speed, a constant deceleration
cancels the speed difference
after a relative distance
given by
. If we want
to vanish exactly when the distance reaches
, we need
![Rendered by QuickLaTeX.com \[ a_{kin} = -\frac{\Delta v^2}{2\,(d - d_{end})} + a_t. \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-f8e3c036bde461d893870adbc9a7a7ae_l3.png)
Recomputed every cycle, this law corrects its own errors: if the car brakes less than planned, the remaining distance shrinks and the request grows.
Elasticity. It is not necessary to arrive exactly at
with
. If we accept going temporarily below the desired distance by a margin
and recovering it calmly afterwards, the distance available for braking grows and the braking gets softer: with
,
![Rendered by QuickLaTeX.com \[ |a_{kin}| = \frac{\Delta v^2}{2\,(d - d_{des} + \delta)} < \frac{\Delta v^2}{2\,(d - d_{des})}. \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-62dad1f06c132718d86d27e3a7a20a88_l3.png)
In the code
: a quarter of the desired distance, never more than 12 m.

, which ends at
instead of
(dashed); (3) a short elastic undershoot; (4) gentle recovery to
.Three details make the manoeuvre robust:
- mode with hysteresis: the approach starts with a real closing speed (above 1 m/s) and ends when it is almost zero or the elastic margin is used up; without hysteresis, with
close to zero the mode switches on and off; - mild phase: as long as
is weaker than what releasing the pedal gives (
m/s²), the following controller does the job, but without braking more than necessary (
) and without closing faster than
; - elastic recovery: after the approach the missing distance is recovered with a reduced gain (
) and a deceleration of at most
m/s²: the distance opens up because we slow down slightly, not because we brake.

Overtaking preboost
We follow a truck at 80 km/h with the set speed at 130. The driver signals left to overtake. A simple ACC keeps the 37 m of distance until the truck has left the corridor, and only then accelerates: the overtake starts slowly, and whoever comes from behind in the overtaking lane has to brake.
Preboost anticipates the overtake: with the indicator towards the overtaking lane, a target slower than the set speed and the next lane free (corner radars and fusion say so), the planner
- reduces the time gap towards
s, always with the slow change of 0.25 s per second; - adds an acceleration
m/s² to the following term; - stops after 4 s if the lane change does not happen, or as soon as the indicator is switched off, and the distance goes back gently to its normal value.

and the car starts accelerating before the truck has left the corridor; after the lane change the target is free and the acceleration rises towards
.
Stop & go
In a queue the target brakes until it stops. The following controller, with the target acceleration fed forward, would copy its braking and stop us where we are, perhaps at 15 m. What we need is to stop
from the point where the other one will stop.
The stopping law. If the target brakes with
, it will stop after the distance
, that is at the distance
from us. To stop
behind that point with constant deceleration:
![Rendered by QuickLaTeX.com \[ a_{stop} = -\frac{v^2}{2\,(x_{stop} - d_0)}. \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-1edee3f4567249eb16a86160054453bd_l3.png)
If the target is already stopped,
. The law replaces following and approach when the target will stop within 4 s and we are below 54 km/h. At low speed the wider limits of ISO 22179 apply, interpolated as seen in lesson 1: down to −5 m/s² and up to +4 m/s² below 18 km/h. When we are stopped less than
m from the stopped target, the planner requests the stop and the state machine goes to STANDSTILL: the brakes hold the car (lesson 6).

Arbitration, limits and jerk
The proposals of the modes (set speed
, following, approach, stop) go into the minimum block: the most cautious wins. Then:
- saturation to the limits of the standard, which depend on speed (from
/
m/s² above 72 km/h to
/
below 18 km/h); - jerk limit: the request changes by at most 2.5 m/s³ (comfort); in firm braking (below
m/s²) up to 5 m/s³ at low speed.
self.mode = min(cands, key=cands.get) # the most cautious proposal wins
a_lo, a_hi, j_lo = iso_limits(v, p) # ISO 15622 / 22179, speed dependent
a_goal = float(np.clip(cands[self.mode], a_lo, a_hi))
if self.stop_request:
a_goal, self.mode = min(a_goal, -0.5), "stop"
jerk = j_lo if a_goal < -2.0 else p.jerk_max
self.a_out += float(np.clip(a_goal - self.a_out, -jerk * dt, p.jerk_max * dt))The alternative: model predictive control
A different approach is model predictive control (MPC), which we saw in the lesson on optimal and predictive control. With the state
and the model of relative motion, every cycle a quadratic problem is solved over a horizon of a few seconds: minimise a weighted sum of distance error, speed difference, acceleration and jerk, with explicit constraints (limits of the standard, minimum distance, set speed). Gentle approach, elasticity and early braking come out of the cost and the constraints by themselves.
| Rule-based (this lesson) | Predictive (MPC) | |
|---|---|---|
| behaviour | designed mode by mode | comes from cost and constraints |
| constraints | with saturations and special cases | explicit, met by construction |
| computation | microseconds | a quadratic problem every 20 ms |
| calibration and certification | every parameter has a physical meaning | less intuitive weights, solver to qualify |
Many series systems stay rule-based precisely because of the last row; MPC is used more and more where the ECU has computing power and long predictions are needed (curves, speed limits, lane changes).
The request
is ready. But the car has no acceleration command: it has an engine and brakes. In the next lesson we turn it into wheel torque, with all the physics of the vehicle.
6Torque control: powertrain and brakes
The planner requests an acceleration,
. The car, however, has no acceleration command: it has an engine (or an electric motor) that gives positive torque and a small braking torque when the pedal is released, and brakes that give only braking torque. Longitudinal control turns
into two wheel torque requests,
to the powertrain and
to the ESC, taking into account grade, wind, payload and actuator delays. It is the point where vehicle physics really enters the software, and it is the part where you can feel an ACC: an abrupt change between engine and brakes, braking that comes late, a car that rolls back uphill.
The forces on the vehicle

with wind
. Along the road act the driving force at the wheels
, the aerodynamic drag
, the rolling resistance
and the weight component
; the normal reactions
,
balance
.Newton’s second law along the road (see Newton’s laws and the inclined plane) gives
![]()
with
: the total torque at the wheels divided by the wheel radius;
: what counts is the speed relative to the air;
is tailwind,
headwind;
: rolling, with
;
: the grade. A 5% climb means
.
For our car (1600 kg,
m²) at 100 km/h:
N,
N, and a 5% climb adds 783 N, more than the other two together. A 12 m/s headwind takes the aerodynamic force from 324 to 665 N. A 350 kg payload adds 22% to everything that depends on mass. None of these quantities is known precisely by the software: we will handle them with estimates and feedback.
The equivalent mass

, gearbox with ratio
and efficiency
, final drive
, wheels of inertia
and radius
.Accelerating the car means also accelerating everything that rotates. The equivalent mass comes from the kinetic energy: with the angular speed of the wheels
and of the engine
,
![]()
In a high gear
exceeds
by a few percent (4% in our model), in first gear by as much as 30% (rotational dynamics explains why: the engine spins much faster than the wheels and the term grows with the square of the ratio).
The feedforward part: the inverse model
If we knew everything, the required torque would come from inverting the equation of motion:
![]()
This is the feedforward part: on its own it does almost all the work, with the estimates
and
we will see shortly. What it does not know (the wind, model errors, the varying effectiveness of the brakes) is corrected by proportional-integral feedback on the acceleration error, with the acceleration derived from the wheel speeds:
![]()
The integral action needs a good anti-windup (see the PID controller): here there is no integration when the actuator of the active zone is at its limit, when a zone change is pending or has just happened, and in the intermediate zone. Without the second rule, during the waiting time before switching to the brakes the integral wound up and then made the car brake at −3.9 m/s² instead of the requested −3.0: we found it in the simulation and fixed it.
The three zones
The most delicate point is the split between engine and brakes. The natural boundary is the coast acceleration
: the one the car has with the pedal released and no brakes,
![]()
where
(−180 Nm at the wheels in our model) is the engine drag. Above
the engine is enough; below it the brakes are needed.

, B (brakes, red) below, C (coast, orange) in the band around
. The
curve depends a lot on the grade: at 100 km/h −0.64 m/s² on the flat, −1.11 on a 5% climb, −0.16 on a 5% descent. The green curve at the top is the power limit.The hard case is precisely the intermediate band, because four problems add up there:
- small braking torques are imprecise: the first tens of Nm of pressure only overcome the piston return springs (in the model 25 Nm do not brake), pads away from the disc need 0.1 s to touch it, and light braking is noisy and wears the pads;
- the two actuators have different timing: the engine responds with a dead time and a time constant of 0.25 s, the brakes in 0.12 s;
- the request is noisy: it oscillates by a few hundredths of m/s² with the sensor measurements; with a sharp boundary it goes back and forth between engine and brakes;
- the boundary moves: it depends on the estimated speed, grade and mass.
The solutions, in the code:
- an acceptance band: in zone C the engine is released and the brakes do not work; the residual error (at most the width of the band, 0.08 m/s²) is accepted and the integral stops, so it does not wind up;
- minimum time in a zone (0.3 s) before changing it, except for real braking (more than 0.5 m/s² below
), which enters at once; - minimum braking torque of 40 Nm when the brakes are active: either we brake effectively or we do not brake;
- step-free handover: entering the brakes, the engine does not go to zero all at once; the brakes give exactly the difference between the estimated engine torque (a model of its delay) and the total one, so the sum stays constant while the engine winds down;
- prefill: if in zone C the request falls quickly towards the brakes, 15 Nm bring the pads to the disc without braking.

, the minimum time
, the immediate entry into the brakes for an urgent request. Each zone shows how the torques are split.
With an electric car zone C widens a lot: regenerative braking of the motor reaches −1.5 m/s² and beyond, and the split becomes one between regeneration (which recovers energy) and disc brakes (for hard braking or a full battery). The structure is the same, with the motor also working with negative torques.
Estimating grade and mass
The inverse model needs
and
. They come from signals every car already has.
Grade. The longitudinal accelerometer (in the inertial unit of the ESC) does not measure the acceleration of the car but the specific force: uphill, gravity “pulls” it backwards like a forward acceleration, and it measures
. The wheels instead measure only
(differentiating the speed). Therefore
![]()
filtered with a 1 s time constant. A 0.03 m/s² error of the accelerometer (its offset) becomes a grade error of 0.3%: small, and feedback corrects it. With the vehicle stopped the formula gives the exact grade: it is needed to hold the car uphill.
Mass. While driving, without brakes, the equation of motion says
![Rendered by QuickLaTeX.com \[ \underbrace{\hat T_{pt}/r - F_a - m_{nom} k_{rot}\,\hat a}_{y} = m\,\underbrace{(a_{imu} + g\,c_r)}_{\varphi}, \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-7872eeb292e2aa0ca455a21745bdc2e5_l3.png)
linear in the mass: it is a regression, and it is solved with least squares in recursive form (RLS), updating the estimate at every sample:
![]()
The forgetting factor
gives a memory of about 10 s. The estimate is updated only when the equation is reliable: no brakes (their torque is poorly known), speed above 18 km/h, acceleration of at least 0.3 m/s² (otherwise
is small and the estimate picks up the noise).

The controller at work

and the estimated acceleration, sum into
, split into the zones based on
, engine model giving the estimated torque
for the handover to the brakes; the estimator (EST) derives
,
,
from speed and accelerometer.The toughest test bench: 90 km/h, and everything the controller does not know. A 350 kg payload, a 6% climb from 4 to 20 s, a 12 m/s headwind from 14 s, brakes 20% less effective (cold or worn pads), accelerometer offset; at the end a requested braking of 2 m/s².


Standing still, uphill
When the state machine is in STANDSTILL or WAIT (stop & go, lesson 5) the controller receives the hold command:
- hold: brakes at
Nm, at least 800 Nm, and the integral reset. With the vehicle stopped the estimated grade is exact; - drive-off without rolling back: below 0.5 m/s uphill the brakes hold the part of the weight that the engine does not give yet,
, and they open as the engine torque grows. In the stop & go of lesson 5, on a 4% climb, the car does not roll back by a millimetre.
/* 2. zone around the coast acceleration, band + dwell time; urgent braking enters at once */
a_c = CoastAcceleration(p, v, c->sin_th, m);
want = a_req > a_c + c->b_hi ? Z_DRIVE : (a_req < a_c - c->b_lo ? Z_BRAKE : Z_COAST);
c->t_zone += ACC_DT;
urgent = want == Z_BRAKE && a_req < a_c - 0.5f;
if (want != c->zone && (c->t_zone >= c->t_dwell || urgent)) { c->zone = want; c->t_zone = 0.0f; }
sat = t_tot > t_hi || t_tot < t_lo || (c->zone == Z_DRIVE && t_tot < p->t_coast && e < 0.0f);
settling = want != c->zone || c->t_zone < c->t_dwell;
if (c->zone != Z_COAST && !sat && !settling) c->i_term += c->ki * e * ACC_DT; /* anti-windup */
t_tot = clampf(t_tot, t_lo, t_hi);
/* 3. split: the brakes complement the ESTIMATED powertrain torque */
*t_pt = c->zone == Z_DRIVE ? t_tot : p->t_coast;
*t_br = c->zone == Z_BRAKE ? maxf(c->t_brake_min, c->t_pt_est - t_tot) : 0.0f;We have all the pieces. In the last lesson we put them together and test them on a catalogue of scenarios with measurable criteria, in Python and in C.
7Integration and test scenarios
In the previous lessons we built every block of the ACC, from the radar measurement to the torque on the brakes. A block that works on its own, however, does not prove anything yet: real errors come from the interactions, when an overconfident tracker discards the camera, when an integral winds up during a zone change, when the state machine takes a slowdown for a stop. We found all of these precisely by putting the pieces together and testing them. In this lesson we look at the complete system, how it is tested, and the results: 14 scenarios in Python and 13 in C, all passed with measurable criteria.
The complete system

| Block | Lesson | Python (acc_sim.py) | C (acc.c) | Period |
|---|---|---|---|---|
| radar, camera | 2 | radar_measure, camera_measure | (in the sensor ECUs) | 50 / 66 ms |
| fusion | 3 | Tracker, Track | (Kalman: as in Python) | per measurement |
| path prediction | 4 | PathPredictor | PathPred_Run, PathPred_At | 20 ms |
| target selection | 4 | TargetSelector | TgtSel_Run | 20 ms |
| planner | 5 | Planner | Planner_Run | 20 ms |
| state machine | 1, 5 | AccStateMachine | AccSm_Run | 20 ms |
| torque control | 6 | TorqueController, Estimator | LongCtrl_Run | 20 ms (10 ms in the ESC) |
| vehicle (plant) | 6 | Vehicle | car_step in the test bench | 10 ms |
The main loop of the simulation has the same shape as an execution in the ECU: each block runs at its own rate and passes only its outputs to the next one.
for k in range(int(T / veh.dt)): # vehicle and sensors at 10 ms
t = k * veh.dt
tk.predict_to(t, veh.a)
if k % 5 == 0: # radar, 20 Hz
zs = [A.radar_to_cartesian(rp, m) for (x, y, v) in objs if (m := A.radar_measure(rp, rng, x - veh.x, y, v - veh.v))]
if zs:
tk.update(zs, A.H_RADAR, A.GATE_3D)
if k % 7 == 3: # camera, about 15 Hz
zs = [m for (x, y, v) in objs if (m := A.camera_measure(cp, rng, x - veh.x, y))]
if zs:
tk.update(zs, A.H_CAMERA, A.GATE_2D, init=False)
if k % 2 == 0: # ADAS runnables, 20 ms
tgt = ts.step(tk.tracks, pp.predict(veh.v, yaw_rate, lane), veh.v, 0.02, t)
a_pl = pl.step(veh.v, (tgt.s[0], veh.v + tgt.s[1], 0.0) if tgt is not None else None)
a_req = sm.step(driver, veh.v, a_pl, sensors_ok, t, pl.stop_request)
t_pt, t_br, _ = tq.step(a_req, veh.v, veh.a_imu, hold=sm.hold)
veh.step(t_pt, t_br, grade, wind)How such a function is tested
An assistance function is tested at several levels, and the code of these lessons is ready for the first two:
- SIL (software in the loop): the real code, as it runs in the ECU, with a model of the vehicle and the sensors on a PC. This is what
test_scenarios.py(Python) andtest_acc.c(C) do; - HIL (hardware in the loop): the real ECU connected to a real-time simulator that generates the sensor and bus signals;
- track tests with moving targets (also the test procedures of ISO 15622 and Euro NCAP);
- road tests with thousands of recorded kilometres, replayed in simulation (re-simulation) with every new software version.
The rule that makes all of this useful: every scenario has a measurable criterion, decided before looking at the result. “The approach looks good” is not a test; “maximum deceleration below 2 m/s² and distance error below 5% after 60 s” is.
The scenario catalogue
| Scenario | Criterion | Result | Outcome |
|---|---|---|---|
| free cruise, from 100 to 120 km/h | speed error in the last 5 s < 1 km/h | 0.02 km/h | passed |
| approach from 130 to 80 km/h, 200 m | maximum deceleration < 2 m/s² | 0.75 m/s² | passed |
| approach from 130 to 80 km/h, 200 m | distance error after 60 s < 5% | 0.40% | passed |
| the target brakes at −4 m/s² to a stop | minimum distance > 2 m | 3.90 m | passed |
| cut-in at 50 m, 12 km/h slower (complete chain) | minimum distance > 15 m | 33.5 m | passed |
| cut-in at 50 m (complete chain) | maximum deceleration < 3.6 m/s² | 3.07 m/s² | passed |
| loss of radar measurements for 0.4 s | cycles without target = 0 | 0 | passed |
| car in the next lane at the entry of a curve, poor lines | time as a false target = 0 | 0 s | passed |
| stop & go on a 4% climb | stopping distance 4 ± 0.5 m | 3.93 m | passed |
| stop & go on a 4% climb | rollback < 0.1 km/h | 0.00 km/h | passed |
| stop & go on a 4% climb | WAIT, then RES, then ACTIVE | yes | passed |
| payload, 6% climb, headwind, weak brakes | speed error < 2 km/h | 0.36 km/h | passed |
| intermediate zone with a noisy request | changes between engine and brakes ≤ 4 | 4 | passed |
| sensor fault while braking | jerk of the request ≤ 2 m/s³ | 2.00 m/s³ | passed |
The criteria are not chosen at random: deceleration and jerk come from the standard (lesson 1), the distances from safety, the false positive and the loss of measurements from the situations that ruin the driver’s trust, the zone changes from comfort.
Almost every row of this table had, during development, a wrong first result, and each one taught something:
- fusion worse than the camera alone (process noise too small, lesson 3);
- the “elastic” approach braking more than the normal one (the mild phase could brake more than necessary, lesson 5);
- stopping at 15 m instead of 4 (the state machine took a slowdown for a stop, and the planner copied the target’s braking instead of aiming at its stopping point, lesson 5);
- braking at −3.9 m/s² instead of −3 (integral wound up during the waiting time of the zone change, lesson 6);
- rolling back uphill (the brakes opened in the coast zone at almost zero speed, lesson 6);
- the short time gap making the string unstable (fixed gains, lesson 5).
This is why automatic tests matter more than any review by eye.
The same chain in C
The C99 version (acc.h, acc.c) is written as AUTOSAR components: every component has an initialisation function and a runnable with explicit inputs and outputs, no dynamic memory, no recursion, only float. The test bench test_acc.c contains a vehicle model (engine with dead time and delay, brakes with springs and pad clearance, static friction at standstill) and 13 scenarios:
Approach 130 -> 80 km/h peak deceleration [m/s2] 0.74 PASS
Approach 130 -> 80 km/h gap error after 60 s [%] 0.52 PASS
Stop & go, 4 % climb stops 2.00 PASS
Stop & go, 4 % climb 1st stop distance (d0 = 4) [m] 3.94 PASS
Stop & go, 4 % climb 2nd stop distance (d0 = 4) [m] 3.95 PASS
Stop & go, 4 % climb rollback speed [km/h] -0.00 PASS
Stop & go, 4 % climb WAIT then RES -> ACTIVE 1.00 PASS
Cut-in, lateral speed 1 m/s locked at t [s] (python 3.9) 3.90 PASS
Next-lane car at 95 m, no lines time locked [s] 0.00 PASS
Coast zone, noisy request zone changes (4 needed) 4.00 PASS
Coast zone, noisy request max |a - a_req| [m/s2] 0.09 PASS
Payload 350 kg + 6 % climb max speed error [km/h] 0.36 PASS
Sensor fault while braking jerk of the request [m/s3] 2.00 PASS
13/13 PASSIt compiles without a single warning with gcc -std=c99 -O2 -Wall -Wextra -Wpedantic -o test_acc acc.c test_acc.c -lm. The results match the Python ones (stops at 3.94 and 3.95 m against 3.93 and 3.94, cut-in locked at 3.90 s against 3.92, speed error 0.36 km/h in both): two independent implementations of the same algorithm giving the same numbers are strong evidence that both do what the theory says.
The parameters
| Parameter | Value | Where | Why |
|---|---|---|---|
| time gap | 1.0 / 1.4 / 1.8 / 2.2 s | state machine | four settings, the standard asks for ≥ 0.8 and one between 1.5 and 2.2 |
| 4 m | planner | distance at standstill | |
| 0.15, 0.6 (or more), 0.3 | planner | damping > 1, string stability | |
| elasticity | 0.25 h v, at most 12 m | planner | softer braking in the approach |
| preboost | 0.9 s, +0.6 m/s², 4 s | planner | smoother overtaking, never below 0.9 s |
| 0.60, 0.35 | selection | hysteresis | |
| 0.3 + 0.25 | selection | longer confirmation if the path is uncertain | |
| 0.6 s | selection | short loss of measurements | |
| 2.0, 1.5 m/s² | fusion | real manoeuvres (lane change) | |
| zone C band | ± 0.08 m/s² | torque | about the minimum useful braking torque |
| minimum time in a zone | 0.3 s | torque | no engine/brake oscillations |
| 0.6, 1.2 | torque | correction of model errors |
Where this subject sits
The seven lessons are in the Automotive subject, with their syllabus; they use tools from other subjects, which they refer to where needed:
- Automatic control: stability, second-order response, PID and anti-windup (lessons 5 and 6);
- Digital control: Kalman filter, observers, discretisation, computation delay, optimal and predictive control (lessons 1, 3, 5);
- Communications and Electromagnetic fields: the FMCW radar (lesson 2);
- Physics 1: dynamics, inclined plane, rotation (lesson 6);
- Numerical methods and Mathematical methods: least squares, Gaussian and probability (lessons 3, 4, 6).
Where to go from here
The code is a real starting point, but a series ACC still requires:
- calibration on the vehicle: the parameters of the engine, the brakes and the comfort tables are measured on the car, not invented;
- several motion models in the tracker (IMM) and probabilistic association in dense traffic;
- the next lane for the preboost, from the corner radars, and the prediction of the trajectories of other vehicles;
- functional safety: hazard analysis (ISO 26262), independent monitors of the requests, fault injection tests;
- homologation and Euro NCAP tests, which use scenarios very similar to those in the table.
Download the complete code (zip, 42 kB): acc_sim.py, make_plots.py, test_scenarios.py, acc.h, acc.c, test_acc.c and instructions. It needs Python 3.8 or newer with numpy (matplotlib for the charts) and a C99 compiler.
The code is meant to be read, changed and run again: change a parameter, rerun the tests and see which criterion stops being met. It is the quickest way to understand why every detail of the previous lessons is there.
∑Formula sheet
Sensors and configurations
The camera: distance from the road plane
![]()
![Rendered by QuickLaTeX.com \[ \sigma_Z = \left|\frac{dZ}{d\Delta y}\right| \sigma_y = \frac{f H}{\Delta y^2}\,\sigma_y = \frac{Z^2}{f H}\,\sigma_y. \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-a6034578325c27f8e8d4977ff2d13d98_l3.png)
Time to collision without knowing the distance
![]()
The FMCW radar
![]()
Radar and camera fusion
The model of relative motion
![]()
![Rendered by QuickLaTeX.com \[ F = \begin{bmatrix}1&T&0&0\\0&1&0&0\\0&0&1&T\\0&0&0&1\end{bmatrix},\quad G = \begin{bmatrix}T^2/2&0\\T&0\\0&T^2/2\\0&T\end{bmatrix},\quad Q = G\,\mathrm{diag}(q_x^2, q_y^2)\,G^T. \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-5c72a73869966fe43ef086161194e36b_l3.png)
The Kalman filter
![]()
![]()
Why two sensors are better than one
![]()
The measurements of the two sensors
![]()
Target selection and path prediction
From the yaw rate
![]()
![]()
![]()
The probability of being on our path
![]()
Planning, following and stop & go
The constant time gap policy
![]()
Steady-state following
![]()
![]()
![]()
String stability
![]()
![]()
![]()
Approaching a slower vehicle
![Rendered by QuickLaTeX.com \[ a_{kin} = -\frac{\Delta v^2}{2\,(d - d_{end})} + a_t. \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-f8e3c036bde461d893870adbc9a7a7ae_l3.png)
![Rendered by QuickLaTeX.com \[ |a_{kin}| = \frac{\Delta v^2}{2\,(d - d_{des} + \delta)} \mathchar"313C \frac{\Delta v^2}{2\,(d - d_{des})}. \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-62dad1f06c132718d86d27e3a7a20a88_l3.png)
Stop & go
![Rendered by QuickLaTeX.com \[ a_{stop} = -\frac{v^2}{2\,(x_{stop} - d_0)}. \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-1edee3f4567249eb16a86160054453bd_l3.png)
Torque control: powertrain and brakes
The forces on the vehicle
![]()
The equivalent mass
![]()
The feedforward part: the inverse model
![]()
![]()
The three zones
![]()
Estimating grade and mass
![]()
![Rendered by QuickLaTeX.com \[ \underbrace{\hat T_{pt}/r - F_a - m_{nom} k_{rot}\,\hat a}_{y} = m\,\underbrace{(a_{imu} + g\,c_r)}_{\varphi}, \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-7872eeb292e2aa0ca455a21745bdc2e5_l3.png)
![]()