Challenge

Project 2 Adaptive Cruise Control

AIM:

  1. To Developing Adaptive Cruise Control feature as per the Requirement Document using MATLAB Simulink.
  2.  To perform all the MBD related processes: Requirement Tagging & Traceability, SLDD creation, Configuration Parameter changes, Model Advisor check & Code Generation.
  3. To change  Configuration Parameters: enable “Support Floating Numbers” under Code Generation settings.
  4. Use Embedded Coder to generate the code.

                                                Figure 1a Simulink Model for Adaptive Cruise control

 

                                                                  Figure 1b Simulink Model of Adaptive Cruise control Subsytem

Requirement Analysis and Tracebillity

  • Based on the Requriements provided, the Inputs, Outputs and control logic is been decided.
  • Requirement Analysis is a very useful method or tool as it simplifies the problem based on what requirements are need to implement the algorithm.
  • All the requriements are Defined in Word File and by building the Model Based on the requreiments it is the fastest way to achieve a solution to the problem.
  • Requirements traceability connects models, tests, and code with requirement definitions to help manage change and reduce waste in the design life cycle.

In Adapative Cruise control there are 3 main requirements  

  1. Lead Vehicle
  2. Drive Vehicle
  3. Adaptive Cruise Control Algorithm

Adaptive Cruise Control is a very complex algorithm which is not easy to implement without a proper Analysis on what the requirements are need to implemenet an effective algorithm.

1.Lead Vehicle: Lead Vehicle is a vehicle which is driving in the road ahead of our drive vehicle.

Inputs Signals:

  • CameraInput_LeadVehicle 
  • RadarInput_LeadVehicle

Output Signals

 LeadVehicle_Speed 

  • Here simply add both the radar & camera inputs & the corresponding output is read as Speed profile output 
  • Speed data of the lead vehicle is critical in implementing the Adaptive Cruise Control algorithm.

                                            Figure 2:  Simulink Model of Lead Vehicle Speed Detection

2. Drive Vehicle: Drive Vehicle is the vehicle driven by the user & this is the vehicle which has ACC algorithm in it.

Inputs Signals: 

  • CameraInput_DriveVehicle
  • RadarInput_DriveVehicle
  • Acceleration_Mode

Output Signals: 

  • 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.

       

                                       Figure 3:  Simulink Model of Drive Vehicle Speed and Lead vehicle_Detection

3. Adaptive Cruise Control Algorithm:

State Machine Logic is used to implement this requriement

Input Signals: 

  • Time_Gap,
  • Set_Speed,
  • Set_Gap
  • CruiseSwitch
  • SetSwitch
  • DriveVehicle_Speed ( from requirement-2 is fed back as an input signal)
  • LeadVehicle_Detected (from requirement-2 is fed back as an input signal)
  • LeadVehicle_Speed (from requirement-1 is given as an input signal)

Output Signals: Acceleration_Mode

It governs the vehicular speed of the drive vehicle which automatically adjusts its speed & velocity to match the lead vehicle.

                                                   

                                         Figure 4a:  Adaptive Cruise Control AcceleraitonAlogorithm main using stateflow Chart

Based on the Inputs given to the Algorithm given as belwo the output Accelaration is varied

Adaptive Cruise Control feature has 3 major modes of operation

  1. OFF Mode,
  2. STANDBY Mode
  3. ON Mode.

                   

                               Figure 4b:  Adaptive Cruise Control Acceleration Alogorithm MOdes using stateflow Chart

1 - ACC OFF MODE state logic:

  • This is the default state inside state machine logic.
  • This state is governed by input signal CruiseSwitch.

Input Signal: CruiseSwitch

Output Signal:  Acceleration_Mode= 0

Condition:

  • If CruiseSwitch== 1, state ACC STANDBY mode will get activated.
  • If CruiseSwitch== 0, state ACC OFF mode will get activated, from either ACC ON mode or ACC STANDBY mode

2 –ACC STANDBY MODE state logic:

  • This is the second activated state inside state machine logic.
  • This state is governed by both input signals CruiseSwitch & SetSwitch.

Input Signal: CruiseSwitch & SetSwitch 

Output Signal:  Acceleration_Mode= 1

Condition

  • If CruiseSwitch== 1, state ACC STANDBY mode will get activated.
  • If CruiseSwitch== 0, state ACC OFF mode will get activated, from either ACC ON mode or ACC STANDBY mode
  • If SetSwitch== 1, state ACC ON mode will get activated.
  • If SetSwitch== 0, state ACC STANDBY mode will get activated.

3– ACC ON MODE state logic:

This state will be activated when 

Input signal: SetSwitch== 1.

