Challenge

Project 2 Adaptive Cruise Control

Adaptive cruise control (ACC) is an available cruise control advanced driver-assistance system for road vehicles that automatically adjusts the vehicle speed to maintain a safe distance from vehicles ahead. As of 2019, it is also called by 20 unique names that describe that basic functionality. This is also known as Dynamic cruise control.[1]

Control is based on sensor information from on-board sensors. Such systems may use a radar or laser sensor or a camera setup allowing the vehicle to brake when it detects the car is approaching another vehicle ahead, then accelerate when traffic allows it to.

ACC technology is regarded as a key component of future generations of intelligent cars. The technology enhances passenger safety and convenience as well as increasing road capacity by maintaining optimal separation between vehicles and reducing driver errors. Vehicles with autonomous cruise control are considered a Level 1 autonomous car, as defined by SAE International.[2] When combined with another driver assist feature such as lane centering, the vehicle is considered a Level 2 autonomous car.

Adaptive cruise control does not provide full autonomy: the system only provides some help to the driver, but does not drive the car by itself

ADAS-advanced drive assistance system

MODEL DEVLOPMENT AS PER THE REQUIRMENT :

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.

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.

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_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)]

TAGGING FOR ALL REQUIRMENTS :

REQUIRMENT 2 TAGGING :

REQUIRMENT 3 TAGGING

MODEL ADVISOR REPORT

CODE GENERATION WE HAVE TO CHANGE THE MODEL SETTING :

CODE GENERATION:

File: main_project.c

