Challenge

Project 1 (Mini Project on Vehicle Direction Detection

AIM: To develop a Simulink model for Vehicle Direction Determination by following the given objectives

OBJECTIVES:

  • 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: Imported Extern; 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

THEORY:

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

SIMULINK MODEL:

There are two subsystems in the model where the Vehicle_Direction_Detection subsystem which takes inputs as SteeringWheel_YawDegreeInput and CameraInput_RoadSign giving Vehicle_Direction_Detection as output.

Two subsystems created based on the requirements provided where the Turn_Status subsystem takes SteeringWheel_YawDegreeInput as input and provide Vehicle_Turn_Status as output which is then provided as an input for the Direction_Indicator subsystem where the final output Vehicle_Direction_Indicator is obtained. The final output is 3x1 indicates whether the steering wheel is turning towards (i.e., right, left turn or straight drive).

Vehicle_Turn_Status_Subsystem (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).

Inside Logic:

The Turn_Status subsystem is created based on Requirement-1. Here, the 3 angular values Right_Turn_AngularLimit, Left_Turn_AngularLimit, Straight_Drive_Steering_Angle are compared using a switch block against the input SteeringWheel_YawDegreeInput to detect in which direction the vehicle is turning.

Vehicle _Directional _Indicator_Subsystem (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 output signal (Signal Name: Vehicle_Direction_Indicator).

Inside Logic:

The output Vehicle_Turn_Status from the Turn_Status subsystem is provided as the input along with the CameraInput_RoadSign confirming the occurrence of the respective road signs.

Here, the Vehicle_Turn_Status value is compared using the relational operator blocks set to equal to with the specified RightTurn_RoadSign, LeftTurn_RoadSign, Straight_RoadSign values. The Boolean output from these blocks is then given to the logical AND operator block to compare it with the Boolean input CameraInput_RoadSign. The output obtained is 3x1 specifying in which direction the vehicle is turning i.e., either left, right turn or straight drive.

Creating Simulink Data Dictionary file for the model:

Below table shows the input, output and calibration values with their respective signal, data type, dimension, min, max and initial values and units.

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

-

-

The same thing we have assigned in the SLDD file

Resolving Signal name to Simulink Signal Object:

Only two Input signals names are resolved to signal object to do so, Goto > Signal Properties > below shown pop-up window will appear, here check the box (signals names must resolve to simulink signal object) > clicl on Apply > Ok.

RESULTS:

Here we need to change the SteeringWheel_YawDegreeInput and CameraInput_RoadSign values in the SLDD file for every Condition correspondingly the results will occur.

Condition: 1

SteeringWheel_YawDegreeInput = 0

CameraInput_RoadSign = 0

Result: No Output (0,0,0)

Condition: 2

SteeringWheel_YawDegreeInput = 0

CameraInput_RoadSign = 1

Result: Straight drive (0,0,1)

Condition: 3

SteeringWheel_YawDegreeInput = 30

CameraInput_RoadSign = 0

Result: No Output (0,0,0)

Condition: 4

SteeringWheel_YawDegreeInput = 30

CameraInput_RoadSign = 1

Result: Right Turn (1,0,0)

Condition: 5

SteeringWheel_YawDegreeInput = -120

CameraInput_RoadSign = 0

Result: No Output (0,0,0)

Condition: 6

SteeringWheel_YawDegreeInput = -120

CameraInput_RoadSign = 1

Result: Left Turn (0,1,0)

Preparing Model Advisor report:

The below pictures show the steps to generate the Model Advisor report. The Vehicle_Direction_Detection subsystem block was selected for report generation by checking the necessary tasks and running them to check errors and warnings as shown below.

Right click on the main Vehicle Direction Detection subsystem > Model Advisor > Open Model Advisor as shown below

Now, check on the required check boxes of by product and by task, it is preferred to check on the By task boxes.

After successful running of the report will be generated.

Generating Code for the Model:

Before code generation we need to configure some properties as shown below System target file should be ert.tlc (Embedded coder).

To generate the code Goto > Apps > click on Embedded Coder.

Select the main subsystem block and click on Generate Code

This the code Generated

Generated Code:

/*

 * File: Vehicle_Direction_Detection_1.c

 *

 * Code generated for Simulink model 'Vehicle_Direction_Detection_1'.

 *

 * Model version                  : 1.52

 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020

 * C/C++ source code generated on : Tue Mar  8 12:22:57 2022

 *

 * Target selection: ert.tlc

 * Embedded hardware selection: Intel->x86-64 (Windows64)

 * Code generation objectives: Unspecified

 * Validation result: Not run

 */



#include "Vehicle_Direction_Detection_1.h"

#include "Vehicle_Direction_Detection_1_private.h"



/* Exported data definition */



/* Const memory section */

/* Definition for custom storage class: Const */

const int16_T LeftTurn_RoadSign = -120;

                                   /* Referenced by: '/LeftTurn_RoadSign' */

const int16_T Left_Turn_AngularLimit = -120;

                              /* Referenced by: '/Left_Turn_AngularLimit' */

const int16_T RightTurn_RoadSign = 30;

                                  /* Referenced by: '/RightTurn_RoadSign' */

const int16_T Right_Turn_AngularLimit = 30;

                             /* Referenced by: '/Right_Turn_AngularLimit' */

const int16_T Straight_Drive_Steering_Angle = 0;

                       /* Referenced by: '/Straight_Drive_Steering_Angle' */

const int16_T Straight_RoadSign = 0;

                               /* Referenced by: '/StraightTurn_RoadSign' */



/* External outputs (root outports fed by signals with default storage) */

ExtY_Vehicle_Direction_Detect_T Vehicle_Direction_Detection_1_Y;



/* Real-time model */

static RT_MODEL_Vehicle_Direction_De_T Vehicle_Direction_Detection__M_;

RT_MODEL_Vehicle_Direction_De_T *const Vehicle_Direction_Detection__M =

  &Vehicle_Direction_Detection__M_;



/* Model step function */

void Vehicle_Direction_Detection_1_step(void)

{

  int16_T rtb_Vehicle_Turn_Status;



  /* Switch: '/Switch' incorporates:

   *  Constant: '/Right_Turn_AngularLimit'

   *  Constant: '/Straight_Drive_Steering_Angle'

   *  Inport: '/SteeringWheel_YawDegreeInput'

   *  Switch: '/Switch1'

   */

  if (SteeringWheel_YawDegreeInput >= 30) {

    rtb_Vehicle_Turn_Status = Right_Turn_AngularLimit;

  } else if (SteeringWheel_YawDegreeInput != 0) {

    /* Switch: '/Switch1' incorporates:

     *  Constant: '/Left_Turn_AngularLimit'

     */

    rtb_Vehicle_Turn_Status = Left_Turn_AngularLimit;

  } else {

    rtb_Vehicle_Turn_Status = Straight_Drive_Steering_Angle;

  }



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



  /* Outport: '/Vehicle_Direction_Indicator' incorporates:

   *  Constant: '/LeftTurn_RoadSign'

   *  Constant: '/RightTurn_RoadSign'

   *  Constant: '/StraightTurn_RoadSign'

   *  Inport: '/CameraInput_RoadSign'

   *  Logic: '/AND'

   *  Logic: '/AND1'

   *  Logic: '/AND2'

   *  RelationalOperator: '/Relational Operator'

   *  RelationalOperator: '/Relational Operator1'

   *  RelationalOperator: '/Relational Operator2'

   */

  Vehicle_Direction_Detection_1_Y.Vehicle_Direction_Indicator[0] =

    ((rtb_Vehicle_Turn_Status == RightTurn_RoadSign) && CameraInput_RoadSign);

  Vehicle_Direction_Detection_1_Y.Vehicle_Direction_Indicator[1] =

    ((rtb_Vehicle_Turn_Status == LeftTurn_RoadSign) && CameraInput_RoadSign);

  Vehicle_Direction_Detection_1_Y.Vehicle_Direction_Indicator[2] =

    ((rtb_Vehicle_Turn_Status == Straight_RoadSign) && CameraInput_RoadSign);

}



/* Model initialize function */

void Vehicle_Direction_Detection_1_initialize(void)

{

  /* (no initialization code required) */

}



/* Model terminate function */

void Vehicle_Direction_Detection_1_terminate(void)

{

  /* (no terminate code required) */

}



/*

 * File trailer for generated code.

 *

 * [EOF]

 */

CONCLUSION:

Hence, a Simulink model with the specified subsystems is developed as per the given requirements and created a Simulink Data Dictionary (SLDD)file as per the Signals and Calibration List and Model Advisor Report is generated. Finally, Code Generation steps are carried and generated the code for Main Subsystem.

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.