Project 1 (Mini Project on Vehicle Direction Detection
Project 1 - Mini Project on Vehicle Direction Detection
Aim: To create a Simulink Data Dictionary file and a Simulink model for Vehicle Direction Detection.
General Overview of Mini Project :
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 basically 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 a 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.
The 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 the 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
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).
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_Statusis 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).
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 |
- |
- |
- The Simulink model is shown below. Which contains two subsystems.
- The First subsystem refers to the First requirement and the Second subsystem refers to another subsystem.

For First Requirement -

- Here, in the requirement 1 subsystem,
the Steering wheel input is given as yaw rate with the Signal name: SteeringWheel_YawDegreeInput which is the input for this system. - And this signal is compared against 3 angular values, one each for a left turn, right turn & straight drive assigned as the Calibration Values, like Right_Turn_AngularLimit, Left_Turn_AngularLimit, and Straight_Drive_Steering_Angle to compare with the input yaw rate of the steering wheel.
- Also, multiple switch blocks and Compare blocks are used to compare & develop this requirement.
The output of this requirement is a local signal with the resolved Signal Name: Vehicle_Turn_Status.
For Second Requirement -

- In the Requirement 2 subsystem,
The Inputs to this requirement are local signals from requirement 1 with Signal Name: Vehicle_Turn_Status & an input signal of the camera sensor from the camera Signal Name: CameraInput_RoadSign, which confirms the occurrence of a road sign. - Here, the Signal Vehicle_Turn_Status is compared against calibration values with the Calibration Values of RightTurn_RoadSign, LeftTurn_RoadSigna, and Straight_RoadSign.
- If any of them is found equal, then each of the three corresponding outputs is compared against the camera input signal. While Using a logical operator block, only one among them is finally given as output signal with the Signal Name: Vehicle_Direction_Indicator.
And this requirement is kept as a separate subsystem.
Simulink Data Dictionary -

The given parameters are defined as the sldd file along with its Storage class and Datatypes.
for Input signals, the storage class is chosen as ImportedExternwhile for the Storage class for the Output signal, Export to File is used. In the case of the Storage class for local signals, localizable is preferred, and in the case of the Storage class for calibration signals, Const is used.
Now let us move to the procedure -

- Procedure:
- Steering wheel input is defined as yaw rate with the Signal name, SteeringWheel_YawDegreeInput, and is the input for this system.
- This input for the system is compared against 3 angular values, one each for a left turn, right turn & straight drive which are defined as Calibration Values of Right_Turn_AngularLimit, Left_Turn_AngularLimit, and Straight_Drive_Steering_Angle, which is to say which specific direction the steering wheel is turning towards.
- We can Use switch blocks, relational and logical operators to compare & develop this requirement. This system, labeled as Requirement 1 keeps this requirement in a subsystem & the output of this requirement is directed to a local signal and is denoted with the Signal Name: Vehicle_Turn_Status.
-
Observation:
-
When the Yaw Rate input is 30 degrees, the steering turns right.
-
If the Yaw Rate input is -120 degrees, the steering is rotated left.
-
If the Yaw Rate input is 0 the vehicle continues to go straight.
-
Analytic Analysis:
When,
SteeringWheel_YawDegreeInput = say 30 then
SteeringWheel_YawDegreeInput==Right_Turn_AngularLimit so we obtained 1 as output from the Relational operator. As the threshold value is kept greater than zero so first switch along with first case is triggered and from switch, we got 30 as an output.
Now, this Vehicle_Turn_Status = 30 so this output goes to the next subsystem as input and it is again compared with three road sign.

So we can see here that we obtain the Vehicle_Direction_Indicator for right =1 and left and stright turn will be zero.
Now do Dynamic Testing -
- When,
SteeringWheel_YawDegreeInput = 30
CameraInput_RoadSign = 1

- When,
SteeringWheel_YawDegreeInput = -120
CameraInput_RoadSign = 1

- When,
SteeringWheel_YawDegreeInput = -120
CameraInput_RoadSign = 1

- Further requirement tagging is also done for both the system -


- Along with that one Requirement report is also generated -

