step 1: create new sldd file

step 2: add new signals and parameters from model explorer

step 3:
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 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
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

subsystem created:


Model advisor report check:

Model parameters check: solver and code generation :


Generate code:

* Academic License - for use in teaching, academic research, and meeting
* course requirements at degree granting institutions only. Not for
* government, commercial, or other organizational use.
* Code generated for Simulink model 'project2'.
* Simulink Coder version : 9.7 (R2022a) 13-Nov-2021
* C/C++ source code generated on : Mon Sep 26 12:55:30 2022
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
#include "project2_private.h"
/* Named constants for Chart: '<S1>/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 pro_IN_LeadVehicle_Not_Detected ((uint8_T)3U)
#define project2_IN_ACC_OFF_Mode ((uint8_T)1U)
#define project2_IN_ACC_ON_MODE ((uint8_T)2U)
#define project2_IN_ACC_STANDBY_Mode ((uint8_T)3U)
#define project2_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
/* Exported data definition */
/* Definition for custom storage class: ExportToFile */
uint8_T Acceleration_Mode; /* '<S1>/Unit Delay' */
uint8_T DriveVehicle_Speed; /* '<S2>/Add' */
uint8_T LeadVehicle_Detected; /* '<S2>/Signal Conversion1' */
uint8_T LeadVehicle_Speed; /* '<S3>/Add' */
/* Block states (default storage) */
DW_project2_T project2_DW;
/* External inputs (root inport signals with default storage) */
ExtU_project2_T project2_U;
static RT_MODEL_project2_T project2_M_;
RT_MODEL_project2_T *const project2_M = &project2_M_;
real_T rt_roundd_snf(real_T u)
if (fabs(u) < 4.503599627370496E+15) {
/* Model step function */
/* UnitDelay: '<S1>/Unit Delay' */
Acceleration_Mode = project2_DW.UnitDelay_DSTATE;
/* Sum: '<S2>/Add' incorporates:
* Inport: '<Root>/CameraInput_DriveVehicle'
* Inport: '<Root>/RadarInput_DriveVehicle'
DriveVehicle_Speed = (uint8_T)((uint8_T)(CameraInput_DriveVehicle +
RadarInput_DriveVehicle) + Acceleration_Mode);
/* SignalConversion: '<S2>/Signal Conversion1' incorporates:
* Inport: '<Root>/RadarInput_DriveVehicle'
LeadVehicle_Detected = RadarInput_DriveVehicle;
/* Sum: '<S3>/Add' incorporates:
* Inport: '<Root>/CameraInput_LeadVehicle'
* Inport: '<Root>/RadarInput_LeadVehicle'
LeadVehicle_Speed = (uint8_T)(CameraInput_LeadVehicle + RadarInput_LeadVehicle);
/* Chart: '<S1>/Logic' incorporates:
* Inport: '<Root>/CruiseSwitch'
* Inport: '<Root>/SetSwitch'
* Inport: '<Root>/Set_Gap'
* Inport: '<Root>/Set_Speed'
* Inport: '<Root>/Time_Gap'
* UnitDelay: '<S1>/Unit Delay'
if (project2_DW.is_active_c3_project2 == 0U) {
project2_DW.is_active_c3_project2 = 1U;
project2_DW.is_c3_project2 = project2_IN_ACC_OFF_Mode;
project2_DW.UnitDelay_DSTATE = 0U;
switch (project2_DW.is_c3_project2) {
case project2_IN_ACC_OFF_Mode:
project2_DW.UnitDelay_DSTATE = 0U;
if (project2_U.CruiseSwitch == 0.0) {
project2_DW.is_c3_project2 = project2_IN_ACC_STANDBY_Mode;
project2_DW.UnitDelay_DSTATE = 1U;
} else if (project2_U.CruiseSwitch == 0.0) {
project2_DW.is_c3_project2 = project2_IN_ACC_ON_MODE;
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
project2_DW.UnitDelay_DSTATE = 2U;
case project2_IN_ACC_ON_MODE:
if (project2_U.SetSwitch == 1.0) {
project2_DW.is_ACC_ON_MODE = project2_IN_NO_ACTIVE_CHILD;
project2_DW.is_c3_project2 = project2_IN_ACC_STANDBY_Mode;
project2_DW.UnitDelay_DSTATE = 1U;
switch (project2_DW.is_ACC_ON_MODE) {
case IN_LeadVehicle_Detected_Follow:
project2_DW.UnitDelay_DSTATE = 2U;
if (LeadVehicle_Detected == 0) {
project2_DW.is_ACC_ON_MODE = pro_IN_LeadVehicle_Not_Detected;
project2_DW.UnitDelay_DSTATE = 1U;
} else if (((LeadVehicle_Detected == 1) && (LeadVehicle_Speed <
project2_U.Set_Speed)) || (project2_U.Time_Gap <
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
project2_DW.UnitDelay_DSTATE = 4U;
case IN_LeadVehicle_Detected_Resume:
project2_DW.UnitDelay_DSTATE = 3U;
if ((DriveVehicle_Speed == project2_U.Set_Speed) &&
(LeadVehicle_Speed >= project2_U.Set_Speed) &&
(project2_U.Time_Gap >= project2_U.Set_Gap)) {
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
project2_DW.UnitDelay_DSTATE = 2U;
} else if (LeadVehicle_Detected == 0) {
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected_Res;
project2_DW.UnitDelay_DSTATE = 1U;
} else if ((DriveVehicle_Speed < project2_U.Set_Speed) &&
(LeadVehicle_Speed > DriveVehicle_Speed) &&
(project2_U.Time_Gap >= project2_U.Set_Gap)) {
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_equal_Set_;
project2_DW.UnitDelay_DSTATE = 1U;
case pro_IN_LeadVehicle_Not_Detected:
project2_DW.UnitDelay_DSTATE = 1U;
if ((LeadVehicle_Detected == 1) && (DriveVehicle_Speed ==
project2_U.Set_Speed) && (LeadVehicle_Speed >=
project2_U.Set_Speed) && (project2_U.Time_Gap >=
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
project2_DW.UnitDelay_DSTATE = 2U;
} else if (((LeadVehicle_Detected == 1) && (LeadVehicle_Speed <
project2_U.Set_Speed)) || (project2_U.Time_Gap <
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
project2_DW.UnitDelay_DSTATE = 4U;
case IN_LeadVehicle_Not_Detected_Res:
project2_DW.UnitDelay_DSTATE = 1U;
case IN_LeadVehicle_Speed_equal_Set_:
project2_DW.UnitDelay_DSTATE = 1U;
if ((LeadVehicle_Detected == 0) || (DriveVehicle_Speed <=
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected_Res;
} else if (LeadVehicle_Speed == 1) {
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
project2_DW.UnitDelay_DSTATE = 4U;
} else if (((DriveVehicle_Speed < project2_U.Set_Speed) &&
(LeadVehicle_Speed > DriveVehicle_Speed)) ||
(project2_U.Time_Gap >= project2_U.Set_Gap)) {
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Resume;
project2_DW.UnitDelay_DSTATE = 3U;
/* case IN_LeadVehicle_Speed_lessthan_Set_Speed: */
project2_DW.UnitDelay_DSTATE = 4U;
if ((LeadVehicle_Detected == 0) && (DriveVehicle_Speed ==
project2_DW.is_ACC_ON_MODE = pro_IN_LeadVehicle_Not_Detected;
project2_DW.UnitDelay_DSTATE = 1U;
tmp = (int32_T)rt_roundd_snf((real_T)LeadVehicle_Speed * 1.25);
if ((tmp_0 >= DriveVehicle_Speed) && ((int32_T)rt_roundd_snf
((real_T)LeadVehicle_Speed * 0.75) <= DriveVehicle_Speed) &&
(DriveVehicle_Speed < project2_U.Set_Speed) &&
(project2_U.Time_Gap <= 1.25 * project2_U.Set_Gap) &&
(project2_U.Time_Gap >= 0.75 * project2_U.Set_Gap)) {
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_equal_Set_;
project2_DW.UnitDelay_DSTATE = 1U;
/* case IN_ACC_STANDBY_Mode: */
project2_DW.UnitDelay_DSTATE = 1U;
if (project2_U.CruiseSwitch == 1.0) {
project2_DW.is_c3_project2 = project2_IN_ACC_OFF_Mode;
project2_DW.UnitDelay_DSTATE = 0U;
} else if (project2_U.SetSwitch == 1.0) {
project2_DW.is_c3_project2 = project2_IN_ACC_ON_MODE;
project2_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
project2_DW.UnitDelay_DSTATE = 2U;
/* End of Chart: '<S1>/Logic' */
/* Model initialize function */
void project2_initialize(void)
/* (no initialization code required) */
/* Model terminate function */
void project2_terminate(void)
/* (no terminate code required) */
* File trailer for generated code.