Skip to content
ELECTRONICS ENGINEERINGelectronics-engineering.com
Automotive

ACC 7: integration, 14 test scenarios and Python and C code

The complete system, how an assistance function is tested, the scenario catalogue with measurable criteria, the bugs found, the C99 version with the same results and the code to download.

https://www.electronics-engineering.com/en/acc-integration-test-scenarios-python-c-code/

No ratings yet: be the first to rate this page.

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

The complete chain
The complete chain, already seen in lesson 1: now every block has its code, its parameters and its tests.
BlockLessonPython (acc_sim.py)C (acc.c)Period
radar, camera2radar_measure, camera_measure(in the sensor ECUs)50 / 66 ms
fusion3Tracker, Track(Kalman: as in Python)per measurement
path prediction4PathPredictorPathPred_Run, PathPred_At20 ms
target selection4TargetSelectorTgtSel_Run20 ms
planner5PlannerPlanner_Run20 ms
state machine1, 5AccStateMachineAccSm_Run20 ms
torque control6TorqueController, EstimatorLongCtrl_Run20 ms (10 ms in the ESC)
vehicle (plant)6Vehiclecar_step in the test bench10 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:

  1. 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) and test_acc.c (C) do;
  2. HIL (hardware in the loop): the real ECU connected to a real-time simulator that generates the sensor and bus signals;
  3. track tests with moving targets (also the test procedures of ISO 15622 and Euro NCAP);
  4. 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

ScenarioCriterionResultOutcome
free cruise, from 100 to 120 km/hspeed error in the last 5 s < 1 km/h0.02 km/hpassed
approach from 130 to 80 km/h, 200 mmaximum deceleration < 2 m/s²0.75 m/s²passed
approach from 130 to 80 km/h, 200 mdistance error after 60 s < 5%0.40%passed
the target brakes at −4 m/s² to a stopminimum distance > 2 m3.90 mpassed
cut-in at 50 m, 12 km/h slower (complete chain)minimum distance > 15 m33.5 mpassed
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 scycles without target = 00passed
car in the next lane at the entry of a curve, poor linestime as a false target = 00 spassed
stop & go on a 4% climbstopping distance 4 ± 0.5 m3.93 mpassed
stop & go on a 4% climbrollback < 0.1 km/h0.00 km/hpassed
stop & go on a 4% climbWAIT, then RES, then ACTIVEyespassed
payload, 6% climb, headwind, weak brakesspeed error < 2 km/h0.36 km/hpassed
intermediate zone with a noisy requestchanges between engine and brakes ≤ 44passed
sensor fault while brakingjerk 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 PASS

It 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

ParameterValueWhereWhy
time gap1.0 / 1.4 / 1.8 / 2.2 sstate machinefour settings, the standard asks for ≥ 0.8 and one between 1.5 and 2.2
d_04 mplannerdistance at standstill
k_d, k_v, k_a0.15, 0.6 (or more), 0.3plannerdamping > 1, string stability k_d h^2 + 2k_v h \ge 2
elasticity \delta0.25 h v, at most 12 mplannersofter braking in the approach
preboost0.9 s, +0.6 m/s², 4 splannersmoother overtaking, never below 0.9 s
p_{in}, p_{out}0.60, 0.35selectionhysteresis
\tau_c0.3 + 0.25 \sigma_p sselectionlonger confirmation if the path is uncertain
\tau_h0.6 sselectionshort loss of measurements
q_x, q_y2.0, 1.5 m/s²fusionreal manoeuvres (lane change)
zone C band± 0.08 m/s²torqueabout the minimum useful braking torque
minimum time in a zone0.3 storqueno engine/brake oscillations
k_p, k_i0.6, 1.2torquecorrection 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.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x