There are 6 sub states to this state logic: They are:

  1. LeadVehicle_Detected_Follow (Default)
  2. LeadVehicle_Not_Detected
  3. LeadVehicle_Detected_Resume
  4. LeadVehicle_Not_Detected_Resume
  5. LeadVehicle_Speed_lessthan_Set_Speed
  6. LeadVehicle_Speed_equalto_Set_Speed

3 (i) – LeadVehicle_Detected_Follow (ACC ON MODE):

  • This is the default sub state inside ACC ON MODE state.

Output signal:  Acceleration_Mode == 2.

Condtions:

  • To  transit from LeadVehicle_Detected_Follow to  LeadVehicle_Not_Detected states; Input signal condition LeadVehicle_Detected == 0.
  •  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==1.

Conditions:

  • 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)]
  •  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= 3.

Condtions: 

  •  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)]
  • To transit from LeadVehicle_Detected_Resume to LeadVehicle_Not_Detected_Resume; 
  • Input signal condition LeadVehicle_Detected==0.
  • 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== 1.

Requirement 3c (v) - LeadVehicle_Speed_lessthan_Set_Speed (ACC ON MODE):

Output signal: Acceleration_Mode= 4.

Conditions:

  • 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=5.

Conditions:

  • 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

            

                                                     Figure 5:  Adaptive Cruise Control Alogorithm of ON State using stateflow Chart

Creation of Simulink Data Dictionary 

               

  • The Model Explorer is used in which, link to data dictionary option is selected to create, modify, and view the entries in a data dictionary
  • Here the access to base workspace is disabled as the requirement of data has already been provided and that data must be used for data referencing.
  • Based on the SLDD-XLFormat  file provided a Simulink Data Dictionary file Adaptive_cruise_control_Dictionary.sldd 

For code generation,

  • Storage class for Input signals: ImportedExtern;
  • Storage class for Output signal: Export to File;
  • Storage class for local signals: localizable;
  • Storage class for calibration signals: Const.

Main Advantage of using SLDD is it reduces repeateble initilasation or declaring init file for the parameters or signals in current model.

These parameters or signals can be directly linked to the SLDD file which not 

Model Advisor :

  • The Model Advisor checks the  model or subsystem for modeling conditions and configuration settings that cause inaccurate or inefficient simulation of the system that the model represents.
  • The Model Advisor checks  helps to verify compliance with industry standards and guidelines.
  • By using the Model Advisor, we can implement consistent modeling guidelines across projects and development teams.

here in this project, MAAB (MathWorks Automotive Advisory Board Standards) are used to check the modelling conditons and required errors are minimized in order to abid to the guidlines or Standards of the MAAB

The detailed report is generated in HTML file after minimising the errors or warinings to less than 15.

Model in Loop (MIL) Testing

Model in Loop testing is a systematic method to generate test cases from models based on the Requirement Analysis. It used to evaluate requirements independent of algorithm design and development.

Model-based testing involves:

  1. Creating a model of system requirements for testing
  2. Generating test data from this requirements using MIL Testing
  • In model-based testing, we use requirement analysis to generate test cases to verify your design.
  • This process also helps automate other verification tasks and streamlines the review process by linking test cases and verification objectives to high-level test requirements.
  • By building a simulink model we can analyze traceability between requirements, design, generated code, and test.

     3. Verifying the design algorithm with generated test cases

  • Using Simulink  can manage the test cases and systematically execute them to confirm that your design meets requirements.
  • code coverage metrics to assess the completeness of the MIL testing which can identify the missing requirements and functionalities.

Procedure for MIL Testing by generating a Test Harness file

Step 1: Configuration of Model Settings  for MIL Testing

                    

                                                 Figure6:  Solver Settings for MIL Testing

Here the in the model configuration settings, In Solver selection 

  • Solver - Discrete 
  • Solver Type - Fixed Step 0.01s

          

                                                  Figure 7: Code Generation parameters for MIL Testing

Here the in the model configuration settings, For Code Generation

  • System Target File: Embedded  Coder (ert.tlc) is selected as target file, to generate a Template of the current model for MIL Testing.
  • here the Floating-point numbers are enabled so as to use the parameters or signals in SLDD

                              

Step 2: Atomic Subsystem of the Adaptive Cruise Control

                                                  

                                               Figure8 : Block parameters of Adaptive Cruise Control

  • An Subsystem for the model is been created and it is block properties of the subsytem is set to  Treat as an Atomic unit.
  • The values or parameters which are defined are confined to this particular Atomic subsytem when it is treated as Atomic unit.

Step 3: Creation of Test Harness File for MIL Testing for the Adaptive Cruise Control

         

                                                                       Figure 9: Block parameters for Test Harness Creation 

This is an important step for MIL Testing, 

