Project 2 Adaptive Cruise Control
AIM
- To develop a MATLAB Simulink model of Adaptive Cruise Control
OBJECTIVES
- Develop Adaptive Cruise Control Simulink model as per the Requirement Document.
- Follow all the MBD-related processes
- Perform SLDD creation, Configuration Parameter changes, Requirement Tagging & Traceability, Model Advisor check, and Code Generation.
General 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 from 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 a 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, the 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, the cruise control stop & go variant 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.
SIMULINK MODEL

MODEL DEVELOPMENT
SLDD creation
**the last three are considered local signals
- first, the given input, output, and local signals are added to Simulink Data Dictionary
- Goto modeling - link to data dictionary - create .sldd file

- go to model explorer then under external data, under the dictionary you created, select design data
- by using add Simulink signal, the input/output/local signals are added
- all the data types, dimensions, min/max, and storage class are entered and saved

Solver and code generation settings
- goto modeling-model settings
- change the solver settings to fixed type, discrete(no continuous states), sample time-0.01
- in code generation - select browse - ert.tlc embedded coder


Creating subsystems
- there are three subsystems. lead_vehicle, drive_vehicle, and ACC_algorithm.
- The input signals are CameraInput_LeadVehicle, RadarInput_LeadVehicle, CameraInput_DriveVehicle, RadarInput_DriveVehicle, Time_Gap, Set_Speed, Set_Gap, CruiseSwitch, SetSwitch
- the local signals are LeadVehicle_Speed, DriveVehicle_Speed, LeadVehicle_Detected
- the output signal is Acceleration_Mode and is given as feedback through the unit delay block to the drive_vehicle subsystem

- the signals used for the first time are resolved and after that, the same signals used are propagated.
- to resolve and propagate, right-click on the signal - properties.
- we can also use <> and enter for propagating signals

Requirement 1– Lead_Vehicle:
- Lead Vehicle is a vehicle that is driving ahead of our drive vehicle on the road.
- there are two input signals (CameraInput_LeadVehicle and RadarInput_LeadVehicle). Ideally, sensor fusion techniques will be deployed to process & analyze data from cameras & radar. For complexity reasons, here we are not adapting to any such algorithms.
- we are adding both the inputs and given to outport as LeadVehicle_Speed signal.
- 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 which has an Adaptive cruise control algorithm in it.
- this subsystem has 2 input signals (CameraInput_DriveVehicle and RadarInput_DriveVehicle) and one more signal coming as an Input (Acceleration_Mode). the Acceleration_Mode signal is a feedback signal.
- these 3 input signals are added and given as a local signal (DriveVehicle_Speed).
- the RadarInput_DriveVehicle signal is only copied and renamed as LeadVehicle_Detected (local signal) by using signal conversion block
- this subsystem has two outputs (local signals: DriveVehicle_Speed and LeadVehicle_Detected)