- Now generating the code for the above model using Embedded C coder.
* Code generated for Simulink model 'Project_1'.
*
* Model version : 1.23
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Tue Dec 7 12:47:58 2021
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "Project_1.h"
#include "Project_1_private.h"
/* Exported data definition */
/* Const memory section */
/* Definition for custom storage class: Const */
const int16_T LeftTurn_RoadSign = -120;/* Referenced by: '<S2>/Constant3' */
const int16_T Left_Turn_AngularLimit = -120;/* Referenced by: '<S1>/Constant3' */
const int16_T RightTurn_RoadSign = 30; /* Referenced by: '<S2>/Constant' */
const int16_T Right_Turn_AngularLimit = 30;/* Referenced by: '<S1>/Constant' */
const int16_T Straight_Drive_Steering_Angle = 0;/* Referenced by: '<S1>/Constant4' */
const int16_T Straight_RoadSign = 0; /* Referenced by: '<S2>/Constant4' */
/* External outputs (root outports fed by signals with default storage) */
ExtY_Project_1_T Project_1_Y;
/* Real-time model */
static RT_MODEL_Project_1_T Project_1_M_;
RT_MODEL_Project_1_T *const Project_1_M = &Project_1_M_;
/* Model step function */
void Project_1_step(void)
{
/* local block i/o variables */
int16_T Vehicle_Turn_Status;
/* Switch: '<S1>/Switch3' incorporates:
* Constant: '<S1>/Constant'
* Constant: '<S1>/Constant3'
* Constant: '<S1>/Constant4'
* Inport: '<Root>/SteeringWheel_YawDegreeInput'
* RelationalOperator: '<S1>/Relational Operator'
* RelationalOperator: '<S1>/Relational Operator1'
* RelationalOperator: '<S1>/Relational Operator2'
* Switch: '<S1>/Switch1'
* Switch: '<S1>/Switch2'
*/
if (Right_Turn_AngularLimit == SteeringWheel_YawDegreeInput) {
/* Switch: '<S1>/Switch3' */
Vehicle_Turn_Status = Right_Turn_AngularLimit;
} else if (Left_Turn_AngularLimit == SteeringWheel_YawDegreeInput) {
/* Switch: '<S1>/Switch1' incorporates:
* Constant: '<S1>/Constant3'
* Switch: '<S1>/Switch3'
*/
Vehicle_Turn_Status = Left_Turn_AngularLimit;
} else if (Straight_Drive_Steering_Angle == SteeringWheel_YawDegreeInput) {
/* Switch: '<S1>/Switch2' incorporates:
* Constant: '<S1>/Constant4'
* Switch: '<S1>/Switch1'
* Switch: '<S1>/Switch3'
*/
Vehicle_Turn_Status = Straight_Drive_Steering_Angle;
} else {
/* Switch: '<S1>/Switch3' incorporates:
* Constant: '<S1>/Constant7'
* Switch: '<S1>/Switch1'
* Switch: '<S1>/Switch2'
*/
Vehicle_Turn_Status = 0;
}
/* End of Switch: '<S1>/Switch3' */
/* Outport: '<Root>/Outport' incorporates:
* Constant: '<S2>/Constant'
* Constant: '<S2>/Constant3'
* Constant: '<S2>/Constant4'
* Inport: '<Root>/CameraInput_RoadSign'
* Logic: '<S2>/AND'
* Logic: '<S2>/AND1'
* Logic: '<S2>/AND2'
* RelationalOperator: '<S2>/Relational Operator'
* RelationalOperator: '<S2>/Relational Operator1'
* RelationalOperator: '<S2>/Relational Operator2'
*/
Project_1_Y.Outport[0] = ((Vehicle_Turn_Status == RightTurn_RoadSign) &&
CameraInput_RoadSign);
Project_1_Y.Outport[1] = ((Vehicle_Turn_Status == LeftTurn_RoadSign) &&
CameraInput_RoadSign);
Project_1_Y.Outport[2] = ((Vehicle_Turn_Status == Straight_RoadSign) &&
CameraInput_RoadSign);
}
/* Model initialize function */
void Project_1_initialize(void)
{
/* (no initialization code required) */
}
/* Model terminate function */
void Project_1_terminate(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
Conclusion -
Thus the Simulink Model has been designed for Vehicle Direction Detection and a Simulink Data Dictionary has been created
along with Code generation of the Designed model.