Adaptive Cruise Control
AIM: To develop Adaptive Cruise Control (ACC) feature as per requirement document using Simulink.
I. OVERVIEW:
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.

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.
Let us understand the few cases/modes of Adaptive cruise control:
Case (1) - Vehicle is not detected in current lane:
The drive vehicle cruises with the set speed.
Case (2) - Vehicle is detected in current lane but the lead vehicle speed is less than the set speed:
The drive vehicle follows the lead vehicle while moving with a speed of lead vehicle and also maintains the set gap between these two vehicles.
Case (3) - Vehicle is detected in current lane but the lead vehicle speed is equal to set speed:
The drive vehicle follows the lead vehicle while moving with a speed of set speed and also maintains the set gap between these two vehicles.
Case (4) - Vehicle is detected in current lane but the lead vehicle speed is more than the set speed:
The drive vehicle cruises with the set speed.

Automakers offers ACC in three different types:
(i) Full speed range: It can bring the car to full stop but must be re-activated by tapping the gas pedal.
(ii) Stop and Go: It will stop the car completely and accelerates again slowly.
(iii) Partial cruise control: It turns off below a set minimum speed.
II. REQUIREMENTS OF THE MODEL:
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)]
Signals & Calibration Data List:
|
Signal / Calibration Name |
Signal Type |
Data Type |
Dimension |
Min |
Max |
Initial Value |
Units |
|
CameraInput_LeadVehicle |
Input |
Uint8 |
1 |
0 |
255 |
- |
- |
|
RadarInput_LeadVehicle |
Input |
Uint8 |
1 |
0 |
255 |
- |
- |
|
CameraInput_DriveVehicle |
Input |
Uint8 |
1 |
0 |
255 |
- |
- |
|
RadarInput_DriveVehicle |
Input |
Uint8 |
1 |
0 |
255 |
- |
- |
|
Time_Gap |
Input |
Uint8 |
1 |
0 |
255 |
- |
- |
|
Set_Speed |
Input |
Uint8 |
1 |
0 |
255 |
- |
- |
|
Set_Gap |
Input |
Uint8 |
1 |
0 |
255 |
- |
- |
|
CruiseSwitch |
Input |
Boolean |
1 |
0 |
1 |
- |
- |
|
SetSwitch |
Input |
Boolean |
1 |
0 |
1 |
- |
- |
|
Acceleration_Mode |
Output |
Uint8 |
1 |
0 |
255 |
- |
- |
|
LeadVehicle_Speed |
Output |
Uint8 |
1 |
0 |
255 |
- |
- |
|
DriveVehicle_Speed |
Output |
Uint8 |
1 |
0 |
255 |
- |
- |
|
LeadVehicle_Detected |
Output |
Uint8 |
1 |
0 |
255 |
- |
- |
III. MODELLING OF ADAPTIVE CRUISE CONTROL FEATURE IN SIMULINK:
(i) The following figure shows the top view of the model:

(ii) Let us understand the model by diving into the 'ACC' subsystem:

- Here, three subsystems created for Lead vehicle speed calculation, Drive vehicle speed calculation and ACC algorithm implementation.
- The signal Acceleration_Mode is actually output of 'Adaptive_Cruise_Control_Algorithm' subsystem but it is fed as input to this subsystem through 'unit delay' block.
(iii) Now, let us look into the 'Lead_Vehicle_Speed_Calculation' subsystem:

- This subsystem is modelled as per Requirement 1.
- Here, inputs CamerInput_LeadVehicle and RadarInput_LeadVehicle are added to get the LeadVehicle_Speed.
- In practical, sensor fusion technologies are deployed and analyzed data from the camera and radar. To reduce the complexity of the model, we are avoiding such algorithms.
(iv) Now, let us look inside the 'Drive_Vehicle_Speed_Calculation' subsystem:

- This subsystem is modelled as per Requirement 2.
- Here, CameraInput_DriveVehicle, RadarInput_DriveVehicle and Acceleration_Mode are added to result into DriveVehicle_Speed.
- The RadarInput_DriveVehicle is converted into LeadVehicle_Detected using 'signal conversion' block.
(v) Let us look into the 'Adaptive_Cruise_Control_Algorithm' subsytem:

(vi) The whole algorithm is implemented using stateflow, so let us look inside the chart:

