Project 2 Adaptive Cruise Control
Objective of Main Project:
- 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
Step1:
Create a sldd file according to the data given in question.
modeling > link to data dictionary > new( create new sldd file)
then access the sldd file from modeling> model explorer>Adaptive_cruise_control> expand external data> design data( input signal and parameters there)
|
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 |
- |
- |
Step2:
DEVELOPMENT OF ADAPTIVE CRUISE CONTROL SIMULINK MODEL:
Adaptive_Cruise_Control_Mode subsystem consist of three requirement subsystems,
Lead vehicle subsystem(Requirement_1),Drive vehicle subsystem(Requirement_2) & Adaptive Cruise Control subsystem(Requirement_3).
Step3:
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.
Step4:
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.
Step5:
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 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.
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
- LeadVehicle_Speed_equal_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>
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>
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> 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 Time_Gap<=1.25*Set_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> 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
Step1:
SLdd File Creation from link to data dictonary option
Requirment 3 Model Diagram:
Model Operation StateFlow Chart
Symbol pane:
Step6:
The next step is solve signals and propagate them.
for signal resolve : select signal>right click signal > properties >signal name >check signal name
must resolve to simulink object>ok
Step7:
propogation of signal
select signal>right click signal > properties > check show propogated signals >ok
Step8:
Tagging of the system
select Lead_Vehicle(Requirement_1) subsystem right-clicks> requirements > link to selection in word
then
word file and information will be open of that subsystem. if we click on it
same do for remaining Drive vehicle subsystem(Requirement_2) & Adaptive Cruise Control subsystem(Requirement_3).
Drive vehicle subsystem(Requirement_2) Tagging:
Adaptive Cruise Control subsystem(Requirement_3) Tagging:
Step9:
Now from model setting> solver configuration> type-fixed-step >solver- discrete solver>stepsize= 0.01seconds.
for code generation
code generation>system target file >ert.tlc embedded codder.
Step10:
got to model advisor check>by task>ony check modelling standards with MAB>Run selected checks
Step11:
generate model advisor report,In 2023a There is seperate export symbol is present to export report and it can convert the output into word,pdf,Docx format.
Report:
Step12:
generate code for model:
apps> embedded coder>generate code
Embedded C-Code:
/*
* Event Support License -- for demonstration use and event support. Not
* for government, research, commercial, or other organizational use.
*
* File: Adaptive_cruise_Control_Project.c
*
* Code generated for Simulink model 'Adaptive_cruise_Control_Project'.
*
* Model version : 1.49
* Simulink Coder version : 9.9 (R2023a) 19-Nov-2022
* C/C++ source code generated on : Thu Sep 21 19:03:45 2023
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "Adaptive_cruise_Control_Project.h"
#include "rtwtypes.h"
#include "Adaptive_cruise_Control_Project_private.h"
#include <math.h>
#include "LeadVehicle_Speed.h"
#include "Acceleration_Mode.h"
#include "DriveVehicle_Speed.h"
#include "LeadVehicle_Detected.h"
/* Named constants for Chart: '/Modes_operation' */
#define Adaptive_cr_IN_ACC_STANDBY_MODE ((uint8_T)3U)
#define Adaptive_cruise_IN_ACC_OFF_MODE ((uint8_T)1U)
#define Adaptive_cruise__IN_ACC_ON_MODE ((uint8_T)2U)
/* Block states (default storage) */
DW_Adaptive_cruise_Control_Pr_T Adaptive_cruise_Control_Proj_DW;
/* External outputs (root outports fed by signals with default storage) */
ExtY_Adaptive_cruise_Control__T Adaptive_cruise_Control_Proje_Y;
/* Real-time model */
static RT_MODEL_Adaptive_cruise_Cont_T Adaptive_cruise_Control_Proj_M_;
RT_MODEL_Adaptive_cruise_Cont_T *const Adaptive_cruise_Control_Proj_M =
&Adaptive_cruise_Control_Proj_M_;
/* Forward declaration for local functions */
static void LeadVehicle_Speed_equal_Set_Spe(void);
static void Adapti_LeadVehicle_Not_Detected(void);
static void Adaptive_cruise_Con_ACC_ON_MODE(void);
real_T rt_roundd_snf(real_T u)
{
real_T y;
if (fabs(u) < 4>= 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: '/Modes_operation' */
static void LeadVehicle_Speed_equal_Set_Spe(void)
{
/* Inport: '/Set_Speed' incorporates:
* Inport: '/Set_Gap'
* Inport: '/Time_Gap'
*/
if ((LeadVehicle_Detected == 0) || (DriveVehicle_Speed <= Set_Speed)) {
/* Update for Outport: '/Acceleration_Mode' */
Adaptive_cruise_Control_Proje_Y.Acceleration_Mode_j = 3U;
} else if (((DriveVehicle_Speed < Set>
DriveVehicle_Speed)) || (Time_Gap >= Set_Gap)) {
/* Update for Outport: '/Acceleration_Mode' */
Adaptive_cruise_Control_Proje_Y.Acceleration_Mode_j = 3U;
} else if (((LeadVehicle_Speed < Set xss=removed>/Acceleration_Mode' */
Adaptive_cruise_Control_Proje_Y.Acceleration_Mode_j = 3U;
}
/* End of Inport: '/Set_Speed' */
}
/* Function for Chart: '/Modes_operation' */
static void Adapti_LeadVehicle_Not_Detected(void)
{
/* Update for Outport: '/Acceleration_Mode' */
Adaptive_cruise_Control_Proje_Y.Acceleration_Mode_j = 3U;
}
/* Function for Chart: '/Modes_operation' */
static void Adaptive_cruise_Con_ACC_ON_MODE(void)
{
/* Inport: '/SetSwitch' */
if (SetSwitch) {
Adaptive_cruise_Control_Proj_DW.is_c1_Adaptive_cruise_Control_P =
Adaptive_cr_IN_ACC_STANDBY_MODE;
/* Update for Outport: '/Acceleration_Mode' */
Adaptive_cruise_Control_Proje_Y.Acceleration_Mode_j = 1U;
} else {
LeadVehicle_Speed_equal_Set_Spe();
Adapti_LeadVehicle_Not_Detected();
/* Inport: '/Set_Speed' incorporates:
* Inport: '/Set_Gap'
* Inport: '/Time_Gap'
*/
if ((DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >= Set_Speed) &&
(Time_Gap >= Set_Gap)) {
/* Update for Outport: '/Acceleration_Mode' */
Adaptive_cruise_Control_Proje_Y.Acceleration_Mode_j = 3U;
} else if ((DriveVehicle_Speed < Set>
DriveVehicle_Speed) && (Time_Gap >= Set_Gap)) {
/* Update for Outport: '/Acceleration_Mode' */
Adaptive_cruise_Control_Proje_Y.Acceleration_Mode_j = 3U;
} else if (LeadVehicle_Detected == 0) {
/* Update for Outport: '/Acceleration_Mode' */
Adaptive_cruise_Control_Proje_Y.Acceleration_Mode_j = 3U;
}
/* End of Inport: '/Set_Speed' */
}
/* End of Inport: '/SetSwitch' */
}
/* Model step function */
void Adaptive_cruise_Control_Project_step(void)
{
/* Sum: '/add' incorporates:
* Inport: '/CameraInput_LeadVehicle'
* Inport: '/RadarInput_LeadVehicle'
*/
LeadVehicle_Speed = (uint8_T)(CameraInput_LeadVehicle + RadarInput_LeadVehicle);
/* UnitDelay: '/unit _delay' */
Acceleration_Mode = Adaptive_cruise_Control_Proj_DW.unit_delay_DSTATE;
/* Sum: '/Add' incorporates:
* Inport: '/CameraInput_DriveVehicle'
* Inport: '/RadarInput_DriveVehicle'
*/
DriveVehicle_Speed = (uint8_T)((uint8_T)(CameraInput_DriveVehicle +
RadarInput_DriveVehicle) + Acceleration_Mode);
/* SignalConversion: '/Signal_Conversion' incorporates:
* Inport: '/RadarInput_DriveVehicle'
*/
LeadVehicle_Detected = RadarInput_DriveVehicle;
/* Chart: '/Modes_operation' incorporates:
* Inport: '/CruiseSwitch'
has popup
CONCLUSION:
Hence we Developed Adaptive Cruise Control feature as per the Requirement Document using MATLAB Simulink
Note:The model file,Requirement tagging file,SLDD file,.c and .h file,Model advisor report were attached below.