Challenge

Project 1 (Mini Project on Vehicle Direction Detection

Aim :

  • Main object of this project is to Create Model Based Development Simulink model for Vehicle Direction Detection As per the requirement specified.
  • Requirement tagging for requirement-1 & requirement-2 subsystems in the Simulink model with the respective selection in word document.
  • Create a data dictionary and linked to the developed model.
  • Code generation using embedded coder for the developed model.

Introduction:

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.

Objective of Mini Project:

  1. Development of MATLAB Simulink model as per requirement.
  2. Tag the requirements to the simulink model; tagging requirement 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 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.

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 THE SIMULINK MODEL:

The main subsystem ‘vehivle_direction along with inputs ‘SteeringWheel_YawDegreeInput’, ‘CameraInput_RoadSign’ and output signal ‘Vehicle_Direction_Indicator’ is shown below

Vehicle_direction subsystem

The main subsystem ‘vehicle_Direction’ is further divided into two more subsystems which are ‘Requirement-1’ and ‘Requirement-2’ as shown below.

Requirement-1

  • In the requirement-1 subsystem, the steering wheel yaw degree (Signal name: SteeringWheel_YawDegreeInput) is fed as input to the subsystem and this value 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.
  • The input signal SteeringWheel_YawDegreeInput Is compared against three angular values by using relational operator(‘==’) 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 turning towards .in this case the output of the relational operator’==’is equal to 1 only when the SteeringWheel_YawDegreeInput matches the calibration value angular limit specified in Right_Turn_AngularLimit, Left_Turn_AngularLimit, Straight_Drive_Steering_Angle.
  • Three switch blocks are used to implement the if-else logic.the output from each relational operator is given as condition input (input2)to each switch block.the switch will pass input1 (calibration value) when the condition(input2~=0)condition is satisfied ,else input3(output from the next switch block)is passed as output.
  • The signal’ Vehicle_Turn_Status’ obtained at the output of the first switch will be calibration angular value( Right_Turn_AngularLimit, Left_Turn_AngularLimit, Straight_Drive_Steering_Angle) if none of the conditions get satisfied, zero is passed as the output from the last switch. The signal’vehicle_turn_status’is fed to the outport of subsystem requirement-1.

  • Blocks used in this subsystem is shown below

    * Relational operator(==)

  • True if the first input is equal to the second input.

    * Switch block:

    The Switch block passes through the first input or the third input signal based on the value of the second input. The first and third inputs are data input. The second input is a control input. Specify the condition under which the block passes the first input by using the Criteria for passing first input and Threshold parameters.


    *Inport block:

    Inport blocks in a subsystem represent inputs to the subsystem. A signal arriving at an input port on a Subsystem block flows out of the associated Inport block in that subsystem. The Inport block associated with an input port on a Subsystem block is the block whose Port number parameter matches the relative position of the input port on the Subsystem block. For example, the Inport block whose Port number parameter is 1 gets its signal from the block connected to the topmost port on the Subsystem block.

    *Outport block:

  • Outport blocks in a subsystem represent outputs from the subsystem. A signal arriving at an Outport block in a subsystem flows out of the associated output port on that Subsystem block. The Outport block associated with an output port is the block whose Port number parameter matches the relative position of the output port on the Subsystem block. For example, the Outport block whose Port number parameter is 1 sends its signal to the block connected to the topmost output port on the Subsystem block.

Requirement-2

  • In ‘requirement-2’ subsystem ,the local signal’ vehicle_turn_status’fed from ‘requirement-1’subsystem is taken as input and is compared against calibration values(RightTurn_RoadSign, LeftTurn_RoadSign, Straight_RoadSign) using the relational operator’==’.
  • The Boolean value obtained at the output of the relational operator is compared against a Boolean input signal from camera (Signal Name: CameraInput_RoadSign), which confirms the occurrence of a road sign using ‘AND’operator.
  • The Boolean output signal obtained from each of the three three AND blocks are fed to the Mux and then signal conversion then fed to outport.’vehicle _direction_indicator’ to indicate the vehicle direction .the output vehicle_direction_indicator will be a three dimension signal having three Boolean elements , with the first element to indicate ‘Right_turn’, second element indicates ‘Left_turn’ and third element to indicate ‘Straight _drive’.

Blocks used in this subsystem

AND LOGICAL OPERATOR:

The Logical Operator block performs the specified logical operation on its inputs. If all inputs are 1 then the output is 1.

MUX:

The Mux block combines inputs with the same data type and complexity into a vector output. The output mux signal is flat, even if you create the mux signal from other mux signals. However, you can use multiple Mux blocks to create a mux signal in stages.

Signal conversion:

The Signal Conversion block converts a signal from one type to another

Requirement tagging:

The requirements ‘requirement-1’ and ‘requirements-2’ as provided in the requirements word document are tagged to their corresponding subsystem in the Simulink model. tagging a requirement in Simulink model is to first highlight the requirement statement in the word document, then right click on the subsystem in the model that has to be tagged, then select requirements, and then select ‘link to selection in word’.

For tagging select the word in document as shown below for requirement-1

For tagging select the word in document as shown below for requirement-2.

After tagging the subsystem is like shown below.

Creation of Simulink data dictionary

A simulink data dictionary (SLDD)file is created that contains input, output signals and calibration parameters used in the model. SLDD file is created by clicking the modelling then model properties, then ‘external data’ and specifying a file name for the data dictionary.

After creation of sldd is shown below.

solver settings Type as fixed step and solver as discrete beacuase of Discrete solvers are used for solving purely discrete models. They compute only the next simulation time step for a model.And also select step size is as 0.01.

For code generation purpose change the settings in configuration parameters select the system target file as ert.tlc embeded coder.

*MODEL ADVISOR

Check the model advisor and in that check MAAB and JMAAB rules .open model advisor and select the checks.

After run the checks report is generated .

Model advisor report is shown below.

mini.c
/*

 * File: mini.c

 *

 * Code generated for Simulink model 'mini'.

 *

 * Model version                  : 1.7

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

 * C/C++ source code generated on : Fri May  6 20:28:49 2022

 *

 * Target selection: ert.tlc

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

 * Code generation objectives: Unspecified

 * Validation result: Not run

 */



#include "mini.h"

#include "mini_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: '/LeftTurn_RoadSign' */

const int16_T Left_Turn_AngularLimit = -120;/* Referenced by:

                                             * '/Left_Turn_AngularLimit'

                                             * '/Left_Turn_AngularLimit1'

                                             */

const int16_T RightTurn_RoadSign = 30;

                                  /* Referenced by: '/RightTurn_RoadSign' */

const int16_T Right_Turn_AngularLimit = 30;/* Referenced by:

                                            * '/Right_Turn_AngularLimit'

                                            * '/Right_Turn_AngularLimit1'

                                            */

const int16_T Straight_Drive_Steering_Angle = 0;/* Referenced by:

                                                 * '/Straight_Drive_Steering_Angle'

                                                 * '/Straight_Drive_Steering_Angle1'

                                                 */

const int16_T Straight_RoadSign = 0;

                                   /* Referenced by: '/Straight_RoadSign' */



/* Real-time model */

static RT_MODEL_mini_T mini_M_;

RT_MODEL_mini_T *const mini_M = &mini_M_;



/* Model step function */

void mini_step(void)

{

  int32_T rtb_Vehicle_Turn_Status;



  /* Switch: '/Switch' incorporates:

   *  Constant: '/Left_Turn_AngularLimit'

   *  Constant: '/Right_Turn_AngularLimit'

   *  Constant: '/Right_Turn_AngularLimit1'

   *  Constant: '/Straight_Drive_Steering_Angle'

   *  Inport: '/SteeringWheel_YawDegreeInput'

   *  RelationalOperator: '/Relational Operator'

   *  RelationalOperator: '/Relational Operator1'

   *  RelationalOperator: '/Relational Operator2'

   *  Switch: '/Switch1'

   *  Switch: '/Switch2'

   */

  if (SteeringWheel_YawDegreeInput == Right_Turn_AngularLimit) {

    rtb_Vehicle_Turn_Status = Right_Turn_AngularLimit;

  } else if (SteeringWheel_YawDegreeInput == Left_Turn_AngularLimit) {

    /* Switch: '/Switch1' incorporates:

     *  Constant: '/Left_Turn_AngularLimit1'

     */

    rtb_Vehicle_Turn_Status = Left_Turn_AngularLimit;

  } else if (SteeringWheel_YawDegreeInput == Straight_Drive_Steering_Angle) {

    /* Switch: '/Switch2' incorporates:

     *  Constant: '/Straight_Drive_Steering_Angle1'

     *  Switch: '/Switch1'

     */

    rtb_Vehicle_Turn_Status = Straight_Drive_Steering_Angle;

  } else {

    /* Switch: '/Switch1' incorporates:

     *  Constant: '/Constant'

     *  Switch: '/Switch2'

     */

    rtb_Vehicle_Turn_Status = 0;

  }



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



  /* SignalConversion: '/Signal Conversion' incorporates:

   *  Constant: '/LeftTurn_RoadSign'

   *  Constant: '/RightTurn_RoadSign'

   *  Constant: '/Straight_RoadSign'

   *  Inport: '/CameraInput_RoadSign'

   *  Logic: '/AND'

   *  Logic: '/AND1'

   *  Logic: '/AND2'

   *  RelationalOperator: '/Relational Operator'

   *  RelationalOperator: '/Relational Operator1'

   *  RelationalOperator: '/Relational Operator2'

   */

  Vehicle_Direction_Indicator[0] = (CameraInput_RoadSign &&

    (rtb_Vehicle_Turn_Status == RightTurn_RoadSign));

  Vehicle_Direction_Indicator[1] = (CameraInput_RoadSign &&

    (rtb_Vehicle_Turn_Status == LeftTurn_RoadSign));

  Vehicle_Direction_Indicator[2] = (CameraInput_RoadSign &&

    (rtb_Vehicle_Turn_Status == Straight_RoadSign));

}



/* Model initialize function */

void mini_initialize(void)

{

  /* (no initialization code required) */

}



/* Model terminate function */

void mini_terminate(void)

{

  /* (no terminate code required) */

}



/*

 * File trailer for generated code.

 *

 * [EOF]

 */




For analysing purpose i am adding constant block in the place of SteeringWheel_YawDegreeInput signal

RIght turn

Left_turn

Straight_drive

Conclusion:

Thus, a Simulink model for vehicle direction detection has been designed and a Simulink data dictionary file has been created along with the code generation of the created model and its model advisor report satisfactorily.

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.