Challenge

Project 2 Adaptive Cruise Control

ADAPTIVE CRUISE CONTROL(ACC):
 
Adaptive cruise control (ACC) is an active safety system that automatically controls the acceleration and braking of a vehicle. It is activated through a button on the steering wheel and cancelled by driver’s braking and/or another button.
Even the biggest car enthusiasts have journeys they wish to be chauffeured through, or at least supported in a way that makes them relax behind the wheel after a long and stressful day. If, while doing so, their driving experience becomes safer and more thrilling while saving on fuel, even better. This, at its core, is the main reason behind cruise control technology. While already two decades old, cruise control adoption continues to grow and support drivers during more and more stages of their journeys.
 
How adaptive cruise control works

By monitoring other vehicles and objects on the road, adaptive cruise control enables a safe and comfortable driving experience. It does so by helping the driver keep a steady vehicle speed at a given moment. The driver can set their preference regarding certain factors, such as the distance to the car in front, driving mode – for example, economical, sporty or comfortable – and others. Together with information about speed limits, road curvature, accidents data and more, these choices influence the automatically selected speed.

Cruise control has come a long way from its early days in its quest to assist drivers on the road. When first introduced, it was only found in luxury car models due to its high production cost. As less expensive sensors reached the market, adaptive cruise control is steadily becoming a standard feature in new vehicles today.

daptive cruise control (ACC) is a system designed to help vehicles maintain a safe following distance and stay within the speed limit. This system adjusts a car's speed automatically so drivers don't have to.

Adaptive cruise control is one of 20 terms used to describe its functions so that you might see adaptive cruise control as the following in advertisements and vehicle descriptions:

  • Active cruise control
  • Dynamic cruise control
  • Radar cruise control
  • Automatic cruise control
  • Intelligent cruise control

ACC functions by sensory technology installed within vehicles such as cameras, lasers, and radar equipment, which creates an idea of how close one car is to another, or other objects on the roadway. For this reason, ACC is the basis for future car intelligence.

These sensory technologies allow the car to detect and warn the driver about potential forward collisions. When this happens, red lights begin to flash, and the phrase 'brake now!' appears on the dashboard to help the driver slow down. There might also be an audible warning.

Advantages of Adaptive Cruise Control

Some key advantages of ACC mentioned by MyCarDoesWhat.org include an increase in road safety, as cars with this technology will keep the adequate spacing between them and other vehicles. These space-mindful features will also help prevent accidents that result from an obstructed view or close following distance. Similarly, ACC will help maximize traffic flow because of its spatial awareness. As a driver, you don't have to worry about your speed, and instead, you can focus on what is going on around you.

The total block model is:

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.

ON MODE chart is as follows:

SLDD data is as:

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

-

-

SIL model is as follows:

Model Advisory Report:

By running the model advisory tool, we can get zero error based on the MAB checks on modelling standards.

CODE GENERATION :

 The C code for the above model is:
 

 
 
