Challenge

Project 1 (Mini Project on Vehicle Direction Detection

Mini Project - Vehicle Direction Determination

General Overview:

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 the vehicle is identifying the direction the vehicle is taking based on the camera input.

The camera reads the road signs & stores them into its memory with unique values for the left turn, right turn & straight drive. Depending on the direction it is taking, the 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 alongside 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.

Objective:

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

To create the model for Vehicle direction determination, I created the Simulink data dictionary with the help of the above-mentioned values.

Signals & Calibration Data List:

Signal / Calibration Name

Signal Type

Data Type

Dimension

Min

Max

Initial Value

Units

SteeringWheel_YawDegreeInput

Input

Int16

1

-180

180

-

Deg

CameraInput_RoadSign

Input

Boolean

1

0

1

-

-

Vehicle_Turn_Status

Local

Int16

1

-180

180

-

Deg

Right_Turn_AngularLimit

Calibration

Int16

[1 1]

-180

180

30

Deg

Left_Turn_AngularLimit

Calibration

Int16

[1 1]

-180

180

-120

Deg

Straight_Drive_Steering_Angle

Calibration

Int16

[1 1]

-180

180

0

Deg

RightTurn_RoadSign

Calibration

Int16

[1 1]

-180

180

30

LeftTurn_RoadSign

Calibration

Int16

[1 1]

-180

180

-120

Straight_RoadSign

Calibration

Int16

[1 1]

-180

180

0

Vehicle_Direction_Indicator

Output

Boolean

1

0

1

-

-

To create the data dictionary for a Simulink model, we need to link the data dictionary file to the model. To link the data dictionary to the model, initially expand the design tab in the modeling section and click on the link to the data dictionary then it will ask us to create a new data dictionary or use an existing data dictionary for this model. If we work with data for the first time and select new, then it asks us to save the file. Once the file was saved the data dictionary file is linked to our model. Now by following the below-mentioned steps we can add the data inside the data dictionary, once we successfully finished adding data to the data dictionary, right-click on the data dictionary file and select save changes to save the data in the data dictionary file.

Now we need to change the default solver settings to a fixed-step discrete (no continuous states), according to MAB guidelines the model must simulate in a fixed-step solver. The start time of the simulation is '0' seconds and the stop time is '4' seconds (start time is always '0' seconds). The sample time is changed from 'auto' to '0.01' seconds (this means the model will get updated every 0.01 seconds).

Now we need to change the default code generation target file to the 'ert.tlc' embedded coder. This embedded coder will generate the code in C language. The code generation target file will be saved in the same directory in which the model is saved.

Now we need to create the model according to the above-given requirements,


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 a 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 & the output of this requirement is a local signal (Signal Name: Vehicle_Turn_Status).

The below_given model represents the Requirement-1 model:

The requirement-1 model gets input of 'SteeringWheel_YawDegreeInput'. This SteeringWheel_YawDegreeInput is connected to the compare to constant blocks to check the input ( the condition inside the blocks are ['>0' and '>=0']), this is compared to the constant block connected to the center port switch blocks. The first switch's upper port is fed with 'Right_Turn_AngularLimit' and the lower port is fed with the output of the second switch block, the second switch's upper port is fed with 'Straight_Drive_Steering_Angle' and the lower port is fed with 'Left_Turn_AngularLimit'. These switch blocks are used to implement the if-else condition in the subsystem model. The output from this model is 'Vehicle_Turn_Status'.

Requirement – 2:

  • Keep this requirement as a separate subsystem. Inputs to this requirement are a local signal from requirement 1 (Signal Name: Vehicle_Turn_Status) & an input signal from the 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 an output signal (Signal Name: Vehicle_Direction_Indicator).

The below-given image represents the Requirement-2 model:

The output 'Vehicle_Turn_Status' is the first input for this model (requirement-2), this requirement-2 has fed with 'CameraInput_RoadSign'. The Vehicle_Turn_Status is connected to the first input ports of the three relational operator blocks and the second input ports are connected to the 'RightTurn_RoadSign', 'LeftTurn_RoadSign', and 'Straight_RoadSign'. The output from the relational operators is connected to the AND operator block upper port and the second input ports of AND operator blocks are connected to the 'CameraInput_RoadSign' with the help of gothe to block. The input parameters othe f goto are shown below, and the tag visibility is kept as 'local' because the to blocks are not connected to any other blocks ooutsidefrofhe the subsystem (If the blocks are connected outside of the subsystem, we need to keep the tag visibility as 'global').

After creating Requirement-1 and Requirement-2 models, we need to keep those models in a single subsystem, like in the above-given image. Now we need to add the requirement tags for both the subsystems 'Requirement-1' and 'Requirement-2'. The steps to add the requirement tag is, initially highlight the requirement in the word document and go to the subsystem in the model in Simulink, right-click on subsystem & select requirements and click on 'Link to Selection in Word'. This will directly add the requirement tag to that subsystem as shown below. The same procedure is repeated for rqurequirementsgging for the second subsystem 'Requirement-2'.

After adding the requirement tags to the subsystems, we need to resolve and propagate the signals properly. To resolve the signals, right-click on the signal and select properties. In the Signal properties add the signal name and select the option 'Simulink must resolve to Simulink signal object'. To indicate the signal name once the signal was resolved previously, we need to double click on the signal and type angular brackets & press enter, the signal name will be shown in the angular braces. The below-given image shows the process to resolve and propagate.

Before generating the code, we need to check whether this model is created under the MAB guidelines or not. To check for the MAB guidelines. Open 'Model Advisor' and select the subsystem, In the model advisor select 'By task'. In By task's select 'Modeling Standards for MAB', in MAB guidelines we have a total of 144 checks. Out of 144 checks, we shouldn't have any fail conditions in it and we need to reduce the warning count also to less than 5. The model advisor report will be saved in the same model directory in 'HTML' format. The model advisory check report is given-below.

After model advisory checks are finished successfully without having any fail conditions, we need to generate the C-code for the created model. To generate the C-code, click on apps and then 'Embedded Coder' and expand the build option, in build select 'Build' to generate the code. Once the code was generated we can see it on the right side of the Simulink modeling window, and we can see the code again in with the help of the view code option even if we close the generated code. The below-given images visualize, how I generated the code for the model 'Vehicle_Direction'.

The C-code:

/*
 * File: Vehicle_Direction.c
 *
 * Code generated for Simulink model 'Vehicle_Direction'.
 *
 * Model version                  : 1.3
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Fri May 27 11:22:28 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "Vehicle_Direction.h"
#include "Vehicle_Direction_private.h"

/* Exported data definition */

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

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

/* Real-time model */
static RT_MODEL_Vehicle_Direction_T Vehicle_Direction_M_;
RT_MODEL_Vehicle_Direction_T *const Vehicle_Direction_M = &Vehicle_Direction_M_;

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

  /* Switch: '/Switch2' incorporates:
   *  Constant: '/Constant'
   *  Constant: '/Constant'
   *  Inport: '/SteeringWheel_YawDegreeInput'
   *  RelationalOperator: '/Compare'
   *  RelationalOperator: '/Compare'
   *  Switch: '/Switch1'
   */
  if (SteeringWheel_YawDegreeInput > 0) {
    /* Switch: '/Switch2' incorporates:
     *  Constant: '/Constant'
     */
    Vehicle_Turn_Status = Right_Turn_AngularLimit;
  } else if (SteeringWheel_YawDegreeInput == 0) {
    /* Switch: '/Switch1' incorporates:
     *  Constant: '/Constant1'
     *  Switch: '/Switch2'
     */
    Vehicle_Turn_Status = Straight_Drive_Steering_Angle;
  } else {
    /* Switch: '/Switch2' incorporates:
     *  Constant: '/Constant2'
     *  Switch: '/Switch1'
     */
    Vehicle_Turn_Status = Left_Turn_AngularLimit;
  }

  /* End of Switch: '/Switch2' */

  /* SignalConversion: '/Signal Conversion' incorporates:
   *  Constant: '/Constant'
   *  Constant: '/Constant1'
   *  Constant: '/Constant2'
   *  Inport: '/CameraInput_RoadSign'
   *  Logic: '/AND'
   *  Logic: '/AND1'
   *  Logic: '/AND2'
   *  RelationalOperator: '/Relational Operator'
   *  RelationalOperator: '/Relational Operator1'
   *  RelationalOperator: '/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);
}

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

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

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

'The Simulink model file, other required data dictionary, model advisory checks HTML file and generated C-code files are attached as zip folder in the below browse section'.

1 comment
  1. Jaya PrabaharVery much useful in auto motive industry.
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.