Requirement 3 – ACC_ALGORITHM:
- The Adaptive Cruise Control algorithm has 3 major modes of operation: OFF Mode, STANDBY Mode, and ON Mode. This is implemented as state machine logic (ACC_LOGIC chart)
- The input signals given to this state machine are Time_Gap, Set_Speed, Set_Gap, CruiseSwitch, and SetSwitch.
- the outputs from the other 2 subsystems are considered as local signals (LeadVehicle_Speed, DriveVehicle_Speed, and LeadVehicle_Detected) and are given as inputs to the state machine block.
- the output Acceleration_Mode from this subsystem governs the vehicular speed of the drive vehicle and 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.
- the output signal Acceleration_Mode is at value 0 in this state.
- This state is governed by the input signal CruiseSwitch.
- If CruiseSwitch is equal to 1, state ACC STANDBY mode will get activated and 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.
- the 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 and 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 and 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 the 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 the ACC ON MODE state.
- the output signal Acceleration_Mode is equal to 2.
- the condition to transit from LeadVehicle_Detected_Follow to LeadVehicle_Not_Detected is LeadVehicle_Detected == 0.
- the condition to transit from LeadVehicle_Detected_Follow to LeadVehicle_Speed_lessthan_Set_Speed are (LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed) || (Time_Gap < Set_Gap).
Requirement 3c (ii) – LeadVehicle_Not_Detected (ACC ON MODE):
- the output signal Acceleration_Mode is equal to 1.
- the condition to transit from LeadVehicle_Not_Detected to LeadVehicle_Detected_Follow are [(LeadVehicle_Detected==1) && (DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)]
- the condition to transit from LeadVehicle_Not_Detected to LeadVehicle_Speed_lessthan_Set_Speed are [(LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed) || (Time_Gap < Set_Gap)]
Requirement 3c (iii) – LeadVehicle_Detected_Resume (ACC ON MODE):
- the output signal Acceleration_Mode is equal to 3.
- the condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Detected_Follow are [(DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)]
- the condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Not_Detected_Resume is LeadVehicle_Detected==0.
- the condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Speed_equal_Set_Speed are [(DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed > DriveVehicle_Speed) && (Time_Gap >= Set_Gap)]
Requirement 3c (iv) - LeadVehicle_Not_Detected_Resume (ACC ON MODE):
- the output signal Acceleration_Mode is equal to 1.
Requirement 3c (v) - LeadVehicle_Speed_lessthan_Set_Speed (ACC ON MODE):
- the output signal Acceleration_Mode is equal to 4.
- the condition to transit from LeadVehicle_Speed_lessthan_Set_Speed to LeadVehicle_Not_Detected are [(LeadVehicle_Detected == 0) && (DriveVehicle_Speed == Set_Speed)]
- the condition to transit from LeadVehicle_Speed_lessthan_Set_Speed to LeadVehicle_Speed_equal_Set_Speed are [((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):
- the output signal Acceleration_Mode is equal to 5.
- the condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Not_Detected_Resume are [(LeadVehicle_Detected == 0) || (DriveVehicle_Speed <= Set_Speed)]
- the condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Detected_Resume are [(DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed > DriveVehicle_Speed) || (Time_Gap >= Set_Gap)]
- the condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Speed_lessthan_Set_Speed are [(LeadVehicle_Speed<Set_Speed) && (LeadVehicle_Speed<DriveVehicle_Speed) || (Time_Gap == 0.75*Set_Gap)]
all the requirements of ACC_ALGORITHM are implemented as ACC_LOGIC

Symbols pane
- To resolve undefined symbols (signals we used inside the state flow logic)
- Goto modeling -- symbols pane -- resolve the symbols. we can select input and output data as well

SLDD edit
- after resolving signals in the state logic, we need to edit the default data types of the state logic into the given data types for the input/output signals under Data Dictionary.

Requirement tagging
- open the word file containing the requirement document
- select the word (Requirement 1– Lead Vehicle) on the word file which is going to be tagged with the subsystem (Lead_Vehicle)
- then right-click on the subsystem -- Requirements -- Link to selection in word.

- after linking, right-click on subsystem -- requirements -- select the word which was tagged.
- the requirement document will be opened automatically

- the same procedure is used for all the requirement tagging.
- inside the state flow logic, right-click on the states instead of the subsystem. other than that same procedure is followed.
Model Advisor Check
- The Model Advisor checks the created Simulink model follows, proper conditions and configuration settings
- The Model Advisor checks can help you verify compliance with industry standards and guidelines.
- select modeling -- model advisor


- under By Task, select only Modeling standards for MAB
- then select Run selected checks
- after running selected checks and reducing the warnings

- then select generate report

- the model advisor report has been generated.
CODE GENERATION
- for generating C code, Goto apps -- embedded coder

- then select build option and the C code will be generated.

Generated C code
/*
* File: adaptive_cruise_control.c
*
* Code generated for Simulink model 'adaptive_cruise_control'.
*
* Model version : 1.6
* Simulink Coder version : 9.3 (R2020a) 18-Nov-2019
* C/C++ source code generated on : Fri May 27 12:32:34 2022
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "adaptive_cruise_control.h"
#include "adaptive_cruise_control_private.h"
/* Named constants for Chart: '<S2>/ACC_LOGIC' */
#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 ada_IN_LeadVehicle_Not_Detected ((uint8_T)3U)
#define adaptive_cr_IN_ACC_STANDBY_MODE ((uint8_T)3U)
#define adaptive_cru_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define adaptive_cruise_IN_ACC_OFF_MODE ((uint8_T)1U)
#define adaptive_cruise__IN_ACC_ON_MODE ((uint8_T)2U)
/* Exported data definition */
/* Definition for custom storage class: ExportToFile */
uint8_T Acceleration_Mode; /* '<S1>/Unit Delay' */
/* Definition for custom storage class: Localizable */
static uint8_T DriveVehicle_Speed; /* '<S3>/Add' */
static uint8_T LeadVehicle_Detected; /* '<S3>/Signal Conversion' */
static uint8_T LeadVehicle_Speed; /* '<S4>/Add' */
/* Block states (default storage) */
DW_adaptive_cruise_control_T adaptive_cruise_control_DW;
/* External outputs (root outports fed by signals with default storage) */
ExtY_adaptive_cruise_control_T adaptive_cruise_control_Y;
/* Real-time model */
RT_MODEL_adaptive_cruise_cont_T adaptive_cruise_control_M_;
RT_MODEL_adaptive_cruise_cont_T *const adaptive_cruise_control_M =
&adaptive_cruise_control_M_;
/* Forward declaration for local functions */
static void adaptive_cruise_con_ACC_ON_MODE(void);
real_T rt_roundd_snf(real_T u)
{
real_T y;
if (fabs(u) < 4.503599627370496E+15) {
if (u >= 0.5) {
y = floor(u + 0.5);
} else if (u > -0.5) {
y = u * 0.0;
} else {
y = ceil(u - 0.5);
}
} else {
y = u;
}
return y;
}
/* Function for Chart: '<S2>/ACC_LOGIC' */
static void adaptive_cruise_con_ACC_ON_MODE(void)
{
int32_T tmp;
int32_T tmp_0;
uint8_T tmp_1;
uint8_T tmp_2;
/* Inport: '<Root>/SetSwitch' incorporates:
* Inport: '<Root>/CruiseSwitch'
*/
if (!SetSwitch) {
adaptive_cruise_control_DW.is_ACC_ON_MODE = adaptive_cru_IN_NO_ACTIVE_CHILD;
adaptive_cruise_control_DW.is_c3_adaptive_cruise_control =
adaptive_cr_IN_ACC_STANDBY_MODE;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 1U;
} else if (!CruiseSwitch) {
adaptive_cruise_control_DW.is_ACC_ON_MODE = adaptive_cru_IN_NO_ACTIVE_CHILD;
adaptive_cruise_control_DW.is_c3_adaptive_cruise_control =
adaptive_cruise_IN_ACC_OFF_MODE;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 0U;
} else {
switch (adaptive_cruise_control_DW.is_ACC_ON_MODE) {
case IN_LeadVehicle_Detected_Follow
:
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 2U;
/* Inport: '<Root>/Set_Speed' incorporates:
* Inport: '<Root>/Set_Gap'
* Inport: '<Root>/Time_Gap'
*/
if (((LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed)) ||
(Time_Gap < Set_Gap)) {
adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Speed_lessthan_S;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 4U;
} else {
if (LeadVehicle_Detected == 0) {
adaptive_cruise_control_DW.is_ACC_ON_MODE =
ada_IN_LeadVehicle_Not_Detected;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 1U;
}
}
break;
case IN_LeadVehicle_Detected_Resume:
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 3U;
/* Inport: '<Root>/Set_Speed' incorporates:
* Inport: '<Root>/Set_Gap'
* Inport: '<Root>/Time_Gap'
*/
if ((DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >= Set_Speed) &&
(Time_Gap >= Set_Gap)) {
adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Detected_Follow;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 2U;
} else if ((DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed >
DriveVehicle_Speed) && (Time_Gap >= Set_Gap)) {
adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Speed_equal_Set_;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 5U;
} else {
if (LeadVehicle_Detected == 0) {
adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Not_Detected_Res;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 1U;
}
}
break;
case ada_IN_LeadVehicle_Not_Detected:
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 1U;
/* Inport: '<Root>/Set_Speed' incorporates:
* Inport: '<Root>/Set_Gap'
* Inport: '<Root>/Time_Gap'
*/
if ((LeadVehicle_Detected == 1) && (DriveVehicle_Speed == Set_Speed) &&
(LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)) {
adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Detected_Follow;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 2U;
} else {
if (((LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed)) ||
(Time_Gap < Set_Gap)) {
adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Speed_lessthan_S;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 4U;
}
}
break;
case IN_LeadVehicle_Not_Detected_Res:
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 1U;
break;
case IN_LeadVehicle_Speed_equal_Set_:
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 5U;
/* Inport: '<Root>/Set_Speed' incorporates:
* Inport: '<Root>/Set_Gap'
* Inport: '<Root>/Time_Gap'
*/
if ((LeadVehicle_Detected == 0) || (DriveVehicle_Speed <= Set_Speed)) {
adaptive_cruise_control_DW
.is_ACC_ON_MODE =
IN_LeadVehicle_Not_Detected_Res;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 1U;
} else if (((DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed >
DriveVehicle_Speed)) || (Time_Gap >= Set_Gap)) {
adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Detected_Resume;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 3U;
} else {
if (((LeadVehicle_Speed < Set_Speed) && (LeadVehicle_Speed <
DriveVehicle_Speed)) || ((int32_T)rt_roundd_snf(0.75 * (real_T)
Set_Gap) == Time_Gap)) {
adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Speed_lessthan_S;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 4U;
}
}
break;
default:
/* Outport: '<Root>/Acceleration_Mode' */
/* case IN_LeadVehicle_Speed_lessthan_Set_Speed: */
adaptive_cruise_control_Y.Acceleration_Mode_i = 4U;
/* Inport: '<Root>/Set_Speed' */
if ((LeadVehicle_Detected == 0) && (DriveVehicle_Speed == Set_Speed)) {
adaptive_cruise_control_DW.is_ACC_ON_MODE =
ada_IN_LeadVehicle_Not_Detected;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 1U;
} else {
tmp = (int32_T)rt_roundd_snf((real_T)LeadVehicle_Speed * 1.25);
/* Inport: '<Root>/Set_Gap' */
tmp_0 = (int32_T)rt_roundd_snf(1.25 * (real_T)Set_Gap);
if (tmp < 256) {
tmp_1 = (uint8_T)tmp;
} else {
tmp_1 = MAX_uint8_T;
}
if (tmp_0 < 256) {
tmp_2 = (uint8_T)tmp_0;
} else {
tmp_2 = MAX_uint8_T;
}
/* Inport: '<Root>/Time_Gap' incorporates:
* Inport: '<Root>/Set_Gap'
*/
if ((tmp_1 >= DriveVehicle_Speed) && ((int32_T)rt_roundd_snf((real_T)
LeadVehicle_Speed * 0.75) <= DriveVehicle_Speed) &&
(DriveVehicle_Speed < Set_Speed) && (Time_Gap <= tmp_2) && (Time_Gap
>= (int32_T)rt_roundd_snf(0.75 * (real_T)Set_Gap))) {
adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Speed_equal_Set_;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 5U;
}
}
break;
}
}
/* End of Inport: '<Root>/SetSwitch' */
}
/* Model step function */
void adaptive_cruise_control_step(void)
{
/* Sum: '<S4>/Add' incorporates:
* Inport: '<Root>/CameraInput_LeadVehicle'
* Inport: '<Root>/RadarInput_LeadVehicle'
*/
LeadVehicle_Speed = (uint8_T)((uint32_T)CameraInput_LeadVehicle +
RadarInput_LeadVehicle);
/* UnitDelay: '<S1>/Unit Delay' */
Acceleration_Mode = adaptive_cruise_control_DW.UnitDelay_DSTATE;
/* Sum: '<S3>/Add' incorporates:
* Inport: '<Root>/CameraInput_DriveVehicle'
* Inport: '<Root>/RadarInput_DriveVehicle'
*/
DriveVehicle_Speed = (uint8_T)((uint32_T)(uint8_T)((uint32_T)
CameraInput_DriveVehicle + Acceleration_Mode) + RadarInput_DriveVehicle);
/* SignalConversion: '<S3>/Signal Conversion' incorporates:
* Inport: '<Root>/RadarInput_DriveVehicle'
*/
LeadVehicle_Detected = RadarInput_DriveVehicle;
/* Chart: '<S2>/ACC_LOGIC' incorporates:
* Inport: '<Root>/CruiseSwitch'
* Inport: '<Root>/SetSwitch'
*/
if (adaptive_cruise_control_DW.is_active_c3_adaptive_cruise_co == 0U) {
adaptive_cruise_control_DW.is_active_c3_adaptive_cruise_co = 1U;
adaptive_cruise_control_DW.is_c3_adaptive_cruise_control =
adaptive_cruise_IN_ACC_OFF_MODE;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 0U;
} else {
switch (adaptive_cruise_control_DW.is_c3_adaptive_cruise_control) {
case adaptive_cruise_IN_ACC_OFF_MODE:
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 0U;
if (CruiseSwitch) {
adaptive_cruise_control_DW.is_c3_adaptive_cruise_control =
adaptive_cr_IN_ACC_STANDBY_MODE;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 1U;
}
break;
case adaptive_cruise__IN_ACC_ON_MODE:
adaptive_cruise_con_ACC_ON_MODE();
break;
default:
/* Outport: '<Root>/Acceleration_Mode' */
/* case IN_ACC_STANDBY_MODE: */
adaptive_cruise_control_Y.Acceleration_Mode_i = 1U;
if (!CruiseSwitch) {
adaptive_cruise_control_DW.is_c3_adaptive_cruise_control =
adaptive_cruise_IN_ACC_OFF_MODE;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 0U;
} else {
if (SetSwitch) {
adaptive_cruise_control_DW.is_c3_adaptive_cruise_control =
adaptive_cruise__IN_ACC_ON_MODE;
adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Detected_Follow;
/* Outport: '<Root>/Acceleration_Mode' */
adaptive_cruise_control_Y.Acceleration_Mode_i = 2U;
}
}
break;
}
}
/* End of Chart: '<S2>/ACC_LOGIC' */
/* Update for UnitDelay: '<S1>/Unit Delay' incorporates:
* Outport: '<Root>/Acceleration_Mode'
*/
adaptive_cruise_control_DW.UnitDelay_DSTATE =
adaptive_cruise_control_Y.Acceleration_Mode_i;
}
/* Model initialize function */
void adaptive_cruise_control_initialize(void)
{
/* (no initialization code required) */
}
/* Model terminate function */
void adaptive_cruise_control_terminate(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
RESULT
- Thus a MATLAB Simulink model of Adaptive Cruise Control is successfully developed under MBD guidelines. the SLDD creation, Configuration Parameter changes, Requirement Tagging & Traceability, Model Advisor check, and Code Generation are performed.