Project 2 Adaptive Cruise Control
Aim: Design the model of Adaptive Cruise Control (ACC).
ABSTRACT: In this project, we going to build the MATLAB model of Adaptive Cruise Control (ACC) by using Simulink blocks and suitable input and output signals in SLDD. Before that, we will know about what is Adaptive Cruise Control (ACC), how it works, and the benefits of Adaptive Cruise Control (ACC). Then we make an actual model in SIMULINK with suitable blocks from the Simulink block set.
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
METHODOLOGY:
- As per the given requirement, we build the model of Adaptive Cruise Control (ACC)
- Then build the SLDD for all input and output signals in that we gave all signal parameters like Input data, data type etc.
- After the model, we generated the code by using the Code generation (embedded).
- We also check the Model adviser to check all errors and warnings.
THEORY:
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 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 stops & 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, cruise control stops & go 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.

Adaptive cruise control (ACC) is an active safety system that automatically controls the acceleration and braking of a vehicle. It is activated through a button on the steering wheel and canceled by the driver's braking and/or another button. It does so by helping the driver keep a steady vehicle speed at a given moment.

There is control on vehical of acc by only selecting an the switch
Steps:
A. Model
- Making an the model as the inports as given in the requirement documents.as the inputs and outputs
make the model as given in the requirement as the with the subsystem.-adas cruise control

- Adaptive Cruise Control Algorithm;-

3.Lead Vehical :-As taking the inputs as camera and the radar as adding these signals we get an the lead vehical speed

4.Drive vehical :-As the we get an the drive vehical we have to add all inputs we get the drive vehical speed. And by the radar input we get the lead_vehical detected

5.state flow:
As by adding the state flow transition and blocks by the given requirements

B.SLDD
1.Creat an the sldd file
in modelling we have to go on the link to data dictionary - new - acc as sldd
and add the data in it as follows
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 |
as by adding all the signal

2. after adding an the sldd we have to change some configurational parameter for the code generation as belows.



as change all the parameters of code generation as well as all the parameters
C. Requirement Tagging & Traceability:
as by the tagging the requirement document it gives the information to the devloper actually what are the requirements

D. Model Advisor:- as we have to make an the model as per the guidlines so we make the model advisor report as per MAAB


And we get an the advisor report as follows.
as the report is generated

D. Code Generation

as by right clicking on it we can generate an the code by the embedded coder

