Challenge

Project 1 (Mini Project on Vehicle Direction Detection

AIM:

  • Development of MATLAB Simulink model as per requirement
  • Tag the requirements to the simulink model; tagging requirement 1 & requirement 2 to their corresponding subsystems is fine
  • MBD compliant changes, Data Dictionary creation & code generation is added advantage, and that is not scope of this project
  • If choosing 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
  • Choose sample time for all signals as 0.01s

OBJECTIVES:

Requirement - 1:

  • Steering wheel input as yaw rate (Signal name: SteeringWheel_YawDegreeInput) is the input for this system.
  • This is compared against 3 angular values, one each for left turn, right turn & straight drive (Calibration Values: Right_Turn_AngularLimit, Left_Turn_AngularLimit, Straight_Drive_Steering_Angle) to say which specific direction the steering wheel is turning towards.
  • Use switch blocks to compare & develop this requirement. Keep this requirement in a subsystem & output of this requirement is a local signal (Signal Name: Vehicle_Turn_Status).

Requirement – 2:

  • Keep this requirement as a separate subsystem. Inputs to this requirement are local signal from requirement 1 (Signal Name: Vehicle_Turn_Status) & an input signal from camera (Signal Name: CameraInput_RoadSign), which confirms the occurrence of a road sign.
  • Signal Vehicle_Turn_Status is compared against calibration values (Calibration Values: RightTurn_RoadSign, LeftTurn_RoadSign, Straight_RoadSign), if each of them is found equal, then each of the three corresponding output is compared against the camera input signal,
  • Using a logical operator block, only one among them is finally given as output signal (Signal Name: Vehicle_Direction_Indicator)

DEVELOPMENT OF MATLAB SIMULINK MODEL OF VEHICLE DIRECTION DETERMINATION

A general overview of the vehicle direction indication is,

  • Identifying the direction of the vehicle is one of the important & diverse features in Autonomous driving & Advanced Driver Assistance Features
  • This particular sub-feature of identifying the direction of vehicle is basically identifying the direction the vehicle is taking based on the camera input
  • Camera reads the road signs & stores into its memory with unique values for left turn, right turn & straight drive
  • Depending on the direction it is taking, final indication is given to the driver – as an indication if he is driving in the recommended direction or not
  • Vehicle Direction Determination can also be coupled along - side features like GPS systems to identify whether the vehicle is reaching its destination in an optimized manner
  • This sub feature can also be used along with Lane Detection, Highway Warning, Ramp Entry / Exit in Wrong Way Detection etcIdentifying the direction of the vehicle is one of the important & diverse features in Autonomous driving & Advanced Driver Assistance Features
  • This particular sub-feature of identifying the direction of vehicle is basically identifying the direction the vehicle is taking based on the camera input
  • Camera reads the road signs & stores into its memory with unique values for left turn, right turn & straight drive
  • Depending on the direction it is taking, final indication is given to the driver – as an indication if he is driving in the recommended direction or not
  • Vehicle Direction Determination can also be coupled along - side features like GPS systems to identify whether the vehicle is reaching its destination in an optimized manner. This sub feature can also be used along with Lane Detection, Highway Warning, Ramp Entry / Exit in Wrong Way Detection etc

Following were the procedure to create a 'Vehicle Direction Determination (VDD)' test environment,

STEP 1 - Open Modelling >>> Model settings. In configuration parameters choose 'Solver' and change the stop time as 0.1 sec, solver selection as Fixed-step type, solver as discrete (no continuous states) and solver details of sample time as 0.01

STEP 2 - Choose code generation, In system target file browse "ert.tlc Embedded Coder" and click OK. This makes to adapt all the configuration parameters as per the testing environment

STEP 3 - Now select Modelling tab >>> Link to Data Dictionary. In that pop-up window, Under the 'external data' tab, click New option to create the new data dictionary, name it and click OK

STEP 4 - Open Modelling >>> Model Explorer, choose created the 'Signals_and_Calibration_DD' (.sldd) file as below. And click the marked two simulink parameter and signal options to add the inputs to the data dictionary file. Then make a right click on the created file and select save changes

STEP 5 - Now we have to create the subsystem of 'Vehicle Direction Control' with two inputs and one output. Inside of this subsystem block we going to construct the given two requirements

STEP 6 - Inside the main subsystem, create 2 subsystems and name it as 'requirement-1' and 'requirement-2'

Requirement-1:

  • First of all pass the input ('SteeringWheel_YawDegreeInput') to the 'compare to constant' block

In first switch block,

  • Pass the 'compare to constant' block's ouput to the condition check of switch block and set criteria for passing first input as 'u2~=0'
  • Connect the 'Right_Turn_AngularLimit' constant block to the true connection
  • Connect the 2nd switch block's output to the 1st switch block's false connection
  • Get the another connection from the input and connect with the 'compare to constant' block

In second switch block,

  • Pass the 'compare to constant' block's ouput to the condition check of switch block and set criteria for passing first input as 'u2~=0'
  • Connect the 'Straight_Drive_Steering_Angle' constant block to the true connection
  • Connect the 'Left_Turn_AngularLimit' constant block to the false connection
  • The output will be the 'Vehicle_Turn_Status' from the switch blocks

Requirement-2:

  • Using goto blocks, for the two inputs of 'Vehicle_Turn_Status' and 'CameraInput_RoadSign'
  • Connect the from block (Vehicle_Turn_Status) and constant block (RightTurn_RoadSign) to the (==) relational operator block
  • Connect the from block (CameraInput_RoadSign) and output of the relational operator block to the (AND) logical operator block
  • Follow these above two steps for the remaining LeftTurn_RoadSign, Straight_RoadSign inputs
  • Then connect 3 logical operator outputs to the MUX block to get a single final output

STEP 7 - Follow the following points,

  • Connect the 'SteeringWheel_YawDegreeInput' signal to the requirement-1 subsystem as input
  • Connect the 'Vehicle_Turn_Status' local signal of requirement-1's output and 'CameraInput_RoadSign' signal to the requirement-2 subsystem as inputs
  • Make a 'Vehicle_Direction_Indicator' signal as final output

STEP 8 - Now Tagging. Tag the required documents of 'Requirement 1' & 'Requirement 2' to their corresponding subsystems were shown below

  • Create the word document with the given information
  • Select the appropriate word (Requirement - 1:) from the created document

  • And go to the simulink model and right click on the related subsystem (Requirement 1), then select Requirements >>> link to the selection in word. This makes that selected paragraph on word document to link with this subsystem's description

  • After the linking process, we can cross check as it linked properly or not. So again right click on the subsystem and select Requirements >>> 1. "Requirements - 1:"

  • Now you can see the targeted word from the document as below

  • Just follow the same steps to tag the description for 'Requirements 2' subsystem from the word document

STEP 9 - Resolve & Propagate. For resolve(requires that the resolved signal have the same name as the subsystem output or local data). For Propagate (to track a signal label through one block or many blocks)

Follow these steps for resolve:

  • Right-click the signal line connected to the subsystem that you want to resolve and select properties from the context menu
  • In the signal properties dialog box, enter a name for the signal that corresponds to the signal object
  • Enable the signal name must resolve to Simulink signal object check box. Click apply and OK

Follow these steps for propagate:

  • Right-click the signal for which you want to display a propagated signal label and select properties
  • In the signal properties dialog box, enable propagated signals check box. Click apply and OK

  • Following will shows how the model will looks like after the signals resolve and propagate were done,

Vehicle direction control subsystem:

Inside the Main subsystem:

Requirement-1 Subsystem:

Requirement-2 Subsystem:

STEP 10 - Now have to change the subsystem's parameter, so right click on the created subsystem and select 'block parameters (subsystem)'

STEP 11 - In this block parameters, enable the 'Treat as atomic unit', this causes simulink to treat the subsystem as a unit when determining block execution order. When it comes time to execute the subsystem, simulink executes all blocks within the subsystem before executing any other block at the same level as the subsystem block

For information,

  • If this option is not selected, simulink treats all blocks in the subsystem as being at the same level in the model hierarchy as the subsystem when determining block execution order
  • This can cause execution of blocks within the subsystem to be interleaved with execution of blocks outside the subsystem

STEP 12 - Code Generation. Open the APPS tab and choose the 'Embedded Coder' option to go for the code generation as shown below

STEP 13 - By choosing the 'Embedded Coder', the 'C code' tab will appears. In that tab, check once the 'code for' section for ensuring we're doing the codes for right subsystem and choose the 'Build' option to generate the codes. By this process, after the few moments the "C code" will be generated as shown below

STEP 14 - After the code generation, the 'mini_project_1_ert_rtw' folder will auto generated. This folder holds the supporting files of Vehicle Direction Determination Subsystem' like codes (.c), MAT (.mat), header (.h) files, etc.,

  • Following will shows the codes were hold by the C source file of 'mini_project_1.c',
/*
 * File: mini_project_1.c
 *
 * Code generated for Simulink model 'mini_project_1'.
 *
 * Model version                  : 1.31
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Fri May 27 11:37:54 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "mini_project_1.h"
#include "mini_project_1_private.h"

/* Exported data definition */

/* Definition for custom storage class: ExportToFile */
boolean_T Vehicle_Direction_Indicator[3];/* '<S3>/Signal Conversion' */

/* Const memory section */
/* Definition for custom storage class: Const */
const int16_T LeftTurn_RoadSign = -120;/* Referenced by: '<S3>/Constant1' */
const int16_T Left_Turn_AngularLimit = -120;/* Referenced by: '<S2>/Constant2' */
const int16_T RightTurn_RoadSign = 30; /* Referenced by: '<S3>/Constant' */
const int16_T Right_Turn_AngularLimit = 30;/* Referenced by: '<S2>/Constant' */
const int16_T Straight_Drive_Steering_Angle = 0;/* Referenced by: '<S2>/Constant1' */
const int16_T Straight_RoadSign = 0;   /* Referenced by: '<S3>/Constant2' */

/* Real-time model */
static RT_MODEL_mini_project_1_T mini_project_1_M_;
RT_MODEL_mini_project_1_T *const mini_project_1_M = &mini_project_1_M_;

/* Model step function */
void mini_project_1_step(void)
{
  /* local block i/o variables */
  int16_T Vehicle_Turn_Status;

  /* Outputs for Atomic SubSystem: '<Root>/Vehicle_Direction_Control' */
  /* Switch: '<S2>/Switch' incorporates:
   *  Constant: '<S4>/Constant'
   *  Constant: '<S5>/Constant'
   *  Inport: '<Root>/SteeringWheel_YawDegreeInput'
   *  RelationalOperator: '<S4>/Compare'
   *  RelationalOperator: '<S5>/Compare'
   *  Switch: '<S2>/Switch1'
   */
  if (SteeringWheel_YawDegreeInput > 0) {
    /* Switch: '<S2>/Switch' incorporates:
     *  Constant: '<S2>/Constant'
     */
    Vehicle_Turn_Status = Right_Turn_AngularLimit;
  } else if (SteeringWheel_YawDegreeInput == 0) {
    /* Switch: '<S2>/Switch1' incorporates:
     *  Constant: '<S2>/Constant1'
     *  Switch: '<S2>/Switch'
     */
    Vehicle_Turn_Status = Straight_Drive_Steering_Angle;
  } else {
    /* Switch: '<S2>/Switch' incorporates:
     *  Constant: '<S2>/Constant2'
     *  Switch: '<S2>/Switch1'
     */
    Vehicle_Turn_Status = Left_Turn_AngularLimit;
  }

  /* End of Switch: '<S2>/Switch' */

  /* SignalConversion: '<S3>/Signal Conversion' incorporates:
   *  Constant: '<S3>/Constant'
   *  Constant: '<S3>/Constant1'
   *  Constant: '<S3>/Constant2'
   *  Inport: '<Root>/CameraInput_RoadSign'
   *  Logic: '<S3>/AND'
   *  Logic: '<S3>/AND1'
   *  Logic: '<S3>/AND2'
   *  RelationalOperator: '<S3>/Relational Operator'
   *  RelationalOperator: '<S3>/Relational Operator1'
   *  RelationalOperator: '<S3>/Relational Operator2'
   */
  Vehicle_Direction_Indicator[0] = ((Vehicle_Turn_Status == RightTurn_RoadSign) &&
    CameraInput_RoadSign);
  Vehicle_Direction_Indicator[1] = ((Vehicle_Turn_Status == LeftTurn_RoadSign) &&
    CameraInput_RoadSign);
  Vehicle_Direction_Indicator[2] = ((Vehicle_Turn_Status == Straight_RoadSign) &&
    CameraInput_RoadSign);

  /* End of Outputs for SubSystem: '<Root>/Vehicle_Direction_Control' */
}

/* Model initialize function */
void mini_project_1_initialize(void)
{
  /* (no initialization code required) */
}

/* Model terminate function */
void mini_project_1_terminate(void)
{
  /* (no terminate code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */

STEP 15 - Model Advisor. Now open the Modelling >>> Model Advisor for MBD compliant changes. In that pop-up window, choose the system have to check and click OK

STEP 16 - Under the 'By Task' option, check 'Modeling Standards for MAB' and click the 'Run Selected Checks' option to starts the complaints checking

STEP 17 - After the check done, the report summary will shows the no.of pass, fail, warning as below,

  • Finally generate the report by selecting the 'Generate Report' option and click OK. The report file will saves in the related folder as in HTML format

Note: All the workout files were attached by zip file (.slx, .sldd, .m, .xlsx, .c, .html, etc.,) as below

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.