Challenge

Project 2 Adaptive Cruise Control

1. AIM:

  • To develop Adaptive Cruise Control feature as per the Requirement Document using MATLAB Simulink.
  • Following all the MBD related processes: Requirement Tagging & Traceability, SLDD creation, Configuration Parameter changes, Model Advisor check & Code Generation.
  • Setting Configuration Parameters: enable “Support Floating Numbers” under Code Generation settings.
  • with the use of Embedded Coder to generate the code.
  • 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.
  • And choose sample time for all signals as 0.01s

2.DESCRIPTION:

I. Developing model:

  • Open a blank model.
  • Add subsystem block into model canvas.
  • Making some setting changes like off the Content Preview , On Show Block Names . For all this set-up just double click on subsystem block and Goto Format a drop down will appear click on Content Preview.
  • To On Show Block Names go inside subsystem select blocks and right click ,again do the similar drill as we just did.
  • Now replace by default appeared blocks and add a subsystem.
  • Name that subsystem as LeadVehicle_Input.
  • Double tap onto subsystem LeadVehicle_Input , go inside and add all the required blocks.
  • Make all connections and provide names to two inputs and an output block as CameraInput_LeadVehicle RadarInput_LeadVehicle and LeadVehicle_Speed.
  • Get out of LeadVehicle_Input subsystem and add same inputs ,output to the ports appearing on this subsystem.
  • CameraInput_LeadVehicle and RadarInput_LeadVehicle and output is LeadVehicle_Speed.
  • Create a new subsystem DriveVehicle_Input on the same canvas where LeadVehicle_Input exists.
  • Add all Required blocks inside subsystem DriveVehicle_Input.
  • There are three inputs to this subsystem CameraInput_DriveVehicle, RadarInput_DriveVehicle and Acceleration_Mode and two outputs are DriveVehicle_Speed and LeadVehicle_Detected.
  • Acceleration_Mode is actually an output which is fedback as input to this subsystem.
  • The 2nd output LeadVehicle_Detected is renamed from Input Signal RadarInput_DriveVehicle by use of Signal Conversion block.
  • Make all the connection.
  • Get out of this Subsystem, add three inputs and two outputs to all the available ports as shown in image below.
  • Connect them with their corresponding ports.
  • Now apply third requirement by using State machine flowcharts.
  • Load a Chart on the same canvas where two subsystems exist.
  • This Chart is consists Adaptive Cruise Control Logic Algorithm.
  • There are Three Main Modes of ACC : ACC OFF MODE(default) , ACC STANDBY MODE, ACC ON MODE.
  • There are eight inputs and one output for control logic.
  • 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.
  • To make connections we need to get input and output ports on Chart.
  • Goto Model Explorer, on the left side of window we can see some listed items.
  • Find Chart and as we click on it, a blank stateflow canvas open.
  • Go to top left of window find Add Data in icon tray, click nine times on Add Data as we have nine values combining inputs and output.
  • As we add data to Chart we can see all input and output ports are available on the chart.
  • Make connection of three signals( LeadVehicle_Speed, DriveVehicle_Speed & LeadVehicle_Detected) to their corresponding ports which are the outputs coming out from subsystems LeadVehicle_Input and DriveVehicle_Input.
  • Also connect output block to the output port Acceleration_Mode.
  • There is an input named Acceleration_Mode in subsystem DriveVehicle_Input which is being fedback from the final output Acceleration_Mode by using a unit delay block.
  • Five more Input blocks need to add for Input ports of Chart.
  • Go inside the Chart and write control llogic using states and flowcharts.
  • First of all load a default state which is for ACC OFF MODE, entry is Acceleration Mode=0 in this state.
  • Add a state for ACC STANDBY MODE.
  • 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.
  • ACC ON MODE 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

i) LeadVehicle_Detected_Follow (Default):

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

ii) LeadVehicle_Not_Detected:

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

iii) LeadVehicle_Detected_Resume:

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