The block parameters of creation of Test harness are set as below

  • Source - Signal Builder 
  • Sink - Outport
  • Harness Creation options - Normal mode as verification mode

Other parameters are set to inheritly, By setting the above parameters, a Test Harness file is created for MIL Testing, 

Fix the errors displayed by Diagnostic Viewer and also check Model Advisor Tool. 

Step 4:  Internal Test Harness File of Adaptive Cruise Control

             

                           

                                    Figure 10: Simulink Model of Internal Test Harness File for Adaptive Cruise Control

Code Generation

After building the simulink model in order to determine the correctness of the model which is build a Model In Loop Testing is done first with the defined functional test cases. 

If the result found satisfactory then it is send to further higher stages for Software in Loop Testing and Hardware in Loop Testing.

Here in this model our Aim is to generate a code not to do SIL Testing.

Software-in-the-loop (SIL) Testing and Code Generation

  • A software-in-the-loop (SIL) simulation compiles generated source code and executes the code as a separate process on the computer.
  • During a SIL simulation, we can collect code coverage and execution-time metrics for the generated code.

Procedure for Software In Loop (SIL) Testing by generating a Test Harness file

Step 1: Configuration of Model Settings  for SIL Testing

                 

                                                 Figure11:  Solver Settings for SIL Testing

Here the in the model configuration settings, In Solver selection 

  • Solver - Discrete 
  • Solver Type - Fixed Step 0.01s

          

                                                  Figure 12: Code Generation parameters for SIL Testing

Here the in the model configuration settings, For Code Generation

  • System Target File: Embedded  Coder (ert.tlc) is selected as target file, to generate a Template of the current model for SIL Testing.
  • here the Floating-point numbers are enabled so as to use the parameters or signals in SLDD

                              

Step 2: Atomic Subsystem of the Adaptive Cruise Control

                                                  

                                               Figure 13: Block parameters of Adaptive Cruise Control

  • An Subsystem for the model is been created and it is block properties of the subsytem is set to  Treat as an Atomic unit.
  • The values or parameters which are defined are confined to this particular Atomic subsytem when it is treated as Atomic unit.

Step 3: Creation of Test Harness File for SIL Testing for the Adaptive Cruise Control

            

                                                                       Figure 14 : Block parameters for Test Harness Creation 

This is an important step for SIL Testing, 

The block parameters of creation of Test harness are set as below

  • Source - Signal Builder 
  • Sink - Outport
  • Harness Creation options - Software in Loop as verification mode

Other parameters are set to inheritly, By setting the above parameters, a Test Harness file is created for SIL Testing, 

Fix the errors displayed by Diagnostic Viewer and also check Model Advisor Tool. 

Step 4:  External Test Harness File of Adaptive Cruise Control

             

                   

                                                                Figure 15: Simulink Model of External Test Harness File for Adaptive Cruise Control

S function Logic 

  • An S-function is a computer language description of a Simulink block written in MATLAB, C, C++, or Fortran. C, C++, and Fortran S-functions are compiled as MEX (Matlab Executable ) files using the mex utility
  • As with other MEX files, S-functions are dynamically linked subroutines that the MATLAB execution engine can automatically load and execute.
  • S-functions use a special calling syntax called the S-function API that uses to interact with the Simulink engine.
  • This interaction is very similar to the interaction that takes place between the engine and built-in Simulink blocks.
  • Embedded Coder (ert.TLC), is used for S-functions in a model to generate a code for the Sign Detection Logic Subsystem.
  • After Creation of Test Harness file the parameters inside the sfunction are not tunable, in order to do so we have change in the main subsytem and repeat the code generation again.

                                 

 Signal Routing Subsystem

Input Signal Routing Subsystem

  • This subsystem has been created by Simulink to adapt the output of Signal builder blocks to the inteface required by the harness component. 
  • Any attempt in modifyong the contents of this subsystem may result in compliation and simulation failure                      

                                           

Output Signal Routing Subsystem

  • This subsystem has been created by Simulink to adapt the output of the harnessed component  to the inteface required by the sink block.
  • Any attempt in modifying the contents of this subsystem may result in compliation and simulation failure

                                                           

Conclusion:

  1. Hence Adaptive Cruise Control feature as per the Requirement Document is developed using MATLAB Simulink.
  2. All the MBD related processes: Requirement Tagging & Traceability, SLDD creation, Configuration Parameter changes, Model Advisor check & Code Generation was performed to above model and saved in the attached files.
  3. In Configuration Parameters: we enabled “Support Floating Numbers” under Code Generation settings.
  4. Hence a Model In Loop (MIL) , Software In Loop (SIL) Test Environment and Code Generation( Using Embedded Coder ertc.tlc) without function any functional testing is succesfully created for the Adaptive Cruise Control.
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.