- This algorithm is modelled as per Requirment 3.
- Here, mainly three states are present and they are ACC_OFF (Default), ACC_STANDBY & ACC_ON.
- In ACC_ON, there are six substates and 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.
As per given requirements, all the state actions and transition conditions are implemented in the chart but all the variables/symbols will be in invalid/undefined state since they hadn't assigned as either input, local or output data. Symbols can be defined in either Model explorer or Symbols pane.
Steps to define data using Symbols Pane:
- Open the chart, click on Symbols Pane from Prepare option in Simulation tab of simulink tool bar.

- Now, onto your right symbols pane is opened as shown below figure where we can observe that all the symbols in undefined state.

- Click on the icon in Type column then you can view list of options as shown below:

- As per given requirements, symbol, Acceleration_Mode is assigned as ouput data and all other symbols as input data as shown below:

- Before implementing the logic in the chart, its action language is set to 'C' using Property Inspector tab in tool strip as shown below:

IV. TAGGING THE REQUIREMENTS TO THE SIMULINK MODEL & TRACING THEM:
- Here, we need to tag the three subsystems named as 'Lead_Vehicle_Speed_Calculation', 'Drive_Vehicle_Speed_Calculation' and 'Adaptive_Cruise_Control_Algorithm' to Requirements 1, 2 & 3 respectively which are present in the Requirement document.
- Make sure the Requirement document is stored in the current directory of the MATLAB.
- Open the document and select the text (which is to be tagged) in the Requirement document as shown below.

- Right click on the subsystem which is needed to be tagged, which opens list of options as shown below.

- Click on Requirements from list of options, which displays few options as shown below:

- By clicking on the Link to Selection in Word, the tagged subsystem flashes around two times which means the tagging is carried successfully.
- The tagged requiremnents can be traced by right clicking on tagged subsystem/block and then select Requirements and now you can observe the tagged requirements with S.No. on top.

- Click on Requirement 1 -Lead Vehicle, the Requirement document opens and displays the tagged text and the tagged subsystem changes its colour to light amber as shown below.


- Likewise, Requirement 2 & 3 are also tagged to its corresponding subsystem.
- All the tagging links are stored in .slmx extension file in the current directory.
V. STEPS TO CREATE SIMULINK DATA DICTIONARY (SLDD):
- Click on Model settings in Modelling tab of simulink tool bar and then click on Model properties which will open window as shown below:

- From above window, click on External Data option then interface is displayed as shown below:

- Now, click on New option which will create a file with an extension .sldd for that you can name it as per your requirement.
- Here, we had untick the 'Enable model access to base workspace' which forces the created .sldd file not to accessing the base workspace.
- After creating .sldd file, we can open it from your directory where it was saved or by clicking on Model data icon on bottom left corner of simulink as shown below:

- By clicking on above icon, it will ask to select one of the two options i.e, Model workspace and External data. Click on External data then a window will be opened within the Model Explorer as shown below:

Creating new signals and constants (calibrations) in SLDD file:
- By double clicking on Model file name (here, it was 'sample_file') in above window, Design Data option will be displayed then click on it.

- Now by clicking on Add option in tool bar, a list of options will be displayed (as shown below) from which you can add required new simulink signals & parameters (constants).

- When we click on simulink signal and parameter (constant/calibration), then those will be added to file as shown below:

- Now, you can edit/select the Initial value, Data type, Dimensions, Complexity Min, Max, Unit, Storage class as per given information in input file for signals and parameters.
- Whenever you edit/add the data into the SLDD, right click on the file name in Model Hierarchy and then click on 'Save Changes'.
Setting the sample time for signals in SLDD:
- Select the signal for which you want to change the sample time, which opens a window as shown below:

- For all signals, Sample time is changed to 0.01 seconds (given) from default value of -1 and then click on Apply at the bottom right of the screen.
The following image shows all the required objects (signals and parameters) are added to the SLDD file:

VI. RESOLVING SIGNALS & THEIR PROPAGATION:
We have created objects (signals and parameters)data dictionary for the signals and calibration values.
When the created Parameters used in simulink, those are directly linked to the data dictionary but that doesn't happens for signals.
So, we need to resolve the signals to corresponding simulink signal objects inorder to do that follow below steps:
(i) Right click on the signal which need to be resolved, which displays list of options as shown below.

