Project 2 Adaptive Cruise Control
AIM:
1. Developing Adaptive Cruise Control feature as per the Requirement Document using MATLAB Simulink.
2. Follow all the MBD-related processes: Requirement Tagging and traceability, SLDD creation, Configuration Parameter changes, MODEl Advisor check and Code Generation.
3. In Configuration Parameters: Enable "Support Floating Numbers" under Code Generation Settings.
4. Use Embedded Coder to generate the code.
5. If choosing code generation, the Storage class for Input signals: ImportedExtern; Storage class for Output signal: ExportToFile; Storage class for local signals: Localizable; Storage class for calibration signals: Const.
6. Choose sample time for signals as 0.01s.
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 camera & radar. For complexity reasons, let's not adapt to any such algorithms.
- We can add both the radar & camera inputs, and 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.
Requirement 2 - Drive Vehicle:
- Drive Vehicle is the vehicle driven by the user & this is the vehicle that has the ACC algorithm in it.
- Like the Lead Vehicle, the Drive Vehicle algorithm also has 2 input signals (Signal Name: CameraInput_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; we ignore them for complexity reasons.
- 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).
- Signal DriveVehicle_Speed is the summation of the three input signals mentioned above & LeadVehicle_Detected is renamed from Input Signal RadarInput_DriveVehicle by more use of the 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.
- Output from this subsystem is a signal (Signal Name: Acceleration_MODE) that 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 the 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 equals 1, state ACC STANDBY MODE will get activated. If CruiseSwitch equals 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 equals 1, state ACC STANDBY MODE will get activated. If CruiseSwitch equals 0, state ACC OFF MODE will get activated from either ACC ON MODE or ACC STANDBY MODE.
Requirement 3c - ACC ON MODE State Logic:
This state will be activated when the input signal SetSwitch equals 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.
- 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 equals 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 equals 4.
- Condition to transit from LeadVehicle_Speed_lessthan_Set_Speed to LeadVehicle_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)) && (Drive_Vehicle_Speed < Set xss=removed>= 0.75 * Set_Gap))].
Requirement 3c (vi) - LeadVehicle_Speed_equal_Set_Speed (ACC ON MODE):
- Output signal Acceleration_Mode equals 5.
- Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Not_Detected_Resume; Input signal condition is [(LeadVehicle_Detected == 0) || (DriveVehicle_Speed <= Set_Speed)].
- Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Detected_Resume; Input signal conditions [((LeadVehicle_Speed * 1.25 >= DriveVehicle_Speed) && (LeadVehicle_Speed * 1.25 >= DriveVehicle_Speed < Set xss=removed>= 0.75 * Set_Gap))].
- Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Speed_lessthan_Set_Speed to LeadVehicle_Speed_lessthan_Set_Speed; Input signals conditions [(LeadVehicle_Speed < Set xss=removed>
Signals & Calibration Data List:
| Signal/Calibration Name | Signal Type | Data Type | Dimension | Min | Max | Initial Value | Units |
| CameraInput_LeadVehicle | Input | unit8 | 1 | 0 | 255 | - | - |
| RadarInput_LeadVehicle | Input | unit8 | 1 | 0 | 255 | - | - |
| CameraInput_DriveVehicle | Input | unit8 | 1 | 0 | 255 | - | - |
| RadarInput_DriveVehicle | Input | unit8 | 1 | 0 | 255 | - | - |
| Time_Gap | Input | unit8 | 1 | 0 | 255 | - | - |
| Set_Speed | Input | unit8 | 1 | 0 | 255 | - | - |
| Set_Gap | Input | unit8 | 1 | 0 | 255 | - | - |
| CruiseSwitch | Input | boolean | 1 | 0 | 1 | - | - |
| SetSwitch | Input | boolean | 1 | 0 | 1 | - | - |
| Acceleration_Mode | Output | unit8 | 1 | 0 | 255 | - | - |
| Leadvehicle_Speed | Output | unit8 | 1 | 0 | 255 | - | - |
| DriveVehicle_Speed | Output | unit8 | 1 | 0 | 255 | - | - |
| LeadVehicle_Detected | Output | unit8 | 1 | 0 | 255 | - | - |
Description:
Adaptive Cruise Control is an intelligent form of cruise control that slows down and speeds up automatically to keep pace with the car in front of you. The driver sets the maximum speed as with cruise control - then a radar sensor watches for traffic ahead, locks on to the car in a lane, and instructs the car to stay 2, 3, or 4 seconds behind the person car ahead of it (the driver sets the follow distance, within reason). Adaptive Cruise Control is now almost always paired with a pre-cash system that alerts you and often begins braking. Adaptive Cruise Control is also called active cruise control, autonomous cruise control, intelligent cruise control, or radar cruise control. This is because distance is measured by a small radar unit behind the front grille or under the bumper.
Adaptive Cruise Control Feature for passenger cars allows the host vehicle to adapt to the speed in line with the traffic flow. Driving in heavy traffic or keeping a safe distance from the preceding vehicle requires a high 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. Consequently, 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 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 around 30 kmph (20 mph) upwards and supports the driver, primarily on cross-country journeys or freeways. The cruise control stop-and-go variant is also active at speeds below 30 kmph (20 mph). It can maintain the set distance to the preceding vehicle even at very low speeds and 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 stop-and-go supports the driver 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 occur within defined limits. Even with Adaptive Cruise Control switched ON, the driver must monitor the speed and distance from the vehicle in front.
Simulink Model
- Open the Model Properties and select the Link to Data Dictionary. Go to External Data and click on New. Create your sldd file and click on OK.

- Now, create a subsystem Adaptive_Cruise_Control with the inputs as CameraInput_LeadVehicle, RadarInput_LeadVehicle, CameraInput_DriveVehicle, RadarInput_DriveVehicle, Time_Gap, Set_Speed, Set_Speed, Set_Gap, CruiseSwitch & SetSwitch, and output as Acceleration_Mode, LeadVehicle_Speed, DriveVehicle_Speed & LeadVehicle_Detected.

- Under the subsystem, create three subsystems.

- From the first subsystem, Lead_Vehicle, implement the given requirement. The following is the representation of the first subsystem:

- From the second subsystem, Drive_Vehicle, implement the given requirement. The following is the representation of the second subsystem:

- From the third subsystem, ACC_Algorithm, implement the given requirement. The following is the representation of the third subsystem:

- Now go to Model Data, which is left below the Simulink Model. Select External Data. Go to the sldd file name and select Design Data. Add all the variables provided in the question. Right-click on the sldd filename and select Save Changes to save the Data Dictionary.

- To resolve a signal, right-click on a signal → Properties.

- In Signal Properties, write a name in Signal name. Select "Signal name must resolve to Simulink signal object".

- To get the code generated, do the following steps:
Right-click on the main subsystem → Block Parameters (Subsystem) → Tick on Treat as atomic size → Model Configuration → Solver (Fixed Step) → Sample Time (0.01s) → Code Generation → ert.tlc → App (Embedded Code) → Build (Generate Code).
/* * Academic License - for use in teaching, academic research, and meeting * course requirements at degree granting institutions only. Not for * government, commercial, or other organizational use. * * File: ert_main.c * * Code generated for Simulink model 'Adaptive_Cruise_Control'. * * Model version : 1.16 * Simulink Coder version : 9.9 (R2023a) 19-Nov-2022 * C/C++ source code generated on : Thu Oct 12 19:45:29 2023 * * Target selection: ert.tlc * Embedded hardware selection: Intel->x86-64 (Windows64) * Code generation objectives: Unspecified * Validation result: Not run */ #include#include /* This example main program uses printf/fflush */ #include "Adaptive_Cruise_Control.h" /* Model header file */ /* * Associating rt_OneStep with a real-time clock or interrupt service routine * is what makes the generated code "real-time". The function rt_OneStep is * always associated with the base rate of the model. Subrates are managed * by the base rate from inside the generated code. Enabling/disabling * interrupts and floating point context switches are target specific. This * example code indicates where these should take place relative to executing * the generated code step function. Overrun behavior should be tailored to * your application needs. This example simply sets an error status in the * real-time model and returns from rt_OneStep. */ void rt_OneStep(void); void rt_OneStep(void) { static boolean_T OverrunFlag = false; /* Disable interrupts here */ /* Check for overrun */ if (OverrunFlag) { rtmSetErrorStatus(Adaptive_Cruise_Control_M, "Overrun"); return; } OverrunFlag = true; /* Save FPU context here (if necessary) */ /* Re-enable timer or interrupt here */ /* Set model inputs here */ /* Step the model */ Adaptive_Cruise_Control_step(); /* Get model outputs here */ /* Indicate task complete */ OverrunFlag = false; /* Disable interrupts here */ /* Restore FPU context here (if necessary) */ /* Enable interrupts here */ } /* * The example main function illustrates what is required by your * application code to initialize, execute, and terminate the generated code. * Attaching rt_OneStep to a real-time clock is target specific. This example * illustrates how you do this relative to initializing the model. */ int_T main(int_T argc, const char *argv[]) { /* Unused arguments */ (void)(argc); (void)(argv); /* Initialize model */ Adaptive_Cruise_Control_initialize(); /* Attach rt_OneStep to a timer or interrupt service routine with * period 0.01 seconds (base rate of the model) here. * The call syntax for rt_OneStep is * * rt_OneStep(); */ printf("Warning: The simulation will run forever. " "Generated ERT main won't simulate model step behavior. " "To change this behavior select the 'MAT-file logging' option.\n"); fflush((NULL)); while (rtmGetErrorStatus(Adaptive_Cruise_Control_M) == (NULL)) { /* Perform application tasks here */ } /* Terminate model */ Adaptive_Cruise_Control_terminate(); return 0; } /* * File trailer for generated code. * * [EOF] */ - Requirements Tagging
a. Create a Word file for each statement.
b. Copy-paste the statements to the respective requirement Word file.
c. Now scan the entire paragraph.
d. Go to the subsystem in the MATLAB Simulink and right-click the first subsystem → Requirements → Link to Selection in Word.
e. You will observe the MATLAB symbol occurring at the end-point. This indicates that Requirement1.docx has been tagged to the MATLAB Simulink.
The same procedure is followed for the Requirements - 2 & 3.
Conclusion:
- I have developed a MATLAB Simulink model of Adaptive Cruise Control as per the requirement document.
- I have followed all the MBD-related processes: Requirement Tagging and Traceability, SLDD creation, Configuration Parameter changes, and Code Generation. Also, I have used Embedded Coder to generate the code.
[Note: I couldn't complete Model Advisor due to some technical issue.]