Project 2 Adaptive Cruise Control
Project - Adaptive Cruise Control feature for an Automobile
Aim: To develop Adaptive Cruise Control feature as per the Requirement Document using MATLAB Simulink.
Objectives:
- Developing Adaptive Cruise Control feature as per the Requirement Document using MATLAB Simulink.
- Follow all the MBD related processes: Requirement Tagging & Traceability, SLDD creation, Configuration Parameter changes, Model Advisor check & Code Generation.
- In Configuration Parameters: enable “Support Floating Numbers” under Code Generation settings.
- Use Embedded Coder to generate the code.
- If choosing code generation, Storage class for Input signals: ImportedExtern; Storage class for Output signal: Export to File; Storage class for local signals: localizable; Storage class for calibration signals: Const.
- Choose sample time for all signals as 0.01s
Requirement 1– Lead Vehicle:
- Lead Vehicle is a vehicle which is driving in the road ahead of our drive vehicle. Two input signals (Signal Name: CameraInput_LeadVehicle & RadarInput_LeadVehicle).
- Ideally sensor fusion techniques will be deployed to process & analyze data from camera & radar. For complexity reasons, let’s not adapt to any such algorithms.
- We can simply add both the radar & camera inputs & the corresponding output is read as Speed profile output (Signal Name: LeadVehicle_Speed).
- Speed data of the lead vehicle is critical in implementing the Adaptive Cruise Control algorithm.
Requirement 2 – Drive Vehicle:
- Drive Vehicle is the vehicle driven by the user & this is the vehicle which has ACC algorithm in it.
- Like the Lead Vehicle, Drive Vehicle algorithm also has 2 input signals (Signal Name: CameraInput_DriveVehicle, RadarInput_DriveVehicle) & one signal coming as an Input to this subsystem (Signal Name: Acceleration_Mode) – three inputs into this requirement in total.
- Like the above requirement, sensor fusion techniques will also be deployed here, for complexity reasons we are ignoring them.
- Two output signals come from this subsystem (Signal Name: DriveVehicle_Speed & LeadVehicle_Detected).
- Signal DriveVehicle_Speed is summation of three input signals mentioned above & LeadVehicle_Detected is renamed from Input Signal RadarInput_DriveVehicle by mere use of Signal Conversion block.
Requirement 3 – Adaptive Cruise Control Algorithm:
- Adaptive Cruise Control feature has 3 major modes of operation: OFF Mode, STANDBY Mode & ON Mode. This particular requirement has to be implemented as state machine logic in Simulink.
- The input signals to this state machine system are (Signal Name: Time_Gap, Set_Speed, Set_Gap, CruiseSwitch, SetSwitch).
- Also, the output signals (Signal Name: DriveVehicle_Speed & LeadVehicle_Detected) from requirement-2 is fed back as an input signal into this state machine block.
- Additionally, output signal (Signal Name: LeadVehicle_Speed) from requirement-1 is given as an input signal to this state machine block as well.
- Output from this subsystem is a signal (Signal Name: Acceleration_Mode) which governs the vehicular speed of the drive vehicle which automatically adjusts its speed & velocity to match the lead vehicle.
Requirement 3a – ACC OFF MODE state logic:
- This is the default state inside state machine logic. Output signal Acceleration_Mode is at value 0 in this state.
- This state is governed by input signal CruiseSwitch.
- If CruiseSwitch is equal to 1, state ACC STANDBY mode will get activated. If CruiseSwitch is equal to 0, state ACC OFF mode will get activated, from either ACC ON mode or ACC STANDBY mode
Requirement 3b – ACC STANDBY MODE state logic:
- This is the second activated state inside state machine logic. Output signal Acceleration_Mode is at value 1 in this state.
- This state is governed by both input signals CruiseSwitch & SetSwitch.
- If CruiseSwitch is equal to 1, state ACC STANDBY mode will get activated. If CruiseSwitch is equal to 0, state ACC OFF mode will get activated, from either ACC ON mode or ACC STANDBY mode
- If SetSwitch is equal to 1, state ACC ON mode will get activated. If SetSwitch is equal to 0, state ACC STANDBY mode will get activated.
Requirement 3c – ACC ON MODE state logic:
This state will be activated when input signal SetSwitch is equal to 1. There are 6 sub states to this state logic: They are:
- LeadVehicle_Detected_Follow (Default)
- LeadVehicle_Not_Detected
- LeadVehicle_Detected_Resume
- LeadVehicle_Not_Detected_Resume
- LeadVehicle_Speed_lessthan_Set_Speed
- LeadVehicle_Speed_equal_Set_Speed
Requirement 3c (i) – LeadVehicle_Detected_Follow (ACC ON MODE):
- This is the default sub state inside ACC ON MODE state. Output signal Acceleration_Mode is equal to 2.
- Condition to transit from LeadVehicle_Detected_Follow to LeadVehicle_Not_Detected; Input signal condition LeadVehicle_Detected == 0.
- Condition to transit from LeadVehicle_Detected_Follow to LeadVehicle_Speed_lessthan_Set_Speed; Input Signals condition (LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed) || (Time_Gap < Set_Gap).
Requirement 3c (ii) – LeadVehicle_Not_Detected (ACC ON MODE):
- Output signal Acceleration_Mode is equal to 1.
- Condition to transit from LeadVehicle_Not_Detected to LeadVehicle_Detected_Follow; Input signals condition [(LeadVehicle_Detected==1) && (DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)]
- Condition to transit from LeadVehicle_Not_Detected to LeadVehicle_Speed_lessthan_Set_Speed; Input signals condition [(LeadVehicle_Detected == 1) && LeadVehicle_Speed < Set_Speed) || (Time_Gap < Set_Gap)]
Requirement 3c (iii) – LeadVehicle_Detected_Resume (ACC ON MODE):
- Output signal Acceleration_Mode is equal to 3.
- Condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Detected_Follow; Input signals condition [(DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)]
- Condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Not_Detected_Resume; Input signal condition LeadVehicle_Detected==0.
- Condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Speed_equal_Set_Speed; Input Signal condition [(DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed > DriveVehicle_Speed) && (Time_Gap >= Set_Gap)]
Requirement 3c (iv) - LeadVehicle_Not_Detected_Resume (ACC ON MODE):
- Output signal Acceleration_Mode is equal to 1.
Requirement 3c (v) - LeadVehicle_Speed_lessthan_Set_Speed (ACC ON MODE):
- Output signal Acceleration_Mode is equal to 4.
- Condition to transit from LeadVehicle_Speed_lessthan_Set_Speed to LeadVehicle_Not_Detected; Input signal condition [(LeadVehicle_Detected == 0) && (DriveVehicle_Speed == Set_Speed)]
- Condition to transit from LeadVehicle_Speed_lessthan_Set_Speed to LeadVehicle_Speed_equal_Set_Speed; Input signals condition [((LeadVehicle_Speed*1.25>=DriveVehicle_Speed) && (LeadVehicle_Speed * 0.75<=DriveVehicle_Speed)) && (DriveVehicle_Speed < Set_Speed) && ((Time_Gap<=1.25*Set_Gap) && (Time_Gap >=0.75*Set_Gap))]
Requirement 3c (vi) - LeadVehicle_Speed_equal_Set_Speed (ACC ON MODE):
- Output signal Acceleration_Mode is equal to 5.
- Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Not_Detected_Resume; Input signal conditions is [(LeadVehicle_Detected == 0) || (DriveVehicle_Speed <= Set_Speed)]
- Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Detected_Resume; Input signal conditions [(DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed > DriveVehicle_Speed) || (Time_Gap >= Set_Gap)]
- Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Speed_lessthan_Set_Speed; Input signals conditions [(LeadVehicle_Speed<Set_Speed) && (LeadVehicle_Speed<DriveVehicle_Speed) || (Time_Gap == 0.75*Set_Gap)]
Solution:
Link for Model files: https://drive.google.com/drive/folders/14FnhbPyBBMkMkvgA2QQmMxOVeaDxGiyF?usp=share_link
A. Introduction
Adaptive Cruise Control Feature for passenger cars allows the host vehicle to adapt to the speed in line with the flow of traffic. Driving in heavy traffic or keeping a safe distance to the preceding vehicle calls for a high level of concentration. The Adaptive Cruise Control feature can reduce the stress on the driver by automatically controlling the vehicle speed & maintaining a predefined minimum distance to the preceding vehicle. As a consequence, the driver enjoys more comfort & can concentrate on the road little better.
A radar sensor is usually at the core of the Adaptive Cruise Control. Installed at the front of the vehicle, the system permanently monitors the road ahead. As long as the road ahead is clear, cruise control feature maintains the speed set by the driver. If the system spots a slower vehicle within its detection range, it gently reduces speed by releasing the accelerator or actively engaging the brake control system. If the vehicle ahead speeds up or changes lanes, the cruise control automatically accelerates to the driver’s desired speed.
Standard Adaptive Cruise Control can be activated from speeds of around 30 km/h (20 mph) upwards and supports the driver, primarily on cross-country journeys or on freeways. The cruise control stop & go variant is also active at speeds below 30 km/h (20 mph). It can maintain the set distance to the preceding vehicle even at very low speeds and can decelerate to a complete standstill. When the vehicle remains stopped longer, the driver needs only to reactivate the system, for example by briefly stepping on the gas pedal to return to cruise control mode. In this way, cruise control stop & go supports the driver even in heavy traffic and traffic jams.
Since Adaptive Cruise Control is a comfort and convenience system, brake interventions and vehicle acceleration only take place within defined limits. Even with Adaptive Cruise Control switched on, it remains the driver’s responsibility to monitor the speed and distance from the vehicle in front.
B. Building the Model:
Firstly, we begin by defining the data dictionary for the signals to be used. For it, we follow:
Go to 'Modeling window'->'Model properties'->Click on New->Name the SLDD and save it
After creating the SLDD, we add all the signals to it as per the given details. Next, we move on to building the model. According to the given requirements, it is clear that the model should have three subsystems, corresponding to the given requirements.
Heading to the first requirement, it represents the lead vehicle in the model. The lead vehicle has two inputs to it, the camera and the radar input; while the output, i.e. the lead vehicle speed, is the addition of these inputs as per our requirement. Accordingly, the subsystem can be modelled as:

Next, is the Adaptive Cruise Control (ACC) feature of the Drive vehicle. Based on the lead vehicle speed output and inputs such as time gap, speed and gap set by the driver, cruise switch and set switch status, ACC decides the acceleration mode the vehicle should be driven in. It decides whether the vehicle should accelerate, decelerate or keep going as is. For it, it also takes 2 feedbacks from the Drive vehicle as inputs, the drive vehicle speed and the status of whether lead vehicle is detected. The decision-making is done using Stateflow charts. Three charts represent the acceleration ON, OFF and Standby modes. The default state is the off state. To transition from the off to standby state, the cruise switch value should be equal to 1. When in this state, the acceleration mode is set to 0. After transitioning into the standby state, the acceleration mode is set to 1. To transition from standby state to on state, the set switch value should be set to 1. The on state has 6 sub-states based on the camera and radar detections of the lead vehicle. The transitions between these sub-states is based on the input parameter values. As per the requirements of this subsystem, it can be modelled as:


The final subsystem represents the Drive vehicle. As discussed earlier, ACC is based on radar and camera inputs to the vehicle. Hence, the inputs to this subsystem are the radar and camera inputs and the acceleration mode; which is the output from the ACC subsystem. Based on these inputs, the drive vehicle is driven at a certain speed, as decided by the ACC system based on the acceleration mode. Basis the requirements, this subsystem can be modelled as:

The subsystems are interconnected as:

C. Code generation and model validation:
Post building the models, we'll head onto requirement tagging, generating the code, model advisor report and building the SIL block for the model. For requirement tagging we shall copy the requirements in a word file and select the text of the corresponding requirement to be tagged. Then we follow:
Right click on the subsytem built corresponding to the requirement->Go to 'Requirements'->Select 'Link to selection in word'

This will tag the selected text in word to the subsystem. Further, for generating the code and building the SIL block, firstly we need to resolve all the signals and propagate them to their last use. For it we follow :
- Right click on the signal-> Go to 'Properties'-> Check the box against 'Signal name must resolve to Simulink signal object'->Apply the changes and then 'OK'


- For propagating the signals, '<>' should be typed after double clicking on each signal extended further.
Next up, we need to configure some properties for code generation. For it:
- Go to 'Modeling window'-> Go to 'Model settings'-> Under 'Solver', change the solver type to 'Fixed-step' and Solver to 'discrete (no continuous states)', also change the 'step-size' to 0.01

- Nextly, under the same settings go to 'Code Generation'->Select the 'System target file' as 'ert.tlc' that is a embedded coder

Having done this, we right click on the top-level subsystem and follow:
- Select 'C/C++ code'->'Generate s-function'->A block will appear as shown below->In it check the box against 'Create SIL block' and hit the 'Build' option.


This should create the SIL block and generate the code. The code gets saved in the '.c' and '.h' files in our working directory automatically. Having done this, we move ahead to generate the model advisor report. For it we follow:
- Right click on the subsystem-> Go to 'Model Advisor'-> Select 'Open Model Advisor...'-> A window will pop-up as shown below


In this window we have many a options to check and verify our model against various prescribed guidelines. These checks are grouped into 'By Product' and 'By Task'. The former has checks specific to the MATLAB products used in the model, say for MATLAB or Simulink or Simscape, whereas the latter has checks specific to the tasks performed in the model. For our case we will get our model verified against the Matlab Advisory Board (MAB) guidelines. For it steps to be followed are:
Expand 'By Task'->Locate 'Modeling standards for MAB' and click on it-> On the right side 'Run selected checks' option would be available->Click on it and wait until the checks are done->The 'Summary' under the 'Report' section will inform us of the passed, failed, tasks with warnings and not-run checks
The failed tasks should be corrected on priority, while the warnings should be reduced to as low as possible.
Conclusion:
In this project, we successfully built the Adaptive Cruise Control (ACC) feature for an automobile, as per the given Requirement document, using MATLAB Simulink. In addition, we also generated the C-code for the model and built the SIL block for the Software-In-Look testing. Also, we successfully generated the model advisor report with 0 failed tasks and warnings within limits.
References:
MATLAB Documentation
!!!Thank You!!!