so finally we generate an the code as file
ACC.c 8.02 K
/*
* File: ACC.c
*
* Code generated for Simulink model 'ACC'.
*
* Model version : 1.7
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Fri Feb 18 16:08:39 2022
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives:
* 1. Execution efficiency
* 2. RAM efficiency
* Validation result: Not run
*/
#include "ACC.h"
/* Named constants for Chart: '<S1>/Adaptive_Cruise_Control_Algorithm' */
#define IN_LeadVehicle_Detected_Follow ((uint8_T)1U)
#define IN_LeadVehicle_Detected_Resume ((uint8_T)2U)
#define IN_LeadVehicle_Not_Detected ((uint8_T)3U)
#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 IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define IN_OFF_mode ((uint8_T)1U)
#define IN_ON_mode ((uint8_T)2U)
#define IN_Standby_mode ((uint8_T)3U)
/* Block signals and states (default storage) */
DW rtDW;
/* External inputs (root inport signals with default storage) */
ExtU rtU;
/* External outputs (root outports fed by signals with default storage) */
ExtY rtY;
/* Real-time model */
static RT_MODEL rtM_;
RT_MODEL *const rtM = &rtM_;
/* Model step function */
void ACC_step(void)
{
int32_T rtb_Acceleration_Mode;
real32_T rtb_Add;
real32_T rtb_Add_g;
/* Outputs for Atomic SubSystem: '<Root>/Subsystem' */
/* Sum: '<S3>/Add' incorporates:
* Inport: '<Root>/CameraInput_DriveVehicle'
* Inport: '<Root>/RadarInput_DriveVehicle'
* UnitDelay: '<S1>/Unit Delay'
*/
rtb_Add = (rtU.CameraInput_DriveVehicle + rtDW.UnitDelay_DSTATE) +
rtU.RadarInput_DriveVehicle;
/* Sum: '<S4>/Add' incorporates:
* Inport: '<Root>/CameraInput_LeadVehicle'
* Inport: '<Root>/RadarInput_LeadVehicle'
*/
rtb_Add_g = rtU.CameraInput_LeadVehicle + rtU.RadarInput_LeadVehicle;
/* Chart: '<S1>/Adaptive_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'
*/
if (rtDW.is_active_c3_ACC == 0U) {
rtDW.is_active_c3_ACC = 1U;
rtDW.is_c3_ACC = IN_OFF_mode;
rtb_Acceleration_Mode = 0;
} else {
switch (rtDW.is_c3_ACC) {
case IN_OFF_mode:
rtb_Acceleration_Mode = 0;
if (rtU.CruiseSwitch == 1.0F) {
rtDW.is_c3_ACC = IN_Standby_mode;
rtb_Acceleration_Mode = 1;
}
break;
case IN_ON_mode:
if (rtU.CruiseSwitch == 0.0F) {
rtDW.is_ON_mode = IN_NO_ACTIVE_CHILD;
rtDW.is_c3_ACC = IN_OFF_mode;
rtb_Acceleration_Mode = 0;
} else if (rtU.SetSwitch == 0.0F) {
rtDW.is_ON_mode = IN_NO_ACTIVE_CHILD;
rtDW.is_c3_ACC = IN_Standby_mode;
rtb_Acceleration_Mode = 1;
} else {
switch (rtDW.is_ON_mode) {
case IN_LeadVehicle_Detected_Follow:
rtb_Acceleration_Mode = 2;
if (rtU.RadarInput_DriveVehicle == 0.0F) {
rtDW.is_ON_mode = IN_LeadVehicle_Not_Detected;
rtb_Acceleration_Mode = 1;
} else if (((rtU.RadarInput_DriveVehicle == 1.0F) && (rtb_Add_g <
rtU.Set_Speed)) || (rtU.Time_Gap < rtU.Set_Gap)) {
rtDW.is_ON_mode = IN_LeadVehicle_Speed_lessthan_S;
rtb_Acceleration_Mode = 4;
}
break;
case IN_LeadVehicle_Detected_Resume:
rtb_Acceleration_Mode = 3;
if ((rtb_Add < rtU.Set_Speed) && (rtb_Add_g > rtb_Add) &&
(rtU.Time_Gap >= rtU.Set_Gap)) {
rtDW.is_ON_mode = IN_LeadVehicle_Speed_equal_Set_;
rtb_Acceleration_Mode = 5;
} else if ((rtb_Add == rtU.Set_Speed) && (rtb_Add_g >= rtU.Set_Speed) &&
(rtU.Time_Gap >= rtU.Set_Gap)) {
rtDW.is_ON_mode = IN_LeadVehicle_Detected_Follow;
rtb_Acceleration_Mode = 2;
} else if (rtU.RadarInput_DriveVehicle == 0.0F) {
rtDW.is_ON_mode = IN_LeadVehicle_Not_Detected_Res;
rtb_Acceleration_Mode = 1;
}
break;
case IN_LeadVehicle_Not_Detected:
rtb_Acceleration_Mode = 1;
if ((rtU.RadarInput_DriveVehicle == 1.0F) && (rtb_Add == rtU.Set_Speed)
&& (rtb_Add_g >= rtU.Set_Speed) && (rtU.Time_Gap >= rtU.Set_Gap))
{
rtDW.is_ON_mode = IN_LeadVehicle_Detected_Follow;
rtb_Acceleration_Mode = 2;
} else if (((rtU.RadarInput_DriveVehicle == 1.0F) && (rtb_Add_g <
rtU.Set_Speed)) || (rtU.Time_Gap < rtU.Set_Gap)) {
rtDW.is_ON_mode = IN_LeadVehicle_Speed_lessthan_S;
rtb_Acceleration_Mode = 4;
}
break;
case IN_LeadVehicle_Not_Detected_Res:
rtb_Acceleration_Mode = 1;
break;
case IN_LeadVehicle_Speed_equal_Set_:
rtb_Acceleration_Mode = 5;
if ((rtU.RadarInput_DriveVehicle == 0.0F) || (rtb_Add <= rtU.Set_Speed))
{
rtDW.is_ON_mode = IN_LeadVehicle_Not_Detected_Res;
rtb_Acceleration_Mode = 1;
} else if (((rtb_Add < rtU.Set_Speed) && (rtb_Add_g > rtb_Add)) ||
(rtU.Time_Gap >= rtU.Set_Gap)) {
rtDW.is_ON_mode = IN_LeadVehicle_Detected_Resume;
rtb_Acceleration_Mode = 3;
} else if (((rtb_Add_g < rtU.Set_Speed) && (rtb_Add_g < rtb_Add)) ||
(0.75F * rtU.Set_Gap == rtU.Time_Gap)) {
rtDW.is_ON_mode = IN_LeadVehicle_Speed_lessthan_S;
rtb_Acceleration_Mode = 4;
}
break;
default:
/* case IN_LeadVehicle_Speed_lessthan_Set_Speed: */
rtb_Acceleration_Mode = 4;
if ((rtU.RadarInput_DriveVehicle == 0.0F) && (rtb_Add == rtU.Set_Speed))
{
rtDW.is_ON_mode = IN_LeadVehicle_Not_Detected;
rtb_Acceleration_Mode = 1;
} else if ((rtb_Add_g * 1.25F >= rtb_Add) && (rtb_Add_g * 0.75F <=
rtb_Add) && (rtb_Add < rtU.Set_Speed) && (rtU.Time_Gap <=
1.25F * rtU.Set_Gap) && (rtU.Time_Gap >= 0.75F *
rtU.Set_Gap)) {
rtDW.is_ON_mode = IN_LeadVehicle_Speed_equal_Set_;
rtb_Acceleration_Mode = 5;
}
break;
}
}
break;
default:
/* case IN_Standby_mode: */
rtb_Acceleration_Mode = 1;
if (rtU.CruiseSwitch == 0.0F) {
rtDW.is_c3_ACC = IN_OFF_mode;
rtb_Acceleration_Mode = 0;
} else if (rtU.SetSwitch == 1.0F) {
rtDW.is_c3_ACC = IN_ON_mode;
rtDW.is_ON_mode = IN_LeadVehicle_Detected_Follow;
rtb_Acceleration_Mode = 2;
}
break;
}
}
/* End of Chart: '<S1>/Adaptive_Cruise_Control_Algorithm' */
/* Update for UnitDelay: '<S1>/Unit Delay' */
rtDW.UnitDelay_DSTATE = (real32_T)rtb_Acceleration_Mode;
/* End of Outputs for SubSystem: '<Root>/Subsystem' */
/* Outport: '<Root>/LeadVehicle_Speed' */
rtY.LeadVehicle_Speed = rtb_Add_g;
/* Outport: '<Root>/DriveVehicle_Speed ' */
rtY.DriveVehicle_Speed = rtb_Add;
/* Outport: '<Root>/LeadVehicle_Detected ' incorporates:
* Inport: '<Root>/RadarInput_DriveVehicle'
*/
rtY.LeadVehicle_Detected = rtU.RadarInput_DriveVehicle;
/* Outputs for Atomic SubSystem: '<Root>/Subsystem' */
/* Outport: '<Root>/Acceleration_Mode' incorporates:
* UnitDelay: '<S1>/Unit Delay'
*/
rtY.Acceleration_Mode = (real32_T)rtb_Acceleration_Mode;
/* End of Outputs for SubSystem: '<Root>/Subsystem' */
}
/* Model initialize function */
void ACC_initialize(void)
{
/* (no initialization code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
so finally we creat an model, model advisor report as well as the tagging and trecability , and c code generation.