Project 2 Adaptive Cruise Control
EV BATCH17
AIM:
To develop a model of adaptive cruise control by using the matlab.
Objective:
Development of a MATLAB Simulink Model for Adaptive Cruise Control feature as per the requirement document following Model Based Development(MBD) related process.SLDD creation,configuration parameter changes,Model advisor check and code generation using embedded codel tool.
Overview:
Adaptive Cruise Control Feature for passenger cars allows the host vehicle to adapt to the speed in ine 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 distanec to the preceding vehicle.As a consequence,the driver enjoys more comfort & can concentrate on the road little better.
A radar sensor usually at the core of the Adaptive Cruise Control.Installed a 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 speed up or changes lanes,the cruise controll automatically accelerates to the drivers desired speed.
standard Adaptive Cruise Control can be activated from speeds of around 30 km/h (20mph) upwards and supports to the driver,primarily on cross-country journeys or on free ways.The cruise control stop & go variant is also activate at speeds below 30km/h(20mph).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 breifly stepping on the gas pedal return to cruise control mode.In this way,cruise control stop & go supports the driver even in heavy traffic and traffic jams.
since Adaptive Cruise control is the 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.
FIGURE:1 Schematic of intelligent Cruise Control,the red car automatically maintains a safe distance from blue car.
Model Development:
solver settings of Adaptive Cruise Control:


Figure:1.1 Solver Setup,Figure:1.2 Code Generation Setup.

Figure:1.3 Floating Point Setup.
Signals and calibration data:
| Signal/Calibration Name | Signal Type | Data Type | Dimension | Min | Max | Initial Value | units |
| CameraInput_LeadVehicle | Input | Uint8 | 1 | 0 | 255 | - | - |
| RadarInput_LeadVehcicle | 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 | - | - |
Creation of Simulink Data Dictionary file (SLDD):
A Simulink Data Dictionary (SLDD)file is created that contains input,output signals and calibration parameters used in the model.SLDD file is created by clicking on Modelling.then 'Model Properties',then 'External Data' and specifying a file name for the Data Dictionary.

Figure:2 Data Dictionary file in Model Explorer
Adaptive Cruise Control Model:
The main subsystem 'Adaptive Cruise Control' with inputs of 'Camera_LeadVehicle','RadarInput_Leadvehicle' ,'CameraInput_DriveVehicle','RadarInput_DriveVehcile','CruiseSwitch','Tine_Gap','Set_Speed','Set_Gap','SetSwitch'and Output is 'Acceleration_Mode' is shown below:

Figure:3 Adaptive Cruise Control Model
The Main Subsystem is further Divided into three more subsystems which are 'Requirement1-LeadVehicle','Requirement2-DriveVehicle' and 'Requiremnet3-ACC ON MODE' are shown below.

Figure:4 Lead_Vehicle,Drive_Vehicle and ACC_Algorithm subsystems present inside.
Requirement 1-LeadVehicle:
- Lead Vehicle is a vehicle which is driving in the road ahead of our device vehicle.The subsystem Lead_Vehicle contains 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,in this model such algorithms are not used.
- The speed profile output (Signal Name:LeadVehicle_Speed) is obtained by adding both the radar input and camera inputs (Signal Name:CameraInput_LeadVehicle & RadarInput_LeadVehicle).
- Speed data of the lead vehicle is critical in implementing the adptive cruise control algorithm.

Figure:5 Lead_Vehicle subsytem.
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,Driven 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,but for complexity reasons they are not used in this model.
- Two output signals come from the subsystem (Signal Name:DriveVehicle_Speed & LeadVehicleDetected).
- 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.

Figure:6 Drive_Vehicle substem
Requirement 3-Adaptive Cruise Control Algorithm:
- Adaptive Cruise Control feature has 3 major modes of operation :OFF Mode,STANDBY Mode & ON Mode.This particular requirement is 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).
- The output signals (Signal Name: DriveVehicle_Speed & LeadVehicle_Detected) from requirement-2 is fed back as an input signal into the 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.

Figure:7 State Machine Chart ACC_Algorithm subsystem for requirement 3.
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 equla to 1,state ACC STANBY 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.
if CuiseSwitch is equal to 1,state ACC STANDBY model 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 Substates to the 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(AC ON MODE):
- This is the default substate 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 to1.
- Condition to transit from LeadVehicle_Not_Detection to LeadVehicle_Detected_Follow;Input signals conditin[(LeadVehicle_Detected==1) && (DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed>=SetSpeed) && (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 == SetSpeed) && (LeadVehicle_Speed >= SetSpeed) && (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_Deteced_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 equla to 4.
- Condition to transit from LeadVehicle_Speed_lessthan_SetSpeed 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<Set_Speed) && (LeaVehicle_Speed<DriveVehicle_Speed)||(Time_Gap == 0.75*Set_Gap)].

