All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Introduction to Advanced Driver Assistance System using MATLAB & Simulink. Project-2 Adaptive Cruise Control…
VENKATA AKHIL VARMA MANTENA
updated on 26 Oct 2021
Introduction to Advanced Driver Assistance System using MATLAB & Simulink.
Project-2 Adaptive Cruise Control
Aim: To develop a Matlab Simulink Model for Adaptive Cruise Control as per requirement and generate C-code.
Objective:
Description:
Adaptive Cruise control is an active safety system that automatically controlls the acceleration and braking of a vehicle. It is activated by the response of user by pressing a button on the steering wheel and its state is changed when there is any physical chage i.e. by braking.
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.
By continously monitoring the other vehicles and the surrounding parameters on the road this adaptive cruise control enables a safe, secure and comfortable driving experience. This function helps to keep a steady vehicle speed at a given moment.
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.
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 |
- |
- |
Given Requirement 1– Lead Vehicle:
Simulink Model:
Here as per the above requirement two inport blocks are considered and signals are labeled as 'CameraInput_LeadVehicle' & 'RadarInput_LeadVehicle'. Now both radar inputs and camera inputs are added by using add block and the resultant output is collected as the 'LeadVehicle_Speed'.
Given Requirement 2– Drive Vehicle:
Simulink Model:
The above model is developed by considering 3 inport blocks i.e. the signals are named as 'CameraInput_DriveVehicle', 'RadarInput_DriveVehicle' & 'Acceleration_Mode'. The signal 'DeriveVehicle_Speed' is considered as the summation of all the inports and hence ADD block is used. The signal 'LeadVehicle_Detected' is the required output that is obtained from the connection of inport signal 'RadarInput_DriveVehicles' is passed from the Signal conversion block and this signal is connected to the 'LeadVehicle_Detected'.
Given Requirement 3– Adaptive Cruise Control Algorithm:
State Machine System:
Requirement 3a – ACC OFF MODE state logic:
Requirement 3b – ACC STANDBY MODE state logic:
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:
Requirement 3c (i) – LeadVehicle_Detected_Follow (ACC ON MODE):
Requirement 3c (ii) – LeadVehicle_Not_Detected (ACC ON MODE):
Requirement 3c (iii) – LeadVehicle_Detected_Resume (ACC ON MODE):
Requirement 3c (iv) - LeadVehicle_Not_Detected_Resume (ACC ON MODE):
Requirement 3c (v) - LeadVehicle_Speed_lessthan_Set_Speed (ACC ON MODE):
Requirement 3c (vi) - LeadVehicle_Speed_equal_Set_Speed (ACC ON MODE):
Simulink Model for Adaptive Cruise Control (Including all the requirements):
A SLDD file is created to declare the input and output parameters from the given Signals and Calibration Datalist;
Now, as the model is ready i have performed an Advisory Check for the above model. Here select all the subsystem in order to run the advisory check. For this check only 'Modeling Standads for MAB' is selected and check is made Run. The below images show the actual settings of a Model Advisor .
After running the Advisory check, in run summary we need to check for Pass, Fail, Warning , Not Run and the Total.If ther are any Fails we need to reverify the model. Here all got passed for advisory check and hence we can proceed further to generate the C-code.
Before generaing the Ccode he following settings are made in the final model.
Code Generation:
/*
* 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.
*
* File: ACC_CompleteModel.c
*
* Code generated for Simulink model 'ACC_CompleteModel'.
*
* Model version : 1.6
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Wed Oct 27 01:10:17 2021
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "ACC_CompleteModel.h"
#include "ACC_CompleteModel_private.h"
/* Named constants for Chart: '<Root>/Advance Cruise Control Algorithm' */
#define ACC_Complet_IN_ACC_STANDBY_MODE ((uint8_T)3U)
#define ACC_CompleteMod_IN_ACC_OFF_MODE ((uint8_T)1U)
#define ACC_CompleteMode_IN_ACC_ON_MODE ((uint8_T)2U)
#define ACC_IN_LeadVehicle_Not_Detected ((uint8_T)3U)
#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)
/* Block states (default storage) */
DW_ACC_CompleteModel_T ACC_CompleteModel_DW;
/* External inputs (root inport signals with default storage) */
ExtU_ACC_CompleteModel_T ACC_CompleteModel_U;
/* External outputs (root outports fed by signals with default storage) */
ExtY_ACC_CompleteModel_T ACC_CompleteModel_Y;
/* Real-time model */
static RT_MODEL_ACC_CompleteModel_T ACC_CompleteModel_M_;
RT_MODEL_ACC_CompleteModel_T *const ACC_CompleteModel_M = &ACC_CompleteModel_M_;
/* Model step function */
void ACC_CompleteModel_step(void)
{
real_T rtb_DriveVehicle_Speed;
real_T rtb_LeadVehicle_Speed;
/* Sum: '<S2>/Add' incorporates:
* Inport: '<Root>/CameraInput_LeadVehicle'
* Inport: '<Root>/RadarInput_LeadVehicle'
*/
rtb_LeadVehicle_Speed = ACC_CompleteModel_U.CameraInput_LeadVehicle +
ACC_CompleteModel_U.RadarInput_LeadVehicle;
/* Sum: '<S3>/Add1' incorporates:
* Inport: '<Root>/CameraInput_DriveVehicle'
* Inport: '<Root>/RadarInput_DriveVehicle'
* UnitDelay: '<Root>/Unit Delay'
*/
rtb_DriveVehicle_Speed = (ACC_CompleteModel_U.CameraInput_DriveVehicle +
ACC_CompleteModel_Y.Acceleration_Mode) +
ACC_CompleteModel_U.RadarInput_DriveVehicle;
/* Chart: '<Root>/Advance Cruise Control Algorithm' incorporates:
* Inport: '<Root>/CruiseSwitch'
* Inport: '<Root>/RadarInput_DriveVehicle'
* Inport: '<Root>/SetSwitch'
* Inport: '<Root>/Set_Gap'
* Inport: '<Root>/Set_Speed'
* Inport: '<Root>/Time_Gap'
* UnitDelay: '<Root>/Unit Delay'
*/
if (ACC_CompleteModel_DW.is_active_c3_ACC_CompleteModel == 0U) {
ACC_CompleteModel_DW.is_active_c3_ACC_CompleteModel = 1U;
ACC_CompleteModel_DW.is_c3_ACC_CompleteModel =
ACC_CompleteMod_IN_ACC_OFF_MODE;
ACC_CompleteModel_Y.Acceleration_Mode = 0.0;
} else {
switch (ACC_CompleteModel_DW.is_c3_ACC_CompleteModel) {
case ACC_CompleteMod_IN_ACC_OFF_MODE:
ACC_CompleteModel_Y.Acceleration_Mode = 0.0;
if (ACC_CompleteModel_U.CruiseSwitch == 1.0) {
ACC_CompleteModel_DW.is_c3_ACC_CompleteModel =
ACC_Complet_IN_ACC_STANDBY_MODE;
ACC_CompleteModel_Y.Acceleration_Mode = 1.0;
}
break;
case ACC_CompleteMode_IN_ACC_ON_MODE:
switch (ACC_CompleteModel_DW.is_ACC_ON_MODE) {
case IN_LeadVehicle_Detected_Follow:
ACC_CompleteModel_Y.Acceleration_Mode = 2.0;
if (ACC_CompleteModel_U.RadarInput_DriveVehicle == 0.0) {
ACC_CompleteModel_DW.is_ACC_ON_MODE = ACC_IN_LeadVehicle_Not_Detected;
ACC_CompleteModel_Y.Acceleration_Mode = 1.0;
} else if (((ACC_CompleteModel_U.RadarInput_DriveVehicle == 1.0) &&
(rtb_LeadVehicle_Speed < ACC_CompleteModel_U.Set_Speed)) ||
(ACC_CompleteModel_U.Time_Gap < ACC_CompleteModel_U.Set_Gap))
{
ACC_CompleteModel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
ACC_CompleteModel_Y.Acceleration_Mode = 4.0;
}
break;
case IN_LeadVehicle_Detected_Resume:
ACC_CompleteModel_Y.Acceleration_Mode = 3.0;
if ((rtb_DriveVehicle_Speed < ACC_CompleteModel_U.Set_Speed) &&
(rtb_LeadVehicle_Speed > rtb_DriveVehicle_Speed) &&
(ACC_CompleteModel_U.Time_Gap >= ACC_CompleteModel_U.Set_Gap)) {
ACC_CompleteModel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_equal_Set_;
ACC_CompleteModel_Y.Acceleration_Mode = 5.0;
} else if (ACC_CompleteModel_U.RadarInput_DriveVehicle == 0.0) {
ACC_CompleteModel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected_Res;
ACC_CompleteModel_Y.Acceleration_Mode = 1.0;
} else if ((rtb_DriveVehicle_Speed == ACC_CompleteModel_U.Set_Speed) &&
(rtb_LeadVehicle_Speed >= ACC_CompleteModel_U.Set_Speed) &&
(ACC_CompleteModel_U.Time_Gap >= ACC_CompleteModel_U.Set_Gap))
{
ACC_CompleteModel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
ACC_CompleteModel_Y.Acceleration_Mode = 2.0;
}
break;
case ACC_IN_LeadVehicle_Not_Detected:
ACC_CompleteModel_Y.Acceleration_Mode = 1.0;
if ((ACC_CompleteModel_U.RadarInput_DriveVehicle == 1.0) &&
(rtb_DriveVehicle_Speed == ACC_CompleteModel_U.Set_Speed) &&
(rtb_LeadVehicle_Speed >= ACC_CompleteModel_U.Set_Speed) &&
(ACC_CompleteModel_U.Time_Gap >= ACC_CompleteModel_U.Set_Gap)) {
ACC_CompleteModel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
ACC_CompleteModel_Y.Acceleration_Mode = 2.0;
} else if (((ACC_CompleteModel_U.RadarInput_DriveVehicle == 1.0) &&
(rtb_LeadVehicle_Speed < ACC_CompleteModel_U.Set_Speed)) ||
(ACC_CompleteModel_U.Time_Gap < ACC_CompleteModel_U.Set_Gap))
{
ACC_CompleteModel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
ACC_CompleteModel_Y.Acceleration_Mode = 4.0;
}
break;
case IN_LeadVehicle_Not_Detected_Res:
ACC_CompleteModel_Y.Acceleration_Mode = 1.0;
break;
case IN_LeadVehicle_Speed_equal_Set_:
ACC_CompleteModel_Y.Acceleration_Mode = 5.0;
if (((rtb_DriveVehicle_Speed < ACC_CompleteModel_U.Set_Speed) &&
(rtb_LeadVehicle_Speed > rtb_DriveVehicle_Speed)) ||
(ACC_CompleteModel_U.Time_Gap >= ACC_CompleteModel_U.Set_Gap)) {
ACC_CompleteModel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Resume;
ACC_CompleteModel_Y.Acceleration_Mode = 3.0;
} else if ((ACC_CompleteModel_U.RadarInput_DriveVehicle == 0.0) ||
(rtb_DriveVehicle_Speed <= ACC_CompleteModel_U.Set_Speed)) {
ACC_CompleteModel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected_Res;
ACC_CompleteModel_Y.Acceleration_Mode = 1.0;
} else if (((rtb_LeadVehicle_Speed < ACC_CompleteModel_U.Set_Speed) &&
(rtb_LeadVehicle_Speed < rtb_DriveVehicle_Speed)) || (0.75 *
ACC_CompleteModel_U.Set_Gap == ACC_CompleteModel_U.Time_Gap))
{
ACC_CompleteModel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
ACC_CompleteModel_Y.Acceleration_Mode = 4.0;
}
break;
default:
/* case IN_LeadVehicle_Speed_lessthan_Set_Speed: */
ACC_CompleteModel_Y.Acceleration_Mode = 4.0;
if ((ACC_CompleteModel_U.RadarInput_DriveVehicle == 0.0) &&
(rtb_DriveVehicle_Speed == ACC_CompleteModel_U.Set_Speed)) {
ACC_CompleteModel_DW.is_ACC_ON_MODE = ACC_IN_LeadVehicle_Not_Detected;
ACC_CompleteModel_Y.Acceleration_Mode = 1.0;
} else if ((rtb_LeadVehicle_Speed * 1.25 >= rtb_DriveVehicle_Speed) &&
(rtb_LeadVehicle_Speed * 0.75 <= rtb_DriveVehicle_Speed) &&
(rtb_DriveVehicle_Speed < ACC_CompleteModel_U.Set_Speed) &&
(ACC_CompleteModel_U.Time_Gap <= 1.25 *
ACC_CompleteModel_U.Set_Gap) &&
(ACC_CompleteModel_U.Time_Gap >= 0.75 *
ACC_CompleteModel_U.Set_Gap)) {
ACC_CompleteModel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_equal_Set_;
ACC_CompleteModel_Y.Acceleration_Mode = 5.0;
}
break;
}
break;
default:
/* case IN_ACC_STANDBY_MODE: */
ACC_CompleteModel_Y.Acceleration_Mode = 1.0;
if (ACC_CompleteModel_U.CruiseSwitch == 0.0) {
ACC_CompleteModel_DW.is_c3_ACC_CompleteModel =
ACC_CompleteMod_IN_ACC_OFF_MODE;
ACC_CompleteModel_Y.Acceleration_Mode = 0.0;
} else if ((ACC_CompleteModel_U.SetSwitch == 1.0) ||
(ACC_CompleteModel_U.SetSwitch == 0.0)) {
ACC_CompleteModel_DW.is_c3_ACC_CompleteModel =
ACC_CompleteMode_IN_ACC_ON_MODE;
ACC_CompleteModel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
ACC_CompleteModel_Y.Acceleration_Mode = 2.0;
}
break;
}
}
/* End of Chart: '<Root>/Advance Cruise Control Algorithm' */
}
/* Model initialize function */
void ACC_CompleteModel_initialize(void)
{
/* (no initialization code required) */
}
/* Model terminate function */
void ACC_CompleteModel_terminate(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
Conclusion:
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 2 Adaptive Cruise Control
Introduction to Advanced Driver Assistance System using MATLAB & Simulink. Project-2 Adaptive Cruise Control…
26 Oct 2021 08:42 PM IST
Project 1 (Mini Project on Vehicle Direction Detection
Introduction to Advanced Driver Assistance System using MATLAB & Simulink. Project-1 Mini Project - Vehicle Direction Determination Identifying the direction of the vehicle is one of the important & diverse features in Autonomous driving & Advanced Driver Assistance Features. This particular…
17 Oct 2021 10:31 PM IST
Project
Simulink for Mechanical & Electrical Engineers Aim: - To study and analyze the BAJA All-Terrain Vehicle…
26 Aug 2021 06:46 AM IST
Week - 4
Simulink for Mechanical & Electrical Engineers To implement control logic of a “washing machine” using Stateflow. To Make a Simulink chart for the “Gear shift”. To implement control…
13 Aug 2021 09:14 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.