iv) LeadVehicle_Not_Detected_Resume:

  • Output signal Acceleration_Mode is equal to 1.

v) LeadVehicle_Speed_lessthan_Set_Speed:

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

vi) LeadVehicle_Speed_Equal_Set_Speed:

  • 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)].
  • Come to the top layer subsystem ADAS.
  • Some of Input ports and ouput port is not connected, add required numbers of input and output blocks.
  • Connect input ports to their corresponding blocks.
  • Now,double click on signal line to add signal label at the origin of signals.
  • Do signal labelling to all input signals at the top layer subsystem ADAS.
  • All signals need to be resolved at the origin.
  • Steps fro resolving signal: Right click on signal line>>pop-up window appear>> click on Properties at bottommost>>Signal Properties window appear>>Tick the checkbox that reads "Simulink signal must reslove to simulink signal object"
  • As we click on Apply, we find an "E" with middle line extended backward like symbol appear at starting of Signal label_name.
  • Resolve all the input signals at te top layer.
  • Go for signal propagation.
  • Signal propagation is used in inner layers when the same signals are coming from the topmost layer,so instead of using signal labelling we use signal propagation.
  • For signal propagation, double click on signal line and type '<>' then press Enter.
  • Do signal labelling and signal propagation wherever is required.

3. REQUIREMENT TAGGING:

  • First of all create a requirement file, flie maybe word ,excel,MATLAB or in some other format.
  • Minimize Requirement file window size and select the text to link with model.
  • It requires that model and requirement file must be open side by side, do not even minimize any of them.
  • Now open model window and make right click on top level subsystem.
  • It'll show a context menu, Select Requirements>>Link to selection in word.
  • Now open inner level subsystems and do the same drill for each level of subsystem present in the model.
  • Open Chart and Tag requirement to each state.

4. SLDD CREATION:

  • Now it's time to create Data Dictionary to access all the input, output signal values and also the Calibration values.
  • Steps to create Data Dictionary: Goto Model Properties >> External Data.
  • Select New, it'll ask for name.
  • Name your Data Dictionary and uncheck the box present at the bottom which reads ''Enable model access to base workspace''.
  • Press Apply and Ok.
  • If Data Dictionary is Created succesfully, it'll start showing to Explore Data Dictionary at the bottom Left corner of the model window.
  • Click on External Data showing at bottom left corner of model window, a new window of model porerties will going to open.
  • Click on drop down arrow of Data Dictionary, Design Data appear.
  • We are ready to add all parameters of input ,output and calibration. Parameters like Initial value, Min and Max value, Dimension, DataType, Storage class, Unit can be set created a data dictionary.
  • Add all the Signals and Calibration values which are given to us.
  • Use Simulink Signal from the top icon tray to add input and output signals.
  • Use Simulink Parameters from the top icon tray to add Calibration values.
  • The storage class for Input signals should be ImpotedExtern , for output signals: ExportToFile and for Calibration values: ConstVolatile.
  • If choosing ExportToFile or ConstVolatile as storage class, we must have to provide HeaderFile and DefinitionFile as shown below.
  • After addiing all values, go to list of files present at the left side ,find Data Dictionary, make right click on it, a context menu appear , select Save Changes.

5. SETTING CONFIGURATION PARAMETERS:

  • To open Configuration Parameters: Goto model window>>Modelling>>Model Setting.
  • Another shortcut way to open it, by pressing Ctrl+E.
  • First of all change Solver setting ,by default it is set to Automatic we need to change it to Discrete(No continuous states).
  • Also change Solver Type to Fixed-step from Continuous step.
  • Provide Fundamental sample time as '0.01'
  • Making Some changes in Configuration Parameters in accordance with the MAAB Guidlines.
  • Most Important change required for Code eneration.
  • Goto Code Generation in Configuration Parameter.
  • Change the System Target File from 'grt.tlc' to 'ert.tlc' Embedded Coder.
  • It might be possible that we forget to set some values, for that sake we will do Model Advisor check and run.