(ii) Now, click on Properties, then a window is displayed as shown below:

(iii) Finally, tick the box beside the 'Signal name must resolve to Simulink signal object' and click on OK.
(iv) After resolving the signal to its object, a resolution icon appears onto the left of label on the signal.
Propagation of signals:
- To write signal names at every instant of signal occurance is hectic. So we can label the signal once, and we can propagate the label names at every occurance of signal.
- For propagation of signals, follow same steps as for resolving the signal until signal properties window appears as shown below:

- Now, enable the option 'Show propagated signals' and click on OK. After propagation of signal, the label is displayed inside the angle brackets (<>).
- Shortcut: You can even double click on the signal & type the label name as '<>' and then hitting the Enter button, does the propagation of signals.
VII. MODEL ADVISORY REPORT:
- Click on Modelling tab in tool bar of simulink.
- Now, click on Model Advisor option which opens a window as shown below:

- You can select whole model or particular subsystem and click on OK. (Here, whole model is selected). Then, a window a shown below is displayed:

- Now, you can select different types of checks to be run by checking the tick box beside them. Here, only Modelling Standards for MAB & JMAAB from By task category is selected as shown below:

Click on Run Selected Checks for report.

- The following figure shows summarized report for the model:

- We can even run individual checks (which initially displayed as errors/warnings) as many times we need, until we rectify them.
- Model Advisory Report (in detail) is generated when you click on Generate Report in above window. The following image is a part of Model Advisory Report.

VIII. CODE GENERATION:
- Head to 'Configuration parameters' by clicking on Model settings in Modelling tab from tool bar of simulink.
- Change the solver type to Fixed-step and solver to Discrete (non continous states) as shown in below figure.

- Now, click on Code generation in Configuration parameters, by clicking on 'Browse' option, change the 'System target file' to ert.tlc (Embedded codder).

- Suppoet floating-point numbers are enabled for code generation as shown below:

- Click on Apps tab in toolbar of simulink and then select Embedded Codder. Then interface of tool bar look like as shown below:

- Now, click on down arrow whick is below the Build option to view its options.

- Click on Generate Code then the model enter into C-code perspective and the generated code is displayed to the right of model through tool strip. The following image shows few lines of generated code:

The following code shows the complete generated C-code for designed model:
/*
* File: MBD_P2_Adaptive_Cruise_Control.c
*
* Code generated for Simulink model 'MBD_P2_Adaptive_Cruise_Control'.
*
* Model version : 1.23
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Thu Jul 21 22:20:51 2022
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "MBD_P2_Adaptive_Cruise_Control.h"
#include "MBD_P2_Adaptive_Cruise_Control_private.h"
/* Named constants for Chart: '/Chart' */
#define IN_LeadVehicle_Detected_Follow ((uint8_T)1U)
#define IN_LeadVehicle_Detected_Resume ((uint8_T)2U)
#define IN_LeadVehicle_Not_Detected_Res ((uint8_T)4U)
#define IN_LeadVehicle_Speed_equal_Set_ ((uint8_T)5U)
#define IN_LeadVehicle_Speed_lessthan_S ((uint8_T)6U)
#define MBD_IN_LeadVehicle_Not_Detected ((uint8_T)3U)
#define MBD_P2_Adapt_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define MBD_P2_Adaptive_Crui_IN_ACC_OFF ((uint8_T)1U)
#define MBD_P2_Adaptive_Cruis_IN_ACC_ON ((uint8_T)2U)
#define MBD_P2_Adaptive__IN_ACC_STANDBY ((uint8_T)3U)
/* Exported data definition */
/* Definition for custom storage class: ExportToFile */
uint8_T Acceleration_Mode; /* '/Chart' */
uint8_T DriveVehicle_Speed; /* '/Add' */
uint8_T LeadVehicle_Detected; /* '/Signal Conversion' */
uint8_T LeadVehicle_Speed; /* '/Add' */
/* Block states (default storage) */
DW_MBD_P2_Adaptive_Cruise_Con_T MBD_P2_Adaptive_Cruise_Contr_DW;
/* Real-time model */
static RT_MODEL_MBD_P2_Adaptive_Crui_T MBD_P2_Adaptive_Cruise_Contr_M_;
RT_MODEL_MBD_P2_Adaptive_Crui_T *const MBD_P2_Adaptive_Cruise_Contr_M =
&MBD_P2_Adaptive_Cruise_Contr_M_;
/* Model step function */
void MBD_P2_Adaptive_Cruise_Control_step(void)
{
/* Sum: '/Add' incorporates:
* Inport: '/CameraInput_LeadVehicle'
* Inport: '/RadarInput_LeadVehicle'
*/
LeadVehicle_Speed = (uint8_T)((uint32_T)CameraInput_LeadVehicle +
RadarInput_LeadVehicle);
/* Sum: '/Add' incorporates:
* Inport: '/CameraInput_DriveVehicle'
* Inport: '/RadarInput_DriveVehicle'
* UnitDelay: '/Unit Delay'
*/
DriveVehicle_Speed = (uint8_T)((uint32_T)(uint8_T)((uint32_T)
CameraInput_DriveVehicle + RadarInput_DriveVehicle) + Acceleration_Mode);
/* SignalConversion: '/Signal Conversion' incorporates:
* Inport: '/RadarInput_DriveVehicle'
*/
LeadVehicle_Detected = RadarInput_DriveVehicle;
/* Chart: '/Chart' incorporates:
* Inport: '/CruiseSwitch'
* Inport: '/SetSwitch'
* Inport: '/Set_Gap'
* Inport: '/Set_Speed'
* Inport: '/Time_Gap'
*/
if (MBD_P2_Adaptive_Cruise_Contr_DW.is_active_c3_MBD_P2_Adaptive_Cr == 0U) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_active_c3_MBD_P2_Adaptive_Cr = 1U;
MBD_P2_Adaptive_Cruise_Contr_DW.is_c3_MBD_P2_Adaptive_Cruise_Co =
MBD_P2_Adaptive_Crui_IN_ACC_OFF;
Acceleration_Mode = 0U;
} else {
switch (MBD_P2_Adaptive_Cruise_Contr_DW.is_c3_MBD_P2_Adaptive_Cruise_Co) {
case MBD_P2_Adaptive_Crui_IN_ACC_OFF:
Acceleration_Mode = 0U;
if (CruiseSwitch) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_c3_MBD_P2_Adaptive_Cruise_Co =
MBD_P2_Adaptive__IN_ACC_STANDBY;
Acceleration_Mode = 1U;
}
break;
case MBD_P2_Adaptive_Cruis_IN_ACC_ON:
if (!CruiseSwitch) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
MBD_P2_Adapt_IN_NO_ACTIVE_CHILD;
MBD_P2_Adaptive_Cruise_Contr_DW.is_c3_MBD_P2_Adaptive_Cruise_Co =
MBD_P2_Adaptive_Crui_IN_ACC_OFF;
Acceleration_Mode = 0U;
} else if (!SetSwitch) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
MBD_P2_Adapt_IN_NO_ACTIVE_CHILD;
MBD_P2_Adaptive_Cruise_Contr_DW.is_c3_MBD_P2_Adaptive_Cruise_Co =
MBD_P2_Adaptive__IN_ACC_STANDBY;
Acceleration_Mode = 1U;
} else {
switch (MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON) {
case IN_LeadVehicle_Detected_Follow:
Acceleration_Mode = 2U;
if (((LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed)) ||
(Time_Gap < Set_Gap)) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
IN_LeadVehicle_Speed_lessthan_S;
Acceleration_Mode = 4U;
} else if (LeadVehicle_Detected == 0) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
MBD_IN_LeadVehicle_Not_Detected;
Acceleration_Mode = 1U;
}
break;
case IN_LeadVehicle_Detected_Resume:
Acceleration_Mode = 3U;
if (LeadVehicle_Detected == 0) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
IN_LeadVehicle_Not_Detected_Res;
Acceleration_Mode = 3U;
} else if ((DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed >
DriveVehicle_Speed) && (Time_Gap >= Set_Gap)) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
IN_LeadVehicle_Speed_equal_Set_;
Acceleration_Mode = 5U;
} else if ((DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >=
Set_Speed) && (Time_Gap >= Set_Gap)) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
IN_LeadVehicle_Detected_Follow;
Acceleration_Mode = 2U;
}
break;
case MBD_IN_LeadVehicle_Not_Detected:
Acceleration_Mode = 1U;
if (((LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed)) ||
(Time_Gap < Set_Gap)) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
IN_LeadVehicle_Speed_lessthan_S;
Acceleration_Mode = 4U;
} else if ((LeadVehicle_Detected == 1) && (DriveVehicle_Speed ==
Set_Speed) && (LeadVehicle_Speed >= Set_Speed) &&
(Time_Gap >= Set_Gap)) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
IN_LeadVehicle_Detected_Follow;
Acceleration_Mode = 2U;
}
break;
case IN_LeadVehicle_Not_Detected_Res:
Acceleration_Mode = 3U;
break;
case IN_LeadVehicle_Speed_equal_Set_:
Acceleration_Mode = 5U;
if ((LeadVehicle_Detected == 0) || (DriveVehicle_Speed <= Set_Speed))
{
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
IN_LeadVehicle_Not_Detected_Res;
Acceleration_Mode = 3U;
} else if (((DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed >
DriveVehicle_Speed)) || (Time_Gap >= Set_Gap)) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
IN_LeadVehicle_Detected_Resume;
Acceleration_Mode = 3U;
} else if (((LeadVehicle_Speed < Set_Speed) && (LeadVehicle_Speed <
DriveVehicle_Speed)) || (0.75 * (real_T)Set_Gap ==
Time_Gap)) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
IN_LeadVehicle_Speed_lessthan_S;
Acceleration_Mode = 4U;
}
break;
default:
/* case IN_LeadVehicle_Speed_lessthan_Set_Speed: */
Acceleration_Mode = 4U;
if ((LeadVehicle_Detected == 0) && (DriveVehicle_Speed == Set_Speed))
{
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
MBD_IN_LeadVehicle_Not_Detected;
Acceleration_Mode = 1U;
} else if (((real_T)LeadVehicle_Speed * 1.25 >= DriveVehicle_Speed) &&
((real_T)LeadVehicle_Speed * 0.75 <= DriveVehicle_Speed) &&
(DriveVehicle_Speed < Set_Speed) && ((Time_Gap <= 1.25 *
(real_T)Set_Gap) && (Time_Gap >= 0.75 * (real_T)Set_Gap)))
{
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
IN_LeadVehicle_Speed_equal_Set_;
Acceleration_Mode = 5U;
}
break;
}
}
break;
default:
/* case IN_ACC_STANDBY: */
Acceleration_Mode = 1U;
if (!CruiseSwitch) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_c3_MBD_P2_Adaptive_Cruise_Co =
MBD_P2_Adaptive_Crui_IN_ACC_OFF;
Acceleration_Mode = 0U;
} else if (SetSwitch) {
MBD_P2_Adaptive_Cruise_Contr_DW.is_c3_MBD_P2_Adaptive_Cruise_Co =
MBD_P2_Adaptive_Cruis_IN_ACC_ON;
MBD_P2_Adaptive_Cruise_Contr_DW.is_ACC_ON =
IN_LeadVehicle_Detected_Follow;
Acceleration_Mode = 2U;
}
break;
}
}
/* End of Chart: '/Chart' */
}
/* Model initialize function */
void MBD_P2_Adaptive_Cruise_Control_initialize(void)
{
/* (no initialization code required) */
}
/* Model terminate function */
void MBD_P2_Adaptive_Cruise_Control_terminate
(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
- Also, a file named with file_name_ert_rtw is created in current directory which includes files with .c & .h extensions as shown below:

- Since C-code perspective is not default interface, whenever we reopened the model, the generated C-code is not displayed directly.
- We can enter Code perspective through Show Perspective views icon (look like Harness icon as shown below) in bottom right of the simulink model page.
- Click on Show Perspective views icon, then following options are displayed.

- Now, select the Enter Code Perspective, then interface appears as shown below:

By clicking on Code in tool strip onto your right side of screen (shown in above image through indication), then generated code is displayed and then you can access it.
SUMMARY:
- Model is designed as per given requirement document.
- All the requirements are tagged to their corresponding subsystems.
- SLDD file is created and linked to the model.
- All given signals in the model are resolved to simulink.signal objects in SLDD.
- Model Advisory Report is generated for the model.
- C-code is generated usign Embedded Codder for the designed model.
Links which opens the source pages for some of the images uploaded:
Fig1: Adaptive cruise control displaying with two cars