/*
 
 
* File: Adaptive_Cruise_Control.c
 
 
 
* Code generated for Simulink model 'Adaptive_Cruise_Control'.
 
 
 
* Model version : 1.24
 
 
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
 
 
* C/C++ source code generated on : Mon Dec 6 13:39:40 2021
 
 
 
 
* 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: '/Adaptive Cruise Control Logic' */
 
 
#define Ada_IN_LeadVehicle_Not_Detected ((uint8_T)3U)
 
 
#define Adaptive_Cru_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
 
 
#define Adaptive_Cruise_Con_IN_OFF_MODE ((uint8_T)1U)
 
 
#define Adaptive_Cruise_Cont_IN_ON_MODE ((uint8_T)2U)
 
 
#define Adaptive_Cruise_IN_STANDBY_MODE ((uint8_T)3U)
 
 
#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)
 
 
/* Block states (default storage) */
 
 
DW_Adaptive_Cruise_Control_T Adaptive_Cruise_Control_DW;
 
 
/* Real-time model */
 
 
static 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_;
 
 
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;
 
 
}
 
 
/* Model step function */
 
 
void Adaptive_Cruise_Control_step(void)
 
 
{
 
 
int32_T tmp;
 
 
int32_T tmp_0;
 
 
uint8_T tmp_1;
 
 
uint8_T tmp_2;
 
 
 
/* Sum: '/Add' incorporates:
 
 
* Inport: '/CameraInput_LeadVehicle'
 
 
* Inport: '/RadarInput_LeadVehicle'
 
 
*/
 
 
LeadVehicle_Speed = (uint8_T)((uint32_T)CameraInput_LeadVehicle +
 
 
RadarInput_LeadVehicle);
 
 
 
/* SignalConversion: '/Signal Conversion' incorporates:
 
 
* Inport: '/RadarInput_DriveVehicle'
 
 
*/
 
 
LeadVehicle_Detected = RadarInput_DriveVehicle;
 
 
 
 
 
/* Sum: '/Add' incorporates:
 
 
* Inport: '/CameraInput_DriveVehicle'
 
 
* Inport: '/RadarInput_DriveVehicle'
 
 
* UnitDelay: '/Unit Delay'
 
 
*/
 
 
DriveVehicle_Speed = (uint8_T)((uint32_T)(uint8_T)((uint32_T)
 
 
CameraInput_DriveVehicle + RadarInput_DriveVehicle) + Acceleration_Mode);
 
 
 
 
 
/* Chart: '/Adaptive Cruise Control Logic' incorporates:
 
 
* Inport: '/CruiseSwitch'
 
 
* Inport: '/SetSwitch'
 
 
* Inport: '/Set_Gap'
 
 
* Inport: '/Set_Speed'
 
 
* Inport: '/Time_Gap'
 
 
*/
 
 
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_Con_IN_OFF_MODE;
 
 
Acceleration_Mode = 0U;
 
 
} else {
 
 
switch (Adaptive_Cruise_Control_DW.is_c3_Adaptive_Cruise_Control) {
 
 
case Adaptive_Cruise_Con_IN_OFF_MODE:
 
 
Acceleration_Mode = 0U;
 
 
if (CruiseSwitch && (!SetSwitch)) {
 
 
Adaptive_Cruise_Control_DW.is_c3_Adaptive_Cruise_Control =
 
 
Adaptive_Cruise_IN_STANDBY_MODE;
 
 
Acceleration_Mode = 1U;
 
 
}
 
 
break;
 
 
 
 
 
case Adaptive_Cruise_Cont_IN_ON_MODE:
 
 
if (!CruiseSwitch) {
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE = Adaptive_Cru_IN_NO_ACTIVE_CHILD;
 
 
Adaptive_Cruise_Control_DW.is_c3_Adaptive_Cruise_Control =
 
 
Adaptive_Cruise_Con_IN_OFF_MODE;
 
 
Acceleration_Mode = 0U;
 
 
} else if (!SetSwitch) {
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE = Adaptive_Cru_IN_NO_ACTIVE_CHILD;
 
 
Adaptive_Cruise_Control_DW.is_c3_Adaptive_Cruise_Control =
 
 
Adaptive_Cruise_IN_STANDBY_MODE;
 
 
Acceleration_Mode = 1U;
 
 
} else {
 
 
switch (Adaptive_Cruise_Control_DW.is_ON_MODE) {
 
 
case IN_LeadVehicle_Detected_Follow:
 
 
Acceleration_Mode = 2U;
 
 
if (LeadVehicle_Detected == 0) {
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE =
 
 
Ada_IN_LeadVehicle_Not_Detected;
 
 
Acceleration_Mode = 1U;
 
 
} else if (((LeadVehicle_Detected == 1) && (LeadVehicle_Speed <
 
 
Set_Speed)) || (Time_Gap < Set_Gap)) {
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE =
 
 
IN_LeadVehicle_Speed_lessthan_S;
 
 
Acceleration_Mode = 4U;
 
 
}
 
 
break;
 
 
 
 
 
case IN_LeadVehicle_Detected_Resume:
 
 
Acceleration_Mode = 3U;
 
 
if ((DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >=
 
 
Set_Speed) && (Time_Gap >= Set_Gap)) {
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE =
 
 
IN_LeadVehicle_Detected_Follow;
 
 
Acceleration_Mode = 2U;
 
 
} else if (LeadVehicle_Detected == 0) {
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE =
 
 
IN_LeadVehicle_Not_Detected_Res;
 
 
Acceleration_Mode = 1U;
 
 
} else if ((DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed >
 
 
DriveVehicle_Speed) && (Time_Gap >= Set_Gap)) {
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE =
 
 
IN_LeadVehicle_Speed_equal_Set_;
 
 
Acceleration_Mode = 5U;
 
 
}
 
 
break;
 
 
 
 
 
case Ada_IN_LeadVehicle_Not_Detected:
 
 
Acceleration_Mode = 1U;
 
 
if ((LeadVehicle_Detected == 1) && (DriveVehicle_Speed == Set_Speed) &&
 
 
(LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)) {
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE =
 
 
IN_LeadVehicle_Detected_Follow;
 
 
Acceleration_Mode = 2U;
 
 
} else if (((LeadVehicle_Detected == 1) && (LeadVehicle_Speed <
 
 
Set_Speed)) || (Time_Gap < Set_Gap)) {
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE =
 
 
IN_LeadVehicle_Speed_lessthan_S;
 
 
Acceleration_Mode = 4U;
 
 
}
 
 
break;
 
 
 
 
 
case IN_LeadVehicle_Not_Detected_Res:
 
 
Acceleration_Mode = 1U;
 
 
break;
 
 
 
 
 
case IN_LeadVehicle_Speed_equal_Set_:
 
 
Acceleration_Mode = 5U;
 
 
if ((LeadVehicle_Detected == 0) || (DriveVehicle_Speed <= Set_Speed))
 
 
{
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE =
 
 
IN_LeadVehicle_Not_Detected_Res;
 
 
Acceleration_Mode = 1U;
 
 
} else if (((DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed >
 
 
DriveVehicle_Speed)) || (Time_Gap >= Set_Gap)) {
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE =
 
 
IN_LeadVehicle_Detected_Resume;
 
 
Acceleration_Mode = 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_ON_MODE =
 
 
IN_LeadVehicle_Speed_lessthan_S;
 
 
Acceleration_Mode = 4U;
 
 
}
 
 
break;
 
 
 
 
 
default:
 
 
/* case IN_LeadVehicle_Speed_lessthan_Set_Speed: */
 
 
Acceleration_Mode = 4U;
 
 
if ((LeadVehicle_Detected == 0) && (DriveVehicle_Speed == Set_Speed))
 
 
{
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE =
 
 
Ada_IN_LeadVehicle_Not_Detected;
 
 
Acceleration_Mode = 1U;
 
 
} else {
 
 
tmp = (int32_T)rt_roundd_snf((real_T)LeadVehicle_Speed * 1.25);
 
 
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;
 
 
}
 
 
 
 
 
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_ON_MODE =
 
 
IN_LeadVehicle_Speed_equal_Set_;
 
 
Acceleration_Mode = 5U;
 
 
}
 
 
}
 
 
break;
 
 
}
 
 
}
 
 
break;
 
 
 
 
 
default:
 
 
/* case IN_STANDBY_MODE: */
 
 
Acceleration_Mode = 1U;
 
 
if (!CruiseSwitch) {
 
 
Adaptive_Cruise_Control_DW.is_c3_Adaptive_Cruise_Control =
 
 
Adaptive_Cruise_Con_IN_OFF_MODE;
 
 
Acceleration_Mode = 0U;
 
 
} else if (SetSwitch) {
 
 
Adaptive_Cruise_Control_DW.is_c3_Adaptive_Cruise_Control =
 
 
Adaptive_Cruise_Cont_IN_ON_MODE;
 
 
Adaptive_Cruise_Control_DW.is_ON_MODE = IN_LeadVehicle_Detected_Follow;
 
 
Acceleration_Mode = 2U;
 
 
}
 
 
break;
 
 
}
 
 
}
 
 
 
 
 
/* End of Chart: '/Adaptive Cruise Control Logic' */
 
 
}
 
 
 
 
 
/* 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]
 
 
*/
 
 
 
 
 

 
 
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.

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.