1 /*
2 * File: main_project.c
3 *
4 * Code generated for Simulink model 'main_project'.
5 *
6 * Model version : 1.10
7 * Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
8 * C/C++ source code generated on : Mon Aug 22 00:46:47 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 "main_project.h"
17 #include "main_project_private.h"
18
19 /* Named constants for Chart: '<S4>/Chart' */
20 #define IN_LeadVehicle_Detected_Follow ((uint8_T)1U)
21 #define IN_LeadVehicle_Detected_Resume ((uint8_T)2U)
22 #define IN_LeadVehicle_Not_Detected_Res ((uint8_T)4U)
23 #define IN_LeadVehicle_Speed_equal_Set_ ((uint8_T)5U)
24 #define IN_LeadVehicle_Speed_lessthan_S ((uint8_T)6U)
25 #define mai_IN_LeadVehicle_Not_Detected ((uint8_T)3U)
26 #define main_projec_IN_ACC_STANDBY_MODE ((uint8_T)3U)
27 #define main_project_IN_ACC_OFF_MODE ((uint8_T)1U)
28 #define main_project_IN_ACC_ON_MODE ((uint8_T)2U)
29
30 /* Exported data definition */
31
32 /* Definition for custom storage class: ExportToFile */
33 uint8_T Acceleration_Mode; /* '<Root>/Inport9' */
34 uint8_T LeadVehicle_Speed; /* '<S3>/Add' */
35
36 /* Block states (default storage) */
37 DW_main_project_T main_project_DW;
38
39 /* External inputs (root inport signals with default storage) */
40 ExtU_main_project_T main_project_U;
41
42 /* External outputs (root outports fed by signals with default storage) */
43 ExtY_main_project_T main_project_Y;
44
45 /* Real-time model */
46 static RT_MODEL_main_project_T main_project_M_;
47 RT_MODEL_main_project_T *const main_project_M = &main_project_M_;
48 real_T rt_roundd_snf(real_T u)
49 {
50 real_T y;
51 if (fabs(u) < 4.503599627370496E+15) {
52 if (u >= 0.5) {
53 y = floor(u + 0.5);
54 } else if (u > -0.5) {
55 y = u * 0.0;
56 } else {
57 y = ceil(u - 0.5);
58 }
59 } else {
60 y = u;
61 }
62
63 return y;
64 }
65
66 /* Model step function */
67 void main_project_step(void)
68 {
69 int32_T tmp;
70 uint8_T rtb_Add1;
71 uint8_T tmp_0;
72
73 /* Sum: '<S2>/Add1' incorporates:
74 * Inport: '<Root>/Inport'
75 * Inport: '<Root>/Inport1'
76 * Sum: '<S2>/Add'
77 * UnitDelay: '<S1>/Unit Delay'
78 */
79 rtb_Add1 = (uint8_T)((uint32_T)(uint8_T)((uint32_T)CameraInput_DriveVehicle +
80 RadarInput_DriveVehicle) + main_project_Y.Outport2);
81
82 /* Sum: '<S3>/Add' incorporates:
83 * Inport: '<Root>/Inport2'
84 * Inport: '<Root>/Inport3'
85 */
86 LeadVehicle_Speed = (uint8_T)((uint32_T)CameraInput_LeadVehicle +
87 RadarInput_LeadVehicle);
88
89 /* Chart: '<S4>/Chart' incorporates:
90 * Inport: '<Root>/Inport1'
91 * Inport: '<Root>/Inport4'
92 * Inport: '<Root>/Inport5'
93 * Inport: '<Root>/Inport6'
94 * Inport: '<Root>/Inport7'
95 * Inport: '<Root>/Inport8'
96 * UnitDelay: '<S1>/Unit Delay'
97 */
98 if (main_project_DW.is_active_c2_main_project == 0U) {
99 main_project_DW.is_active_c2_main_project = 1U;
100 main_project_DW.is_c2_main_project = main_project_IN_ACC_OFF_MODE;
101 main_project_Y.Outport2 = 0U;
102 } else {
103 switch (main_project_DW.is_c2_main_project) {
104 case main_project_IN_ACC_OFF_MODE:
105 main_project_Y.Outport2 = 0U;
106 if (main_project_U.Inport4 == 1.0) {
107 main_project_DW.is_c2_main_project = main_projec_IN_ACC_STANDBY_MODE;
108 main_project_Y.Outport2 = 1U;
109 } else if (main_project_U.Inport8 == 1.0) {
110 main_project_DW.is_c2_main_project = main_project_IN_ACC_ON_MODE;
111 main_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
112 main_project_Y.Outport2 = 2U;
113 }
114 break;
115
116 case main_project_IN_ACC_ON_MODE:
117 switch (main_project_DW.is_ACC_ON_MODE) {
118 case IN_LeadVehicle_Detected_Follow:
119 main_project_Y.Outport2 = 2U;
120 if (((RadarInput_DriveVehicle == 1) && (LeadVehicle_Speed <
121 main_project_U.Inport6)) || (main_project_U.Inport5 <
122 main_project_U.Inport7)) {
123 main_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
124 main_project_Y.Outport2 = 4U;
125 } else if (RadarInput_DriveVehicle == 0) {
126 main_project_DW.is_ACC_ON_MODE = mai_IN_LeadVehicle_Not_Detected;
127 main_project_Y.Outport2 = 1U;
128 }
129 break;
130
131 case IN_LeadVehicle_Detected_Resume:
132 main_project_Y.Outport2 = 3U;
133 if ((rtb_Add1 == main_project_U.Inport6) && (LeadVehicle_Speed >=
134 main_project_U.Inport6) && (main_project_U.Inport5 >=
135 main_project_U.Inport7)) {
136 main_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
137 main_project_Y.Outport2 = 2U;
138 } else if (RadarInput_DriveVehicle == 0) {
139 main_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected_Res;
140 main_project_Y.Outport2 = 1U;
141 }
142 break;
143
144 case mai_IN_LeadVehicle_Not_Detected:
145 main_project_Y.Outport2 = 1U;
146 if ((RadarInput_DriveVehicle == 1) && (rtb_Add1 ==
147 main_project_U.Inport6) && (LeadVehicle_Speed >=
148 main_project_U.Inport6) && (main_project_U.Inport5 >=
149 main_project_U.Inport7)) {
150 main_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;
151 main_project_Y.Outport2 = 2U;
152 } else if (((RadarInput_DriveVehicle == 1) && (LeadVehicle_Speed <
153 main_project_U.Inport6)) || (main_project_U.Inport5 <
154 main_project_U.Inport7) || ((RadarInput_DriveVehicle == 0) &&
155 (rtb_Add1 == main_project_U.Inport6))) {
156 main_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
157 main_project_Y.Outport2 = 4U;
158 }
159 break;
160
161 case IN_LeadVehicle_Not_Detected_Res:
162 main_project_Y.Outport2 = 1U;
163 if ((rtb_Add1 < main_project_U.Inport6) && (LeadVehicle_Speed > rtb_Add1)
164 && (main_project_U.Inport5 >= main_project_U.Inport7)) {
165 main_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_equal_Set_;
166 main_project_Y.Outport2 = 5U;
167 }
168 break;
169
170 case IN_LeadVehicle_Speed_equal_Set_:
171 main_project_Y.Outport2 = 5U;
172 if ((RadarInput_DriveVehicle == 0) || (rtb_Add1 <=
173 main_project_U.Inport6)) {
174 main_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected_Res;
175 main_project_Y.Outport2 = 1U;
176 } else if (((rtb_Add1 < main_project_U.Inport6) && (LeadVehicle_Speed >
177 rtb_Add1)) || (main_project_U.Inport5 >=
178 main_project_U.Inport7)) {
179 main_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Resume;
180 main_project_Y.Outport2 = 3U;
181 } else if (((LeadVehicle_Speed < main_project_U.Inport6) &&
182 (LeadVehicle_Speed < rtb_Add1)) || (0.75 *
183 main_project_U.Inport7 == main_project_U.Inport5)) {
184 main_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;
185 main_project_Y.Outport2 = 4U;
186 }
187 break;
188
189 default:
190 /* case IN_LeadVehicle_Speed_lessthan_Set_Speed: */
191 main_project_Y.Outport2 = 4U;
192 tmp = (int32_T)rt_roundd_snf((real_T)LeadVehicle_Speed * 1.25);
193 if (tmp < 256) {
194 tmp_0 = (uint8_T)tmp;
195 } else {
196 tmp_0 = MAX_uint8_T;
197 }
198
199 if ((tmp_0 >= rtb_Add1) && ((int32_T)rt_roundd_snf((real_T)
200 LeadVehicle_Speed * 0.75) <= rtb_Add1) && (rtb_Add1 <
201 main_project_U.Inport6) && (main_project_U.Inport5 <= 1.25 *
202 main_project_U.Inport7) && (main_project_U.Inport5 >= 0.75 *
203 main_project_U.Inport7)) {
204 main_project_DW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_equal_Set_;
205 main_project_Y.Outport2 = 5U;
206 }
207 break;
208 }
209 break;
210
211 default:
212 /* case IN_ACC_STANDBY_MODE: */
213 main_project_Y.Outport2 = 1U;
214 if (main_project_U.Inport4 == 0.0) {
215 main_project_DW.is_c2_main_project = main_project_IN_ACC_OFF_MODE;
216 main_project_Y.Outport2 = 0U;
217 }
218 break;
219 }
220 }
221
222 /* End of Chart: '<S4>/Chart' */
223 }
224
225 /* Model initialize function */
226 void main_project_initialize(void)
227 {
228 /* (no initialization code required) */
229 }
230
231 /* Model terminate function */
232 void main_project_terminate(void)
233 {
234 /* (no terminate code required) */
235 }
236
237 /*
238 * File trailer for generated code.
239 *
240 * [EOF]
241 */
242
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.