Project 2 Adaptive Cruise Control
AIM OF PROJECT:
To develop MATLAB Simulink model of Adaptive Cruise Control as per the given requirement document.
MODEL:
(After Model Advisor Run & Removing some Warnings)
Simulink Model Name: ‘ACC.slx’
As we can see this is the base root architecture of our model. It has a subsystem named ‘ACC_Model’ with 9 input signals ‘CameraInput_LeadVehicle’, ‘RadarInput_LeadVehicle’, ‘CameraInput_DriveVehicle’, ‘RadarInput_DriveVehicle’, ‘Time_Gap’, ‘Set_Speed’. ‘Set_Gap’, ‘CruiseSwitch’, and ‘SetSwitch’ and an output signal ‘Acceleration_Mode’, coming from the subsystem.

Inside subsystem ‘ACC_Model’, we have 3 subsystems named ‘Requirement1_LeadVehicle’, ‘Requirement2_DriveVehicle’, and ‘Requirement3_ACC_Algorithm’.
The subsystem ‘Requirement1_LeadVehicle’ has two input signals ‘CameraInput_LeadVehicle’ and ‘RadarInput_LeadVehicle’ coming from the base model and an output signal ‘LeadVehicle_Speed’, which is fed as an input signal to Requirement3_ACC_Algorithm Subsystem.
The subsystem ‘Requirement2_DriveVehicle’ has three input signals ‘CameraInput_DriveVehicle’, ‘RadarInput_DriveVehicle’ and ‘Acceleration_Mode, the output signal of the main model. The output signal for this subsystem is ‘DriveVehicle_Speed’ and LeadVehicle_Detected which are fed as an input signal to Requirement3_ACC_Algorithm Subsystem.
The subsystem ‘Requirement3_ACC_Algorithm’ has 8 input signals, Time_Gap’,‘Set_Speed’,‘Set_Gap’, ‘CruiseSwitch’ and ‘SetSwitch’, ‘LeadVehicle_Speed’ is coming from ‘Requirement1_LeadVehicle’, ‘DriveVehicle_Speed’ and ‘LeadVehicle_Detected’ coming from ‘Requirement2_DriveVehicle’. The output signal for this subsystem is ‘Acceleration_Mode’ which is our output signal of the main model.
These three subsystems are designed according to our Requirement 1, Requirement 2, and Requirement 3 respectively, mentioned in the project.

In ‘Requirement1_LeadVehicle’ subsystem
- Two input signals (Signal Name: CameraInput_LeadVehicle & RadarInput_LeadVehicle).
- Both the radar & camera inputs are added & the corresponding output is read as Speed profile output (Signal Name: LeadVehicle_Speed).

In ‘Requirement2_DriveVehicle’ subsystem
- Two 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.
- Two output signals come from this subsystem (Signal Name: DriveVehicle_Speed & LeadVehicle_Detected).
- Signal DriveVehicle_Speed is the summation of the three input signals mentioned above & LeadVehicle_Detected is renamed from Input Signal RadarInput_DriveVehicle by mere use of the Signal Conversion block.

In ‘Requirement3_ACC_Algorithm’ subsystem
- This requirement is implemented as state machine logic in Simulink using the chart.
- The adaptive Cruise Control feature has 3 major modes of operation: OFF Mode, STANDBY Mode & ON Mode.
- 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 are fed back as an input signal into this state machine block. Additionally, the 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 and automatically adjusts its speed & velocity to match the lead vehicle.

Requirement 3a – ACC OFF MODE state logic:
- The default state inside state machine logic.
- Output signal Acceleration_Mode is at value 0 in this state.
- This state is governed by the 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 the 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 the 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 the ACC ON MODE state.
- Output signal Acceleration_Mode is equal to 2.
- Conditiontotransitfrom 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<Set_Speed) && (LeadVehicle_Speed<DriveVehicle_Speed) || (Time_Gap == 0.75*Set_Gap)].

REQUIREMENT TAGGING & TRACEABILITY :
For tagging the requirements to a specific block, first,, we need to select the lines in our WordPad, then right-click on the Simulink block, select ‘Requirements’, then ‘Link to Selection in Word’.
Here we see that the subsystem ‘Requirement1_LeadVehicle’ containing the model of requirement 1 has been tagged. Similarly for other two requirements can be done.


SIMULINK DATA DICTIONARY
A new Simulink data dictionary for this project is created named ‘acc_dd.sldd’ and is linked to our model ‘ACC.slx’. All the signals and calibration parameters are added according to the below table provided to us in the requirement document.
|
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 |
- |
- |
Also, the Storage class for Input signals: ImportedExtern; the Storage class for Output signals: Export to File; the Storage class for local signals: localizable; the Storage class for calibration signals: Const.
The sample time for all signals is set as 0.01s.

We have taken output signals ‘LeadVehicle_Speed’, ‘DriveVehicle_Speed’, and ‘LeadVehicle_Detected’ as local signals, as they are not our main output signals.
CONFIGURATION SETTINGS:
We need to set and adjust some configuration settings according to different guidelines and requirements documents.


Similarly, we will adjust other parameters.
For the code generation, we need to change our target file to ‘ert.tlc’ from ‘grt.tlc’ for Embedded Coder.

Enabling “Support Floating Numbers” under the Code Generation settings of the Interface block.
Some of the configuration settings are also adjusted after running model advisor to remove some warnings.
MODEL ADVISOR:
We will go to the model advisor in the Modelling [or from APPS] tab to check whether the model follows various guidelines.

This is when the model advisor opens. By default, some task is checked. We can check or uncheck some tasks according to our model requirements.

So we will select MAB Guidelines.

So when the following is selected for checks, we see that although there are no fails we can see some warnings. These same warnings can be looked into and can be adjusted so that warnings number can be reduced.
After making proper warning adjustments, again when we run the task, we see that the warnings count decreases. There are some indexing errors and some naming convention errors which can be taken into account.
GENERATE REPORT:
To generate model advisor reports, click on Generate Report option.

The report generated can be seen above.
BUILDING & CODE GENERATION:
The next task is to build and generate the code of the project. For the same, we will first select Embedded Coder in the APPS tab.

In the C CODE tab, select Build to build the model, and after that Generate Code.

An error will pop up which says ‘Failed to Generate all binary outputs’ can be ignored as we know that the required C file takes some time to generate.

The .c file can be seen here in the above screenshot.

Code Generation Report for our model ‘ACC.slx’
