Vehicle Direction Detection
Mini Project - Vehicle Direction Determination
Aim: To build a Simulink model that takes the steering yaw angle as input and compares it with camera inputs to determine the Direction of the Vehicle.
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 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:
- 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
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).
Initially, the subsystem named Vehicle Direction is created which takes the inputs such as SteeringWheel_YawDegreeInput and CameraInput_RoadSign and gives the output as Vehicle_Direction_Indicator.

The subsystem consists of two more subsystems of Requirement1 and Requirement2 as per the requirements given.

Inside the first subsystem,

The yaw angle is the input which is passed through a switch block, which is having the threshold as Right_Turn_AngularLimit. If the input is greater than the right turn limit i.e., 30 deg then theright turn limit is thrown as output or else the input passes through another switch which check for not equal to 0, if the condition satisfies then left turn limit goes as output else the straight angle is thrown as output. The output is labelled as Vehicle_Turn_Status.
Condition of requirement1,
- SteeringWheel_YawDegreeInput >= 30, Right_Turn_AngularLimit
- SteeringWheel_YawDegreeInput ~= 0, Left_Turn_AngularLimit
- SteeringWheel_YawDegreeInput = 0, Straight_Drive_Steering_Angle

Inside the 2nd subsystem, the turn status output from the 1st subsystem is given as input, which is compared with the calibration values of road sign right left and straight. Further these signals are passes through three and gates along with the camera input. This checks the camera input and the compared value of turn status, further these signals are passed through mux block and thrown as outputs.
Condition of requirement2,
- Vehicle_Turn_Status==RightTurn_RoadSign,Output for the Vehicle indication is 1 and CameraInput_Roadsign Input =1 given to AND gate ,If the Both input is same the Vehicle Detection indicator shows RightTurn_RoadSign .
- Vehicle_Turn_Status==LeftTurn_RoadSign,Output for the Vehicle indication is 1 and CameraInput_Roadsign Input =1 given to AND gate ,If the Both input is same the Vehicle Detection indicator shows LeftTurn_RoadSign.
- Vehicle_Turn_Status==Straight_RoadSign,Output for the Vehicle indication is 1 and CameraInput_Roadsign Input =1 given to AND gate ,If the Both input is same the Vehicle Detection indicator shows Straight_RoadSign.
By Using a logical operator block, only one among them is finally given as output signal (Signal Name: Vehicle_Direction_Indicator).
Requirement Tagging
To do the requirement Tagging select the Heading or the section of the particular word file in MS word and go to Subsystem, where we need to tag the requirement and right click requirement1 subsystem and Click on Requirements and click on Link to selection in Word.

Once the requirement tagging is done the Model Advisor check as per MAAB guidelines is carried out.

The warnings are reduces by making the suggested correction.

The report is exported and stored.

Further, the test cases for the requirements are written for right turn, left turn and straight.

MIL Testing:
The test harness for MIL test is created by right clicking on the subsystem and harness option from the list as shown below.

Signal builder is used as inport for the harness,

The test harness is created as shown below and further modification are done to check the nullification.

Signal builder is loaded with the test cases,

The output from the first scope is observed as shown below,

This output is subtracted by the signal builder inputs from test cases,

The difference between is verified as we can see there is no deviation.
SIL Testing
For SIL Testing the same steps as per MIL is done in the harness tab under advanced properties the verification mode is changed to SIL.
Before that to create SIL test Harness check the treat as atomic in subsystem parameters,

Change the model settings, code generation to ert.tlc


The SIL test harness is created,

And the results are same as of MIL test.

For 2nd scope.

Code Generation:
In the Apps section goto embedded coder if not built earlier select build or if built already select view code to display in matlab.

The generated code files are stored in the folder specified.

The generated code is shown below.
/*
* File: Vehicle_Direction.c
*
* Code generated for Simulink model 'Vehicle_Direction'.
*
* Model version : 1.9
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Sat Jul 1 18:13:18 2023
*
* 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"
/* External inputs (root inport signals with default storage) */
ExtU_Vehicle_Direction_T Vehicle_Direction_U;
/* External outputs (root outports fed by signals with default storage) */
ExtY_Vehicle_Direction_T Vehicle_Direction_Y;
/* 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)
{
int16_T rtb_Vehicle_Turn_Status;
/* Outputs for Atomic SubSystem: '/Vehicle_Direction' */
/* Switch: '/Switch' incorporates:
* Constant: '/Constant'
* Constant: '/Constant2'
* Inport: '/SteeringWheel_YawDegreeInput'
* Switch: '/Switch1'
*/
if (Vehicle_Direction_U.SteeringWheel_YawDegreeInput >=
Right_Turn_AngularLimit) {
rtb_Vehicle_Turn_Status = Right_Turn_AngularLimit;
} else if (Vehicle_Direction_U.SteeringWheel_YawDegreeInput != 0.0) {
/* Switch: '/Switch1' incorporates:
* Constant: '/Constant1'
*/
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: '/Constant'
* Constant: '/Constant1'
* Constant: '/Constant3'
* Inport: '/CameraInput_RoadSign'
* Logic: '/Logical Operator'
* Logic: '/Logical Operator1'
* Logic: '/Logical Operator2'
* RelationalOperator: '/Relational Operator'
* RelationalOperator: '/Relational Operator1'
* RelationalOperator: '/Relational Operator2'
*/
Vehicle_Direction_Y.Vehicle_Direction_Indicator[0] = ((rtb_Vehicle_Turn_Status
== RightTurn_RoadSign) && Vehicle_Direction_U.CameraInput_RoadSign);
Vehicle_Direction_Y.Vehicle_Direction_Indicator[1] = ((rtb_Vehicle_Turn_Status
== LeftTurn_RoadSign) && Vehicle_Direction_U.CameraInput_RoadSign);
Vehicle_Direction_Y.Vehicle_Direction_Indicator[2] = ((rtb_Vehicle_Turn_Status
== Straight_RoadSign) && Vehicle_Direction_U.CameraInput_RoadSign);
/* End of Outputs for SubSystem: '/Vehicle_Direction' */
}
/* 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]
*/
CONCLUSION:
- Development of MATLAB Simulink model as per requirement is created and Simulated.
- The Vehicle Direction is Detected Based on the input SteeringWheel_YawDegreeInput and CameraInput_Roadsign to Indicate the RightTurn, LeftTurn and Straight .
- The requirements to the Simulink model; tagging requirement 1 & requirement 2 to their corresponding subsystems is Created
- MBD-compliant changes, Data Dictionary creation & code generation is Generated as per given Requirement.
- Verification and Validation of Model is Done.
- Model In Loop and Software in Loop Testing Is Verified and Test Harness is Created.
- SIL Testing is conducted and the harness is created for the same and the Generated C Code is attached.
The project folder is compressed and the same is attached in the attachments along with the model.