Figure:8 ACC_Logic chart in ACC_Algorithm subsystem.
Requirement Tagging of Simulink Model:
The requirements 'Requirement 1','Requirement 2', and 'Requiremnt 3' as provided in the Requirements Word document are tagged to theri corressponding subsystem in the Simulink Model.
The Steps involved in tagging a requirement in the Simulink model is to first highlight the requirement in the Word document,then right click on the subsystem in the model that has to be tagged,then select 'Requirements' and then 'Link to Selection inWord'.
Figure:9 Highlighting the requirement to be tagged in the requirement Word document.

Figure:10 Tagging 'LeadVehicle' subsystem to its requirement in Word document.
MAAB Guidliness Check in Model Advisor:
A check is performed using 'Model Advisor' tool in Simulink to see Whether the developed model meets the modeling standards for MAAB.

Generated report should be showned below:

Figure:11 Model Advisor Report for MAAB guideliness check.
Generation of C-Code from model:
Using the embeded Coder tool in MATLAB,C code is generated for the model.

Figure:11 C code generation using embeded coder in MATLAB.
C-Codes:
The Code is transferred to the ECU of the Vehicle.The Code is Created Based on our Model behaviour (i.e.if-else condition).
The generated code should be attached below:
/*
* File: Adaptive_cruise_control.c
*
* Code generated for Simulink model 'Adaptive_cruise_control'.
*
* Model version : 1.30
* Simulink Coder version : 9.3 (R2020a) 18-Nov-2019
* C/C++ source code generated on : Mon Jun 27 10:41:47 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: '/ACC_Logic' */
#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)
#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)
/* Exported data definition */
/* Definition for custom storage class: ExportToFile */
uint8_T Acceleration_Mode; /* '/Unit_Delay' */
uint8_T DriveVehicle_Speed; /* '/Add' */
uint8_T LeadVehicle_Detected; /* '/Signal Conversion' */
uint8_T LeadVehicle_Speed; /* '/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: '/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: '/CruiseSwitch' incorporates:
* Inport: '/SetSwitch'
*/
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: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 0U;
} else 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: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 1U;
} else {
switch (Adaptive_cruise_control_DW.is_ACC_ON_MODE) {
case IN_LeadVehicle_Detected_Follow:
/* Outport: '/Acceleration_Mode' */
/* Inport: '/Set_Gap' incorporates:
* Inport: '/Set_Speed'
* Inport: '/Time_Gap'
*/
Adaptive_cruise_control_Y.Acceleration_Mode_p = 2U;
if (LeadVehicle_Detected == 0) {
Adaptive_cruise_control_DW.is_ACC_ON_MODE =
Ada_IN_LeadVehicle_Not_Detected;
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 1U;
} 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: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 4U;
}
}
break;
case IN_LeadVehicle_Detected_Resume:
/* Outport: '/Acceleration_Mode' */
/* Inport: '/Set_Gap' incorporates:
* Inport: '/Set_Speed'
* Inport: '/Time_Gap'
*/
Adaptive_cruise_control_Y.Acceleration_Mode_p = 3U;
if (LeadVehicle_Detected == 0) {
Adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Not_Detected_Res;
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 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_Speed_equal_Set_;
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 5U;
} else {
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: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 2U;
}
}
break;
case Ada_IN_LeadVehicle_Not_Detected:
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 1U;
/* Inport: '/Set_Speed' incorporates:
* Inport: '/Set_Gap'
* Inport: '/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: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 4U;
} else {
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: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 2U;
}
}
break;
case IN_LeadVehicle_Not_Detected_Res:
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 1U;
break;
case IN_LeadVehicle_Speed_equal_Set_:
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 5U;
/* Inport: '/Set_Speed' incorporates:
* Inport: '/Set_Gap'
* Inport: '/Time_Gap'
*/
if ((LeadVehicle_Detected == 0) || (DriveVehicle_Speed <= Set_Speed)) {
Adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Not_Detected_Res;
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 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: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 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: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 4U;
}
}
break;
default:
/* Outport: '/Acceleration_Mode' */
/* case IN_LeadVehicle_Speed_lessthan_Set_Speed: */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 4U;
/* Inport: '/Set_Speed' */
if ((LeadVehicle_Detected == 0) && (DriveVehicle_Speed == Set_Speed)) {
Adaptive_cruise_control_DW.is_ACC_ON_MODE =
Ada_IN_LeadVehicle_Not_Detected;
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 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))) {
Adaptive_cruise_control_DW.is_ACC_ON_MODE =
IN_LeadVehicle_Speed_equal_Set_;
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 5U;
}
}
break;
}
}
/* End of Inport: '/CruiseSwitch' */
}
/* Model step function */
void Adaptive_cruise_control_step(void)
{
/* SignalConversion: '/Signal Conversion' incorporates:
* Inport: '/RadarInput_DriveVehicle'
*/
LeadVehicle_Detected = RadarInput_DriveVehicle;
/* UnitDelay: '/Unit_Delay' */
Acceleration_Mode = Adaptive_cruise_control_DW.Unit_Delay_DSTATE;
/* Sum: '/Add' incorporates:
* Inport: '/CameraInput_DriveVehicle '
* Inport: '/RadarInput_DriveVehicle'
*/
DriveVehicle_Speed = (uint8_T)((uint32_T)(uint8_T)((uint32_T)Acceleration_Mode
+ CameraInput_DriveVehicle) + RadarInput_DriveVehicle);
/* Sum: '/Add' incorporates:
* Inport: '/CameraInput_LeadVehicle'
* Inport: '/RadarInput_LeadVehicle'
*/
LeadVehicle_Speed = (uint8_T)((uint32_T)CameraInput_LeadVehicle +
RadarInput_LeadVehicle);
/* Chart: '/ACC_Logic' incorporates:
* Inport: '/CruiseSwitch'
* Inport: '/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: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 0U;
} else {
switch (Adaptive_cruise_control_DW.is_c3_Adaptive_cruise_control) {
case Adaptive_cruise_IN_ACC_OFF_MODE:
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 0U;
if (CruiseSwitch) {
Adaptive_cruise_control_DW.is_c3_Adaptive_cruise_control =
Adaptive_cr_IN_ACC_STANDBY_MODE;
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 1U;
}
break;
case Adaptive_cruise__IN_ACC_ON_MODE:
Adaptive_cruise_con_ACC_ON_MODE();
break;
default:
/* Outport: '/Acceleration_Mode' */
/* case IN_ACC_STANDBY_MODE: */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 1U;
if (!CruiseSwitch) {
Adaptive_cruise_control_DW.is_c3_Adaptive_cruise_control =
Adaptive_cruise_IN_ACC_OFF_MODE;
/* Outport: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 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: '/Acceleration_Mode' */
Adaptive_cruise_control_Y.Acceleration_Mode_p = 2U;
}
}
break;
}
}
/* End of Chart: '/ACC_Logic' */
/* Update for UnitDelay: '/Unit_Delay' incorporates:
* Outport: '/Acceleration_Mode'
*/
Adaptive_cruise_control_DW.Unit_Delay_DSTATE =
Adaptive_cruise_control_Y.Acceleration_Mode_p;
}
/* 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]
*/
ert main.C:
/*
* File: ert_main.c
*
* Code generated for Simulink model 'Adaptive_cruise_control'.
*
* Model version : 1.30
* Simulink Coder version : 9.3 (R2020a) 18-Nov-2019
* C/C++ source code generated on : Mon Jun 27 10:41:47 2022
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include
#include /* This ert_main.c example uses printf/fflush */
#include "Adaptive_cruise_control.h" /* Model's header file */
#include "rtwtypes.h"
/*
* Associating rt_OneStep with a real-time clock or interrupt service routine
* is what makes the generated code "real-time". The function rt_OneStep is
* always associated with the base rate of the model. Subrates are managed
* by the base rate from inside the generated code. Enabling/disabling
* interrupts and floating point context switches are target specific. This
* example code indicates where these should take place relative to executing
* the generated code step function. Overrun behavior should be tailored to
* your application needs. This example simply sets an error status in the
* real-time model and returns from rt_OneStep.
*/
void rt_OneStep(void);
void rt_OneStep(void)
{
static boolean_T OverrunFlag = false;
/* Disable interrupts here */
/* Check for overrun */
if (OverrunFlag) {
rtmSetErrorStatus(Adaptive_cruise_control_M, "Overrun");
return;
}
OverrunFlag = true;
/* Save FPU context here (if necessary) */
/* Re-enable timer or interrupt here */
/* Set model inputs here */
/* Step the model */
Adaptive_cruise_control_step();
/* Get model outputs here */
/* Indicate task complete */
OverrunFlag = false;
/* Disable interrupts here */
/* Restore FPU context here (if necessary) */
/* Enable interrupts here */
}
/*
* The example "main" function illustrates what is required by your
* application code to initialize, execute, and terminate the generated code.
* Attaching rt_OneStep to a real-time clock is target specific. This example
* illustrates how you do this relative to initializing the model.
*/
int_T main(int_T argc, const char *argv[])
{
/* Unused arguments */
(void)(argc);
(void)(argv);
/* Initialize model */
Adaptive_cruise_control_initialize();
/* Attach rt_OneStep to a timer or interrupt service routine with
* period 0.01 seconds (the model's base sample time) here. The
* call syntax for rt_OneStep is
*
* rt_OneStep();
*/
printf("Warning: The simulation will run forever. "
"Generated ERT main won't simulate model step behavior. "
"To change this behavior select the 'MAT-file logging' option.\n");
fflush((NULL));
while (rtmGetErrorStatus(Adaptive_cruise_control_M) == (NULL)) {
/* Perform other application tasks here */
}
/* Disable rt_OneStep() here */
/* Terminate model */
Adaptive_cruise_control_terminate();
return 0;
}
/*
* File trailer for generated code.
*
* [EOF]
*/
CONCLUSION:
Adaptive Cruise Control has been Created successfully by using the matlab.