6. MODEL ADVISOR REPORT:

  • Now before going to Generate Code, Run Model Advisor and see its report what errors or warnings are encountering at this stage pertaining to modelling guidelines and standards.
  • Try to diagnos those errors/ warnings.
  • All the errors must be removed but some warnings maybe retained if not affecting any of the functionality.
  • How to open Model Advisor: Goto Simulink Model window>> click on model advisor at the top left corner of window(a symbol of green right tick inscribed in a green circle).
  • After clicking on Model Advisor a pop-up window of System Selector appear as shown in image below.
  • Select System and click OK.
  • A new window will open which consists of two major checkbox: By Product and By Task.
  • Go with By Task, inside it there are too many checks pertaining to Modelling standard ,Guidelines.
  • We need to tick on the checks for Modelling Standard for MISRA C:2012 , Modelling Standard for ISO 26262, Modelling Standard for MAAB, Modelling Standard for JMAAB.
  • After marking on all the required checks,click on Run Selected Checks.
  • This Process will take some time to complete.
  • Model advisor window has two partitions, left side partition contain all the standard guidelines and right side partition is used for showing the result after running the selected checks whther checks are Pass, Fail, Warning or Not Run.
  • Warnings are shown by a caution symbol and passed checks are shown by a right tick symbol inscribed in a green circle.
  • If warnings are encountered, each and every warnings are shown on right partition and at the end we are asked to Modify all , clicking on it will modify all the required changes.
  • Another way to remove warnings is to manually go through each warning by clicking on given links.
  • Once all warning are taken into consideration and modified, we'll again do Run Selected Checks.
  • Do modify until get no more warnings.
  • Here are some examples of how to diagnos and fix the warnings.
  • Warning states Check number of inputs for Sum block.
  • We have given three input to a single sum block, go and give two input a sum block and output from this sum block will be given to another sum block with third input as shown below.
  • Next warning is showing that some signals are intersecting with other signal lines.
  • Click on following link ,it'll direct us to that block/signal.
  • Correct them so that they do not intersect .
  • Now, the warning is related to the syntax of state flowchart which states that following transition with condition is not drawn horizontally.
  • Click on following link ,it'll direct us to that block/signal.
  • Correct states and transition by taking them to the left from top.

Report:

  • We have 1210 checks in total ,and have selected 377 Check only.
  • Out of 377 selected checks we got 346 checks Pass, and 31 Warnings.
  • Those 31 Warnings are irremovable and Can be retained without affecting the functionality of system.
  • We need to justify about why those warnings are not removable and not affecting the functionality.
  • A warning is showing that block name of Unit Delay block should display below the block and an another warning is for Not to show block name of UnitDelay block, both warnings are contraversial to each other.

7.CODE GENERATION:

  • We are all set for Code Generation.
  • Goto model window and press Ctrl+B.
  • Once code is generated,two pop up window appears, one is for Code Generation Report and other is for Code.
  • Code Generation report consists of many files like Main File, Model File, Data file etc , it also consists Summary, Subsystem Report, Code Interface Report, Traceability report.
  • Main file cotains all the Main functions of C code.
  • .h File contains header files.
  • .c File contains source code for model.
  • To check the code for each level just goto C Code in model window, click on View Code.
  • A window for code will open, at the top of that window ,we can find a dropdown sign, clicking on it give us access for each files as shown below.
  • To verify our generated code we can further go with Verify Code option which is available in C Code itselfSimulink facilitate three levels to verify the code,first is Run in Real Time in which code is flashed into an ECU then connected to a hardware, second is Dynamic Code Verification which can be done by SIL/PIL Manager and the last is Static Code Verification it uses Polyspace Code Verifier.

8.RESULT:

  • Model is developed as per the requirement document.
  • Step by step procedure is provided with proper justification.
  • All the MBD related processes are fulfilled.
  • Requirement Tagging & Traceability, SLDD creation, Configuration Parameter changes, Model Advisor check & Code Generation has been done.
  • All the model related files are uploaded.
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.