Project 2 Adaptive Cruise Control
Aim-
The main of the project is to guide the vehicle according to the speed and obstacle front of it and it does by adapative cruise control of the vehicle, this reduces stress on the driver.
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.
so we here going to try to achieve adaptive cruise control in it's most simpliest form and do the required block setups in simulink.
Objective-
- 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
Simulink model of the system-


How requirment tagging is done?
Right click on the block link it to word and highlight the follwing which you to tag and then on the requirment we'll see an option link it to some x jst link it to that.
Requirment -1 Tagging-
- 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.

Adaptive cruise control-
- 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.
Rest of the requirment tagging are done on the state flow chart-
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

Creation of sldd -
|
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 |
- |
- |

For input Imported external and for output export to file and connection between to blocks localizable and the rest of variable parameters are added.
Model advisor check-
It's done for checking whether model is working properly and what are the errors in it and what all are the warning and how to reduce the warning and create a better model-

Changed the inherit data type to required data type(ACC)-

The generated code-
* Inport: '/Time_Gap'
*/
if ((DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >= Set_Speed) &&
(Time_Gap >= Set_Gap)) {
major_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
/* Outport: '/Output' */
major_project_Y.Output = 2U;
} else if (LeadVehicle_Detected == 0) {
major_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected_Res;
/* Outport: '/Output' */
major_project_Y.Output = 1U;
} else {
if ((DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed >
DriveVehicle_Speed) && (Time_Gap >= Set_Gap)) {
major_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_equal_Set_;
/* Outport: '/Output' */
major_project_Y.Output = 5U;
}
}
break;
case maj_IN_LeadVehicle_Not_Detected:
/* Outport: '/Output' */
major_project_Y.Output = 1U;
/* Inport: '/Set_Speed' incorporates:
* Inport: '/Set_Gap'
* Inport: '/Time_Gap'
*/
if ((LeadVehicle_Detected == 1) && (DriveVehicle_Speed == Set_Speed) &&
(LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)) {
major_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
/* Outport: '/Output' */
major_project_Y.Output = 2U;
} else {
if (((LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed)) ||
(Time_Gap < Set_Gap)) {
major_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
/* Outport: '/Output' */
major_project_Y.Output = 4U;
}
}
break;
case IN_LeadVehicle_Not_Detected_Res:
/* Outport: '/Output' */
major_project_Y.Output = 1U;
break;
case IN_LeadVehicle_Speed_equal_Set_:
/* Outport: '/Output' */
major_project_Y.Output = 5U;
/* Inport: '/Set_Speed' incorporates:
* Inport: '/Set_Gap'
* Inport: '/Time_Gap'
*/
if ((LeadVehicle_Detected == 0) || (DriveVehicle_Speed <= Set_Speed)) {
major_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected_Res;
/* Outport: '/Output' */
major_project_Y.Output = 1U;
} else if (((DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed >
DriveVehicle_Speed)) || (Time_Gap >= Set_Gap)) {
major_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Resume;
/* Outport: '/Output' */
major_project_Y.Output = 3U;
} else {
if (((LeadVehicle_Speed < Set_Speed) && (LeadVehicle_Speed <
DriveVehicle_Speed)) || ((int32_T)rt_roundd_snf(0.75 * (real_T)
Set_Gap) == Time_Gap)) {
major_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
/* Outport: '/Output' */
major_project_Y.Output = 4U;
}
}
break;
default:
/* Outport: '/Output' */
/* case IN_LeadVehicle_Speed_lessthan_Set_Speed: */
major_project_Y.Output = 4U;
/* Inport: '/Set_Speed' */
if ((LeadVehicle_Detected == 0) && (DriveVehicle_Speed == Set_Speed)) {
major_project_DW.is_ACC_ON_MODE = maj_IN_LeadVehicle_Not_Detected;
/* Outport: '/Output' */
major_project_Y.Output = 1U;
} else {
tmp = (int32_T)rt_roundd_snf((real_T)LeadVehicle_Speed * 1.25);
/* Inport: '/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: '/Time_Gap' incorporates:
* Inport: '/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))) {
major_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_equal_Set_;
/* Outport: '/Output' */
major_project_Y.Output = 5U;
}
}
break;
}
}
/* End of Inport: '/Set_Switch' */
}
/* Model step function */
void major_project_step(void)
{
/* Sum: '/Sum' incorporates:
* Inport: '/CameraInput_LeadVehicle'
* Inport: '/RadarInput_LeadVehicle'
*/
LeadVehicle_Speed = (uint8_T)((uint32_T)CameraInput_LeadVehicle +
RadarInput_LeadVehicle);
/* Delay: '/Delay' */
Acceleration_Mode = major_project_DW.Delay_DSTATE;
/* Sum: '/Sum' incorporates:
* Inport: '/CameraInput_DriveVehicle'
* Inport: '/RadarInput_DriveVehicle'
*/
DriveVehicle_Speed = (uint8_T)((uint32_T)(uint8_T)((uint32_T)
CameraInput_DriveVehicle + Acceleration_Mode) + RadarInput_DriveVehicle);
/* SignalConversion: '/Signal Conversion' incorporates:
* Inport: '/RadarInput_DriveVehicle'
*/
LeadVehicle_Detected = RadarInput_DriveVehicle;
/* Chart: '/ACC_LOGIC' incorporates:
* Inport: '/CruiseSwitch'
* Inport: '/Set_Switch'
*/
if (major_project_DW.is_active_c3_major_project == 0U) {
major_project_DW.is_active_c3_major_project = 1U;
major_project_DW.is_c3_major_project = major_project_IN_ACC_OFF_MODE;
/* Outport: '/Output' */
major_project_Y.Output = 0U;
} else {
switch (major_project_DW.is_c3_major_project) {
case major_project_IN_ACC_OFF_MODE:
if (CruiseSwitch) {
major_project_DW.is_c3_major_project = major_proje_IN_ACC_STANDBY_MODE;
/* Outport: '/Output' */
major_project_Y.Output = 1U;
} else {
major_project_DW.is_c3_major_project = major_project_IN_ACC_ON_MODE;
major_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
/* Outport: '/Output' */
major_project_Y.Output = 2U;
}
break;
case major_project_IN_ACC_ON_MODE:
major_project_ACC_ON_MODE();
break;
default:
/* Outport: '/Output' */
/* case IN_ACC_STANDBY_MODE: */
major_project_Y.Output = 1U;
if (!CruiseSwitch) {
major_project_DW.is_c3_major_project = major_project_IN_ACC_OFF_MODE;
/* Outport: '/Output' */
major_project_Y.Output = 0U;
} else {
if (Set_Switch) {
major_project_DW.is_c3_major_project = major_project_IN_ACC_ON_MODE;
major_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
/* Outport: '/Output' */
major_project_Y.Output = 2U;
}
}
break;
}
}
/* End of Chart: '/ACC_LOGIC' */
/* Update for Delay: '/Delay' incorporates:
* Outport: '/Output'
*/
major_project_DW.Delay_DSTATE = major_project_Y.Output;
}
/* Model initialize function */
void major_project_initialize(void)
{
/* (no initialization code required) */
}
/* Model terminate function */
void major_project_terminate(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
The Adaptive cruise control is designed according to the requirements. The code is generated by using embedded coder. The model is checked for MAB test using Model Advisor and report is added. The requirement blocks are linked to selection in the Word document. There are many advancements in the Adaptive cruise control like turn by turn ACC, the vehicle automatically changes the speed according to the road condition, traffic, turning and slope. It has some limitations, it is not advisable to use ACC in the Bad weather conditions such as heavy rain, storm, foggy and snowy road. These weather condition may affect the sensor output which may lead to serious damage to vehicle and driver.