Project 2 Adaptive Cruise Control
AIM:
To develop the Adaptive Cruise Control feature as per the Requirement Document using MATLAB Simulink
General Overview:
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 from 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.
The objective of the Main Project:
- Developing Adaptive Cruise Control feature as per the Requirement Document using MATLAB Simulink.
- To follow all the MBD-related processes: Requirement Tagging & Traceability, SLDD creation, Configuration Parameter changes, Model Advisor check & Code Generation.
- To use Embedded Coder to generate the code
- Choose sample time for all signals as 0.01s
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 |
- |
- |
CREATION OF SIMULINK DATA DICTIONARY (SLDD FILE)
We need to check all the data variables[Signals/constants/etc] of the model whose values should be loaded in the workspace for simulation.
The data variables can be loaded in the workspace either by an M-script file or by using an SLDD file. Here we are creating an SLDD file to store the data variables for simulation.
STEPS TO CREATE A SLDD FILE:
Go to Link to Data dictionary>> New>> Uncheck Enable to access to base workspace>> Apply.


Now name the SLDD file and save it on the desktop in the same path where the given model is stored.

Open Model Explorer, under the model file, expand External data, and there we can find the SLLD file which we have created.
In this case, they have given the required signals and Calibration Data List.

Under Design Data, Enter all the given signals.
The Storage class for Input signals will be ImportedExtern; Storage class for Output signal: Export to File; Storage class for local signals: localizable; Storage class for calibration signals: Const.

Hence we have loaded all the required data in an SLDD file. Now right click on the SLDD file and select save changes so that the loaded data will be stored in the file.
DEVELOPMENT OF THE SIMULINK MODEL:
The main subsystem Adaptive_Cruise_control has CameraInput_LeadVehicle, RadarInput_LeadVehicle, LeadVehicle_Speed, CameraInput_DriveVehicle, RadarInput_DriveVehicle,Time_Gap, Set_Speed, Set_Gap, CruiseSwitch, SetSwitch as an inputs and Acceleration_Mode as an output which is shown below;

The main subsystem is divided into three more subsystems which are Lead_Vehicle, Drive_Vehicle, and ACC_Algorithm

Requirement 1– Lead Vehicle:
- Lead Vehicle is a vehicle that is driving on 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 cameras & 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.

Requirement 2 – Drive Vehicle:
- Drive Vehicle is the vehicle driven by the user & this is the vehicle that has an ACC algorithm in it.
- Like the Lead Vehicle, the Driver 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 the summation of three input signals mentioned above & LeadVehicle_Detected is renamed from Input Signal RadarInput_DriveVehicle by mere use of Signal Conversion block.

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 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) that 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:
- 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 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 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 substate inside the 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 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)]<="" em=""></set_speed)>

The ACC_logic has been created using a state flow chart, by using symbols pane options under modeling we can select the required and outputs from the subsystem.


SIGNAL PROPAGATING AND RESOLVING:
Select the signal which is propagating first from one block to another, Right click>> Go to properties

Select the signal name which is already pre-defined in the SLDD and check for 'Signal name must resolve to Simulink signal object and apply.

For the signal to resolve, just double click on the extended signal from the origin block to the destination block and enter '<>'


When the signal begins/evolves from a block we need to propagate and the destination signal link should be resolved.
REQUIREMENT TAGGING:
We need our data input file either in Word/Excel/pdf file etc which should be open outside the MATLAB.
For the requirement tagging of a subsystem or any blocks, we need to select the particular requirements/input data in the excel

Now select the substem, Right click>> Requirements>> select Link to Selection to word

Now click on the Requirement which we have selected


Similarly, we have done the requirement tagging for the remaining subsystem as well.


There we have done all the requirement tagging for our model.

PRE-SOLVER SETTING:
The type of the solver we are using for model simulation is of a fixed step and the solver is discrete with a step size of 0.01
Under Modeling>>select>> Model settings>> Double click on Solver


CODE GENERATION SETTING:
The type of the solver we are using for model simulation is of a fixed step and the solver is discrete with a step size of 0.01
Under Modeling>>select>> Model settings>> Double click on Code Generation>> Browse and select Embedded Coder


MAB GUIDELINES:
The MAB (MathWorks Advisory Board) Guidelines are a set of modeling guidelines developed by an industry working group for the independent usage of MATLAB, Simulink, Stateflow, and Embedded Coder. The culmination of guidelines is the years of engineering expertise and best practices for developing, maintaining, and controlling algorithm models used in the documenting development of production software.
To perform the MAB guidelines test on our Simulink model, go which is at to the modeling section and select Model Advisor in the top left corner of the window.
We can use the Model Advisor to verify compliance of our model with the MathWorks Advisory Board guidelines. Below is the procedure.
After checking the model without any errors, Under simulation >> go to the Model Advisor icon


