Model-Based Development for ADAS, Part 2: An ACC Example from MIL to HIL
One adaptive cruise control feature taken through model-based development: testable requirements, a constant time-gap controller model, closed-loop MIL runs of lead-car braking and cut-in scenarios (gap, speed and acceleration checked against limits), test cases and decision coverage, and what changes at SIL, PIL and HIL.

To take an ADAS feature through model-based development, you write its requirements as numeric, testable statements, build the controller as a Simulink/Stateflow model, and run it in closed loop against a vehicle model and traffic scenarios (MIL). Then you measure coverage, generate code and re-run the same tests on the code (SIL, PIL) and on the real ECU (HIL). This part does that for adaptive cruise control (ACC), with every result computed by a script.
In short
- The ACC keeps a gap of , which is 45 m at 90 km/h. The acceleration command is limited to -3 to +2 m/s². These are the defaults in MathWorks' Adaptive Cruise Control System block and its reference example.
- When the lead car brakes at 2 m/s² from 90 to 36 km/h, the simulated ACC keeps the gap within 0.9 m of target. The gap never drops below 24 m, and the car never decelerates harder than 2.03 m/s².
- When the lead car brakes at 6 m/s² to a stop, ACC alone cannot avoid it. It raises a takeover alert at once but, limited to 3 m/s², hits the stopped car 4.8 s after the lead began braking, at 47 km/h. With a separate AEB function (time-to-collision under 2 s, 8 m/s² braking) it stops 3.1 m short.
- Five test cases reach 100% decision coverage of the controller (60%, 80%, 80%, 100%, 100% cumulative). A back-to-back check of the 64-bit model against a 32-bit "code" version differs by at most 2.0 × 10⁻⁶ m/s².
About the numbers: the simulation is a Python illustration of the Simulink model described below, written so you can see every equation. It is not MATLAB or Simulink output. Parameters marked as assumptions (controller gains, scenarios, AEB thresholds) are ours, chosen for teaching. The script asserts the physics as it runs: no negative gaps or speeds, commands within limits, braking below the tyre-friction limit, SI units throughout. New to MBD? Read Part 1: what model-based development is, the V-model, MIL to HIL and ISO 26262 first. To compare course options, see all 11 Skill-Lync ADAS and autonomous driving courses, from 12-week courses in model-based development, validation, computer vision, SLAM, path planning and control to full programs, with fees, duration and projects in one table.
Why use adaptive cruise control as the example?
ACC is the classic first MBD project because it has only longitudinal motion, clear numeric requirements (set speed, time gap, acceleration limits) and two modes: hold a speed, or follow a car. It still shows every MBD step, including mode logic, saturation, a hand-over to the driver and the hand-off to emergency braking.
ISO 15622:2018 is the international standard for ACC performance requirements and test procedures. Its abstract makes two points that shape the design: ACC provides longitudinal control on highways, and a full-speed-range system stops behind a tracked vehicle only within its limited deceleration. It is not a collision-avoidance system. That is why our model has a takeover alert, and why the hard-braking test below needs AEB. For how radar, camera and AEB decide to brake, see how self-driving cars detect and avoid obstacles.
How do you write ACC requirements as testable statements?
A testable requirement names one behaviour, the condition it applies in, a number with units and a pass criterion a script can check. "ACC should follow smoothly" cannot be tested. "In gap mode, the gap stays within 1 m of 10 m + 1.4 s × speed within 30 s of acquiring the lead" can.
| ID | Requirement | Test | Result |
|---|---|---|---|
| R1 | Speed mode: reach the set speed within 0.5 m/s in 15 s, overshoot below 0.5 m/s | TC1 | Pass: 6.4 s, no overshoot |
| R2 | Gap mode: gap within 1 m of within 30 s of acquiring a lead car | TC2 | Pass: 15.4 s |
| R3 | Acceleration command always within -3 to +2 m/s² | TC1-TC5 | Pass: extremes -3.00 and +2.00 |
| R4 | Lead braking within ACC authority: gap never below 10 m, no takeover alert | TC3 | Pass: minimum gap 24.0 m |
| R5 | If the required deceleration exceeds 3 m/s², raise a takeover alert within 0.5 s of the lead starting to brake | TC4 | Pass: alert at 0.1 s |
| R6 | Cut-in at equal speed: no takeover alert, gap within 1 m of target within 20 s | TC5 | Pass: 11.1 s, no alert |
The 10 m, 1.4 s and -3/+2 m/s² values come from MathWorks' ACC block defaults and reference example. A production program takes them from ISO 15622 and the vehicle maker's own specification instead. The 0.5 m/s, 1 m, 15 s, 20 s and 30 s tolerances are our assumptions.
In Simulink you keep these requirements in Requirements Toolbox, or import them from a requirements-management tool, and link each one to the blocks that implement it and the tests that verify it. In practice you open the requirement set next to the model, select a requirement and drag it onto the subsystem, so every block has a reason to exist and every requirement has an implementation. The traceability matrix then shows gaps: a requirement with no test, or a block with no requirement.
What does the ACC controller model look like?
The controller has a spacing policy, two proportional controllers, a min-select and a limiter. The spacing policy sets the desired gap from ego speed. A gap controller and a speed controller each propose an acceleration, and the smaller (safer) proposal wins. The result is clipped to the comfort limits and sent to the powertrain and brakes.
The constant time-gap spacing policy makes the desired gap grow in proportion to speed, so the gap is always the same number of seconds of travel:
The two controllers and the selection are:
with , and (our gains). The vehicle is MathWorks' example model, a 0.5 s lag from acceleration command to actual acceleration, then integration to speed:
Before simulating anything, check that the loop is stable. In gap mode the closed loop has poles at and . In speed mode it has a double pole at , so it is critically damped and should not overshoot. All poles are in the left half-plane, and the script asserts it.
The takeover logic estimates the deceleration needed to stop behind a braking lead car, assuming the lead keeps braking at its current rate:
If exceeds the ACC's 3 m/s², the driver is alerted. When the lead is not braking but is slower, the same idea is applied to the relative speed.
Before code generation, the model gets the housekeeping that makes it reviewable. Parameters such as and the gains go into a Simulink data dictionary with data types and units, not loose workspace variables. Inports go on the left and outports on the right, and signals are named. The Model Configuration Parameters (solver, fixed step, data validity, code-generation target) are set for a fixed-step embedded target. The Model Advisor then runs the modelling-guideline checks (MAB/JMAAB and the ISO 26262 high-integrity checks) and produces a report of what to fix. Skill-Lync's Simulink for mechanical and electrical engineers course covers this modelling hygiene.
How do you run a closed-loop MIL simulation?
A MIL test connects the controller model to a plant model (the ego vehicle) and a scenario (the lead car's motion), runs it, and checks the outputs against the requirements automatically. The controller runs at its real sample time, here 0.1 s as in the MathWorks example, while the plant is integrated in finer steps of 0.001 s.
Our script does what a Simulink Test harness with assessments would do:
- Build the scenario: initial speeds and gap, and when and how hard the lead car brakes.
- Step the plant every 1 ms. Run the controller every 100 ms and hold its output in between (zero-order hold).
- Stop the run if the gap reaches zero (a collision), and record the time and speed.
- Assert the physics on every logged sample: gap ≥ 0, both speeds ≥ 0 (brakes cannot reverse a car), ACC command within -3 to +2 m/s², and actual deceleration within the friction limit m/s².
- Evaluate R1 to R6 and print pass or fail with the evidence.
Here is the heart of the controller step, in the same order as the block diagram:
u_speed = KV * (v_set - v)
if lead_valid: # radar object within 150 m
d_des = D0 + TH * v # 10 m + 1.4 s * v
u_gap = KD * (d - d_des) + KR * (v_lead - v)
u = min(u_gap, u_speed) # safer proposal wins
else:
u = u_speed
a_cmd = min(max(u, A_MIN), A_MAX) # -3 ... +2 m/s^2
tor = lead_valid and (a_req > -A_MIN) # takeover alert
Does the ACC hold the gap when the lead car brakes?
Yes, within its authority. In TC3 both cars travel at 90 km/h, 45 m apart. At 5 s the lead brakes at 2 m/s² for 7.5 s, down to 36 km/h. The ACC tracks the shrinking target gap to within 0.9 m and settles at 24.0 m, which is . It never decelerates harder than 2.03 m/s² and raises no alert.
The gap dips just below target while the lead brakes, and the actual acceleration is smoother than the command. Both come from the 0.5 s powertrain lag, and a reviewer will ask whether the controller is fighting it.
What happens when the lead car brakes harder than ACC can?
The ACC cannot stop in time, and the test proves it. In TC4 the lead brakes at 6 m/s² from 90 km/h to a standstill. The takeover alert fires 0.1 s later, one controller sample. But limited to 3 m/s², the ACC alone reaches the stopped car at 9.8 s, travelling at 47 km/h. A separate AEB function avoids the crash.
Simple kinematics shows why, before any simulation. The lead needs m to stop, so the ego car has at most m. At 3 m/s², the ego car needs m, even with no reaction lag. No ACC tuning can fix that. Only harder braking can.
Our AEB is deliberately crude: one threshold on time-to-collision ( below 2.0 s), one brake level of 8 m/s² with a 0.2 s brake lag, on a dry road with . Those numbers are our assumptions. MathWorks' AEB reference example uses the production pattern instead: a forward-collision warning first, then staged partial braking, then full braking, each triggered by comparing TTC with the stopping time at that braking level. The point of TC4 is the requirement split. ACC must alert (R5), AEB must avoid, and the arbitration logic must let AEB's request win.
There is also a catch in our "pass" for R5. The script hands the controller the lead car's true deceleration. A real radar reports range and range rate, and the lead's deceleration has to be estimated from noisy data, so a real alert comes later than 0.1 s. A HIL test with a realistic sensor model, or a vehicle test, is where that margin gets measured.
Which test cases do you need, and how do you measure coverage?
You need at least one test per requirement, plus tests that drive every decision in the model both ways. Coverage tools measure the second part: which branches, conditions and saturations the tests actually exercised. Our five test cases reach 100% decision coverage, and two of them add nothing to coverage but are still essential.
| Test | Scenario | Checks | Key result |
|---|---|---|---|
| TC1 | Free road, accelerate from 15 (54) to set 25 (90) | R1, R3 | Within 0.5 m/s at 6.4 s; command saturates at +2.00 m/s² |
| TC2 | Slower lead at 18 (64.8), 100 m ahead | R2, R3 | Gap within 1 m of 35.2 m at 15.4 s; minimum command -1.53 m/s² |
| TC3 | Lead brakes at 2 m/s² from 25 to 10 (90 to 36) | R3, R4 | Minimum gap 24.0 m; no alert |
| TC4 | Lead brakes at 6 m/s² to a stop | R3, R5 | Alert at 5.1 s; ACC alone contact at 9.8 s; with AEB stops 3.1 m short |
| TC5 | Car cuts in 20 m ahead at equal speed 25 (90) | R3, R6 | Command saturates at -3.00 m/s²; no alert; gap within 1 m 11.1 s after the cut-in |
MathWorks' Simulink Coverage documentation defines the main metrics:
- Decision coverage: every decision point, such as a Switch block, a min/max or a Stateflow transition, has taken each of its outcomes.
- Condition coverage: every input to a logic block, or condition on a transition, has been both true and false.
- Modified condition/decision coverage (MC/DC): each condition has been shown to change the decision's outcome on its own, with the other inputs held fixed.
MC/DC exposed a design point in our model. The takeover alert is lead_valid AND a_req > 3. To show lead_valid matters on its own, a test needs lead_valid = false with a_req > 3. That can never happen, because the code sets a_req = 0 when there is no lead. The condition is therefore redundant. You either simplify the logic or write a justification. Finding this kind of thing is why stricter standards ask for MC/DC; MathWorks' coverage documentation, for example, sets it up to the DO-178C definition used in aerospace.
Each uncovered outcome in a coverage report is either a missing test, dead logic to delete, or something to justify. The test report lists every test, its assessments and the requirements it links to.
What is the difference between verification and validation?
Verification asks "did we build it right?": does the model or code meet its written requirements? Validation asks "did we build the right thing?": does the feature do what drivers and regulations actually need on real roads? MIL, SIL, PIL and HIL tests are mostly verification. Vehicle tests and SOTIF scenario studies are validation.
Both matter: a verified ACC that faithfully meets a bad requirement, such as a gap that is too short, is still unsafe. Tests are also organised in levels. Unit tests check one component (the spacing policy), integration tests check connected units (fusion into ACC into arbitration), system tests check the whole feature against its specification, including timing and robustness, and acceptance tests show the customer it works in realistic conditions.
What changes at SIL and PIL?
At SIL the generated C code replaces the model and runs on the PC with the same test vectors. At PIL it is cross-compiled and runs on the target processor or an instruction-set simulator. In both, outputs are compared back-to-back with the MIL results within a tolerance. The requirements and scenarios stay the same, and what is new is the code itself.
We imitated a back-to-back test by re-running every test case with the controller computed in 32-bit (single-precision) floats instead of 64-bit, mimicking a data-type choice made at code generation. The largest difference in the acceleration command across TC1-TC5 was 2.0 × 10⁻⁶ m/s², against a tolerance of 10⁻³ m/s², and the takeover-alert flags matched sample for sample. That is the shape of a real SIL result. Small numerical differences are expected and bounded, and any change in a discrete decision, such as an alert firing one sample later, is investigated.
Real SIL and PIL also catch things our Python stand-in cannot:
- Fixed-point scaling and integer overflow, if the code uses integer arithmetic.
- Code-generation settings that change behaviour, such as rounding or how a min/max is implemented.
- On PIL, target compiler effects, execution time per 100 ms step, and stack use.
MathWorks describes back-to-back model-and-code testing with PIL as strongly recommended by ISO 26262-6 for ASIL C and D. Embedded Coder and Simulink Test provide SIL/PIL modes and equivalence-test templates for it. Skill-Lync's Software Verification and Validation and System Testing for Model-Based Development course practises exactly this MIL-to-SIL loop.
What changes at HIL?
At HIL the code runs on the production ECU, which is wired to a real-time simulator that plays the vehicle, the traffic and the sensors. Time can no longer be paused. Inputs arrive over CAN or Ethernet with real timing, and faults can be injected on purpose. The ACC requirements stay, and new tests are added for timing, bus and failure behaviour.
For our ACC, HIL would add tests such as:
- Bus timing. The radar object list arrives as CAN frames. What if a frame is late or missing for 300 ms? The "lead valid" decision must time out safely instead of holding a stale gap.
- Sensor faults. Inject a frozen wheel-speed signal or an implausible range jump, and check that the diagnostics disable ACC and inform the driver. This is ISO 26262 territory.
- Actuator interface. Check that the acceleration request is turned into torque and brake requests the powertrain and brake ECUs accept, within the cycle time.
- Scenario libraries. Re-run TC1-TC5 and many variants (curves, cut-outs, rain) against real ECU timing.
Vendors document the tools for this layer. dSPACE SCALEXIO provides real-time simulation and I/O for ECU HIL testing. IPG CarMaker provides road, traffic and sensor models usable from MIL through HIL to vehicle-in-the-loop. Vector CANoe simulates and tests ECU networks in both SIL and HIL. After HIL comes the vehicle: proving ground first, then public roads. That is where the plant model's assumptions, including our 0.5 s lag and 8 m/s² braking, finally meet reality.
What skills do MBD engineers need for ADAS work?
An MBD engineer for ADAS needs strong MATLAB and Simulink, Stateflow for mode logic, the ability to turn vague requirements into testable ones, discipline with modelling standards, MIL/SIL testing and coverage, and working knowledge of Embedded Coder or AUTOSAR. Control basics (stability, saturation, lag) separate good modellers from block-draggers.
If you are starting from zero, take MATLAB for mechanical engineers or MATLAB and Simulink basics first, then practise writing requirements, following the MAB guidelines and building test harnesses with coverage.
MBD engineers work on powertrain control, body electronics and ADAS features alike, so the skill transfers. For a structured path, Skill-Lync's Introduction to Model-Based Development using MATLAB and Simulink and Autonomous Vehicle Controls using MATLAB and Simulink cover the modelling and control side, and the Post Graduate Program in Electric Vehicle Design & Development includes MBD within a longer program. To see who hires, browse companies that hire mechanical engineering freshers in India.
Frequently asked questions
Can I do this ACC project without Simulink?
You can learn the ideas in Python, as this post does, but employers expect Simulink. The point of MBD is the toolchain: requirements links, test harnesses, coverage and code generation from the same model. Use Python to understand the maths, then build it in Simulink.
What time gap do real ACC systems use?
The values here (10 m plus 1.4 s) are MathWorks' example defaults, not a production calibration. Production limits come from ISO 15622 and each manufacturer's specification, which are not freely published.
Why does ACC limit braking to about 3 m/s² if the car can brake harder?
ACC is designed as a convenience function with limited deceleration capability, as the ISO 15622 abstract puts it, so harsh braking in normal traffic is avoided. Strong braking is left to the driver and to AEB, which is designed and tested for emergencies. Our TC4 shows why the alert and the AEB hand-off are requirements, not extras.
Is 100% decision coverage enough?
No. It shows every branch ran, not that the behaviour was right. Our TC3 added no coverage but is the only test of the gap requirement. Stricter metrics such as MC/DC exist for critical software, and requirement-based tests remain the main evidence.
What is the difference between SIL and HIL in one line?
SIL runs the generated code on a PC to prove it matches the model. HIL runs the real ECU in real time against a simulated vehicle to prove it works with real timing, I/O and faults.
Sources and further reading
- MathWorks, Adaptive Cruise Control System block: default spacing 10 m, acceleration limits -3 / +2 m/s², ego model tf(1,[0.5,1,0]), safe distance = default spacing + time gap × ego speed (accessed 20 Nov 2026).
- MathWorks, Adaptive Cruise Control System Using Model Predictive Control: time gap 1.4 s, Ts = 0.1 s, G = 1/(s(0.5s+1)), speed/spacing mode rule (accessed 20 Nov 2026).
- MathWorks, Autonomous Emergency Braking with Sensor Fusion: FCW, staged partial braking and full braking from TTC vs stopping time (accessed 20 Nov 2026).
- MathWorks, Types of model coverage: decision, condition and MC/DC definitions (accessed 20 Nov 2026).
- MathWorks, SIL and PIL simulations, Simulink Test, Requirements Toolbox, Model Advisor and ISO 26262 pages (accessed 20 Nov 2026).
- ISO, ISO 15622:2018 Adaptive cruise control systems: performance requirements and test procedures, abstract (accessed 20 Nov 2026).
- dSPACE, SCALEXIO; IPG Automotive, CarMaker; Vector, CANoe (product pages, accessed 20 Nov 2026).
- Worked numbers and figures: Skill-Lync verification script
acc_sim.py(Python illustration of the Simulink model, not MATLAB output), run 20 Nov 2026. Gains, scenarios, 150 m radar range, takeover and AEB thresholds, 0.2 s brake lag and μ = 0.9 are labelled assumptions.