Select By Task and check only Modeling Standards for MAB.

Click on run and now the model is checking whether all the guidelines have been followed while modeling

Now a report has been created with all pass checks and stored in an HTML file in our folder.

THE FINAL STEP IS THE CODE GENERATION:
The first step of configuring a model for code generation is to choose & configure a code generation target.
When you select a target, other model configuration parameters change automatically.
Parameters such as code interface parameters, build process parameters, and target hardware parameters change automatically.
System Target File (TLC) -ert.tlc Contains pre-configured settings for the code format, target type, coding language, and other software build environment code generation settings.
Model Files:
Model.c Contains the entry point for the algorithm
Model.h Declares the model data structures
Model_private.h Contains local macros & data required by your model
Model_types.h Provides type definitions for user-defined types in the model.
After the SIL test,
Click on APPS>> BUILD icon from Simulink icons tray


we get a generated CODE report for the model.

A subsystem folder has been created and we can find a separate C- code file for the subsystem and the files are automatically loaded in our model folder.
The generated C - code for the model has been attached below.
File: ACCmodel.c
1 /*
2 * File: ACCmodel.c
3 *
4 * Code generated for Simulink model 'ACCmodel'.
5 *
6 * Model version : 1.16
7 * Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
8 * C/C++ source code generated on : Fri May 27 17:51:29 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #include "ACCmodel.h"
17 #include "ACCmodel_private.h"
18
19 /* Named constants for Chart: '<S2>/ACC_Logic' */
20 #define ACC_IN_LeadVehicle_Not_Detected ((uint8_T)3U)
21 #define ACCmodel_IN_ACC_OFF_MODE ((uint8_T)1U)
22 #define ACCmodel_IN_ACC_ON_MODE ((uint8_T)2U)
23 #define ACCmodel_IN_ACC_STANDBY_MODE ((uint8_T)3U)
24 #define ACCmodel_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
25 #define IN_LeadVehicle_Detected_Follow ((uint8_T)1U)
26 #define IN_LeadVehicle_Detected_Resume ((uint8_T)2U)
27 #define IN_LeadVehicle_Not_Detected_Res ((uint8_T)4U)
28 #define IN_LeadVehicle_Speed_equal_Set_ ((uint8_T)5U)
29 #define IN_LeadVehicle_Speed_lessthan_S ((uint8_T)6U)
30
31 /* Exported data definition */
32
33 /* Definition for custom storage class: ExportToFile */
34 uint8_T Acceleration_Mode; /* '<S1>/Unit Delay' */
35
36 /* Block states (default storage) */
37 DW_ACCmodel_T ACCmodel_DW;
38
39 /* External outputs (root outports fed by signals with default storage) */
40 ExtY_ACCmodel_T ACCmodel_Y;
41
42 /* Real-time model */
43 static RT_MODEL_ACCmodel_T ACCmodel_M_;
44 RT_MODEL_ACCmodel_T *const ACCmodel_M = &ACCmodel_M_;
45 real_T rt_roundd_snf(real_T u)
46 {
47 real_T y;
48 if (fabs(u) < 4.503599627370496E+15) {
49 if (u >= 0.5) {
50 y = floor(u + 0.5);
51 } else if (u > -0.5) {
52 y = u * 0.0;
53 } else {
54 y = ceil(u - 0.5);
55 }
56 } else {
57 y = u;
58 }
59
60 return y;
61 }
62
63 /* Model step function */
64 void ACCmodel_step(void)
65 {
66 /* local block i/o variables */
67 uint8_T LeadVehicle_Speed;
68 uint8_T DriveVehicle_Speed;
69 uint8_T LeadVehicle_Detected;
70 int32_T tmp;
71 int32_T tmp_0;
72 uint8_T tmp_1;
73 uint8_T tmp_2;
74
75 /* Sum: '<S4>/Add' incorporates:
76 * Inport: '<Root>/CameraInput_LeadVehicle '
77 * Inport: '<Root>/RadarInput_LeadVehicle'
78 */
79 LeadVehicle_Speed = (uint8_T)((uint32_T)CameraInput_LeadVehicle +
80 RadarInput_LeadVehicle);
81
82 /* UnitDelay: '<S1>/Unit Delay' */
83 Acceleration_Mode = ACCmodel_Y.Acceleration_Mode_f;
84
85 /* Sum: '<S3>/Add' incorporates:
86 * Inport: '<Root>/CameraInput_DriveVehicle'
87 * Inport: '<Root>/RadarInput_DriveVehicle'
88 */
89 DriveVehicle_Speed = (uint8_T)((uint32_T)(uint8_T)((uint32_T)
90 CameraInput_DriveVehicle + Acceleration_Mode) + RadarInput_DriveVehicle);
91
92 /* SignalConversion: '<S3>/Signal Conversion' incorporates:
93 * Inport: '<Root>/RadarInput_DriveVehicle'
94 */
95 LeadVehicle_Detected = RadarInput_DriveVehicle;
96
97 /* Chart: '<S2>/ACC_Logic' incorporates:
98 * Inport: '<Root>/CruiseSwitch'
99 * Inport: '<Root>/SetSwitch'
100 * Inport: '<Root>/Set_Gap'
101 * Inport: '<Root>/Set_Speed'
102 * Inport: '<Root>/Time_Gap'
103 * UnitDelay: '<S1>/Unit Delay'
104 */
105 if (ACCmodel_DW.is_active_c3_ACCmodel == 0U) {
106 ACCmodel_DW.is_active_c3_ACCmodel = 1U;
107 ACCmodel_DW.is_c3_ACCmodel = ACCmodel_IN_ACC_OFF_MODE;
108 ACCmodel_Y.Acceleration_Mode_f = 0U;
109 } else {
110 switch (ACCmodel_DW.is_c3_ACCmodel) {
111 case ACCmodel_IN_ACC_OFF_MODE:
112 ACCmodel_Y.Acceleration_Mode_f = 0U;
113 if (CruiseSwitch) {
114 ACCmodel_DW.is_c3_ACCmodel = ACCmodel_IN_ACC_STANDBY_MODE;
115 ACCmodel_Y.Acceleration_Mode_f = 1U;
116 }
117 break;
118
119 case ACCmodel_IN_ACC_ON_MODE:
120 if (!CruiseSwitch) {
121 ACCmodel_DW.is_ACC_ON_MODE = ACCmodel_IN_NO_ACTIVE_CHILD;
122 ACCmodel_DW.is_c3_ACCmodel = ACCmodel_IN_ACC_OFF_MODE;
123 ACCmodel_Y.Acceleration_Mode_f = 0U;
124 } else if (!SetSwitch) {
125 ACCmodel_DW.is_ACC_ON_MODE = ACCmodel_IN_NO_ACTIVE_CHILD;
126 ACCmodel_DW.is_c3_ACCmodel = ACCmodel_IN_ACC_STANDBY_MODE;
127 ACCmodel_Y.Acceleration_Mode_f = 1U;
128 } else {
129 switch (ACCmodel_DW.is_ACC_ON_MODE) {
130 case IN_LeadVehicle_Detected_Follow:
131 ACCmodel_Y.Acceleration_Mode_f = 2U;
132 if (LeadVehicle_Detected == 0) {
133 ACCmodel_DW.is_ACC_ON_MODE = ACC_IN_LeadVehicle_Not_Detected;
134 ACCmodel_Y.Acceleration_Mode_f = 1U;
135 } else if (((LeadVehicle_Detected == 1) && (LeadVehicle_Speed <
136 Set_Speed)) || (Time_Gap < Set_Gap)) {
137 ACCmodel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
138 ACCmodel_Y.Acceleration_Mode_f = 4U;
139 }
140 break;
141
142 case IN_LeadVehicle_Detected_Resume:
143 ACCmodel_Y.Acceleration_Mode_f = 3U;
144 if ((DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >=
145 Set_Speed) && (Time_Gap >= Set_Gap)) {
146 ACCmodel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
147 ACCmodel_Y.Acceleration_Mode_f = 2U;
148 } else if ((DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed >
149 DriveVehicle_Speed) && (Time_Gap >= Set_Gap)) {
150 ACCmodel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_equal_Set_;
151 ACCmodel_Y.Acceleration_Mode_f = 5U;
152 } else if (LeadVehicle_Detected == 0) {
153 ACCmodel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected_Res;
154 ACCmodel_Y.Acceleration_Mode_f = 1U;
155 }
156 break;
157
158 case ACC_IN_LeadVehicle_Not_Detected:
159 ACCmodel_Y.Acceleration_Mode_f = 1U;
160 if ((LeadVehicle_Detected == 1) && (DriveVehicle_Speed == Set_Speed) &&
161 (LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)) {
162 ACCmodel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
163 ACCmodel_Y.Acceleration_Mode_f = 2U;
164 } else if (((LeadVehicle_Detected == 1) && (LeadVehicle_Speed <
165 Set_Speed)) || (Time_Gap < Set_Gap)) {
166 ACCmodel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
167 ACCmodel_Y.Acceleration_Mode_f = 4U;
168 }
169 break;
170
171 case IN_LeadVehicle_Not_Detected_Res:
172 ACCmodel_Y.Acceleration_Mode_f = 1U;
173 break;
174
175 case IN_LeadVehicle_Speed_equal_Set_:
176 ACCmodel_Y.Acceleration_Mode_f = 5U;
177 if (((LeadVehicle_Speed < Set_Speed) && (LeadVehicle_Speed <
178 DriveVehicle_Speed)) || ((int32_T)rt_roundd_snf(0.75 * (real_T)
179 Set_Gap) == Time_Gap)) {
180 ACCmodel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
181 ACCmodel_Y.Acceleration_Mode_f = 4U;
182 } else if (((DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed >
183 DriveVehicle_Speed)) || (Time_Gap >= Set_Gap)) {
184 ACCmodel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Resume;
185 ACCmodel_Y.Acceleration_Mode_f = 3U;
186 } else if ((LeadVehicle_Detected == 0) || (DriveVehicle_Speed <=
187 Set_Speed)) {
188 ACCmodel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected_Res;
189 ACCmodel_Y.Acceleration_Mode_f = 1U;
190 }
191 break;
192
193 default:
194 /* case IN_LeadVehicle_Speed_lessthan_Set_Speed: */
195 ACCmodel_Y.Acceleration_Mode_f = 4U;
196 if ((LeadVehicle_Detected == 0) && (DriveVehicle_Speed == Set_Speed))
197 {
198 ACCmodel_DW.is_ACC_ON_MODE = ACC_IN_LeadVehicle_Not_Detected;
199 ACCmodel_Y.Acceleration_Mode_f = 1U;
200 } else {
201 tmp = (int32_T)rt_roundd_snf((real_T)LeadVehicle_Speed * 1.25);
202 tmp_0 = (int32_T)rt_roundd_snf(1.25 * (real_T)Set_Gap);
203 if (tmp < 256) {
204 tmp_1 = (uint8_T)tmp;
205 } else {
206 tmp_1 = MAX_uint8_T;
207 }
208
209 if (tmp_0 < 256) {
210 tmp_2 = (uint8_T)tmp_0;
211 } else {
212 tmp_2 = MAX_uint8_T;
213 }
214
215 if ((tmp_1 >= DriveVehicle_Speed) && ((int32_T)rt_roundd_snf((real_T)
216 LeadVehicle_Speed * 0.75) <= DriveVehicle_Speed) &&
217 (DriveVehicle_Speed < Set_Speed) && (Time_Gap <= tmp_2) &&
218 (Time_Gap >= (int32_T)rt_roundd_snf(0.75 * (real_T)Set_Gap))) {
219 ACCmodel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_equal_Set_;
220 ACCmodel_Y.Acceleration_Mode_f = 5U;
221 }
222 }
223 break;
224 }
225 }
226 break;
227
228 default:
229 /* case IN_ACC_STANDBY_MODE: */
230 ACCmodel_Y.Acceleration_Mode_f = 1U;
231 if (!CruiseSwitch) {
232 ACCmodel_DW.is_c3_ACCmodel = ACCmodel_IN_ACC_OFF_MODE;
233 ACCmodel_Y.Acceleration_Mode_f = 0U;
234 } else if (SetSwitch) {
235 ACCmodel_DW.is_c3_ACCmodel = ACCmodel_IN_ACC_ON_MODE;
236 ACCmodel_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
237 ACCmodel_Y.Acceleration_Mode_f = 2U;
238 }
239 break;
240 }
241 }
242
243 /* End of Chart: '<S2>/ACC_Logic' */
244 }
245
246 /* Model initialize function */
247 void ACCmodel_initialize(void)
248 {
249 /* (no initialization code required) */
250 }
251
252 /* Model terminate function */
253 void ACCmodel_terminate(void)
254 {
255 /* (no terminate code required) */
256 }
257
258 /*
259 * File trailer for generated code.
260 *
261 * [EOF]
262 */
263
Hence we have completed the design of the Adaptive cruise control Model also verified as per MAB guidelines and finally generated the C-code of the model.