Project 1 (Mini Project on Vehicle Direction Detection)
AIM: To create a Simulink model for vehicle direction determination:
Genereal 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 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 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.

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 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
Blocks used in this model:
- Relational operator
- Switch
- Constant block
- Logical operator
- From & go to tag scope.
General requirements to build this model:
In this model, there are two requirements provided so I have to build my model with respect to the 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 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_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 outputs is compared against the camera input signal,
- Using a logical operator block, only one among them is finally given as the output signal (Signal Name: Vehicle_Direction_Indicator).
Test cases:
|
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 |
- |
- |
Model :
- To explain this simulink model by step by step process.
- Create the ssld file to update the variables.
- Design a model based on the requirements.
- To do the SIL & MIL test and explain the process.
- To test the model in MAB guidance and try to rectify the errors.
Step-1
- To Create a sldd file to update all the given inputs, outputs & parameters on this file later calling these variables on the Simulink blocks are shown in the fig.

Step-2 Resolve and propagation:
- In this case, we have updated our signals inputs in the sldd file so we have to add the signal into the connection lines to get the proper output.
- So, we have used the resolve and propagation method on this model
Steps to get resolve and propagate signals.
- once right-click the line a popup window can be opened select properties option to open the resolve and propagate option.


- In that window, we may type the required input signals which is updated in the ssld file and select the resolve option to resolve the signal.

- In that window, we may type the required input signals which is updated in the ssld file and select the propagate option to propagate the signal.
Step-3
Model explanation:

- First I can create two sub-systems and name as requirement-1 & requirement-2
Requirement-1 subsystem:
- 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 & the output of this requirement is a local signal (Signal Name: Vehicle_Turn_Status).

- As per the requirements, 1 can design this model, when the steering yaw degree is considered as input is connected to the relational operator and the relational operator is connected with the switch based on the if-else condition the switch is given the output as a boolean number.
- For eg if I'm given -120 deg as input means when the relation operator checks the given input once it fails means its automatically switch the false statement when the false statement is connected to the left-turn_drive so the the switch given the output the left-turn value.
Requirment:2 Subsystem:
- 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 outputs is compared against the camera input signal,
- Using a logical operator block, only one among them is finally given as the output signal (Signal Name: Vehicle_Direction_Indicator).

- As per requirement statement-2 i have to compare the vehicle turn status and the camera sign once is true means the vehicle can conclude the turn is based on the road sign.
- So, i have to taken the vehicle turn status as input and it would be given to the relational operator which is the road sign is compared with the vehicle turn status.
- and i use the and gate which is used to given the any one output to the mux at a time for if left turn status is true means right turn and straight turn will be fale so that's why I'm using the And gate in this subsytem.
- The basic objective of the subsystem is to comape the vehicle turn status with the road sign.
Step-4 Generating codes without SIL testing process:
- After completion of the model we have generate the required code without Done the SIL test.
- Select the apps option which is available on the top the Simulink window then select the embedded code option to generate the code are shown below.


/*
* File: mini_project_1.c
*
* Code generated for Simulink model 'mini_project_1'.
*
* Model version : 1.7
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Fri May 27 16:16:08 2022
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "mini_project_1.h"
#include "mini_project_1_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: '/Constant3' */
const int16_T RightTurn_RoadSign = 30; /* Referenced by: '/Constant' */
const int16_T Right_Turn_AngularLimit = 30;/* Referenced by: '/Constant1' */
const int16_T Straight_Drive_Steering_Angle = 0;/* Referenced by: '/Constant2' */
const int16_T Straight_RoadSign = 0; /* Referenced by: '/Constant1' */
/* Real-time model */
static RT_MODEL_mini_project_1_T mini_project_1_M_;
RT_MODEL_mini_project_1_T *const mini_project_1_M = &mini_project_1_M_;
/* Model step function */
void mini_project_1_step(void)
{
/* local block i/o variables */
int16_T Vehicle_Turn_Status;
/* Outputs for Atomic SubSystem: '/Requirments' */
/* Switch: '/Switch' incorporates:
* Constant: '/Constant'
* Constant: '/Constant'
* Inport: '/SteeringWheel_YawDegreeInput'
* RelationalOperator: '/Compare'
* RelationalOperator: '/Compare'
* Switch: '/Switch1'
*/
if (SteeringWheel_YawDegreeInput > 0) {
/* Switch: '/Switch' incorporates:
* Constant: '/Constant1'
*/
Vehicle_Turn_Status = Right_Turn_AngularLimit;
} else if (SteeringWheel_YawDegreeInput == 0) {
/* Switch: '/Switch1' incorporates:
* Constant: '/Constant2'
* Switch: '/Switch'
*/
Vehicle_Turn_Status = Straight_Drive_Steering_Angle;
} else {
/* Switch: '/Switch' incorporates:
* Constant: '/Constant3'
* Switch: '/Switch1'
*/
Vehicle_Turn_Status = Left_Turn_AngularLimit;
}
/* End of Switch: '/Switch' */
/* SignalConversion: '/Signal Conversion' incorporates:
* Constant: '/Constant'
* Constant: '/Constant1'
* Constant: '/Constant2'
* Inport: '/CameraInput_RoadSign'
* Logic: '/AND'
* Logic: '/AND1'
* Logic: '/AND3'
* 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);
/* End of Outputs for SubSystem: '/Requirments' */
}
/* Model initialize function */
void mini_project_1_initialize(void)
{
/* (no initialization code required) */
}
/* Model terminate function */
void mini_project_1_terminate(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
- After completion of this process, code is generated gradually can shown the above fig.
Step-5 : To conclude the variant test process:
- In this project, I have done 2 test cases MIL (model in loop test) & SIL(software in loop test).
- Before doing this test have to change the atomic unit and solver to gather my results.



Requirement Tagging:
- In this project, I can update my project details and block explanation in ms word which attach with this model hereafter anyone is able to know the definition and requirements of the block means just simply click the requirement option to Simulink and automatically open the ms word file and highlight the paragraph or points.
- Make sure while doing this requirement process your ms word application should be open.

- Once we right-click the subsystem then select the requirments option select the link to word or excel with our comfortable are shown above the fig.
Model in loop testing:
- In this project, I can perform the MIL test to check the behavior of my model.

- To right, the subsystem to select the test harness and select the create option are shown above pic.
- After selecting this a pop-up display can open and ask for the inputs and output.
- In this case, I can give the inputs through the signal builder so, I can select the signal builder option and display the output as a graphical representation. so I can select the scope are shown in the below fig.
-

Model test:
- After selecting the required options a new pop-up simulink display can be opened, in that window we have to stimulate our model with the process of MIL test and analyze the result.

- As per the test harness option selection, a signal-builder and scope results can be obtained, so I can create another scope to analyze the output with input
- The input can be imported from excel to the signal builder block are shown below.


MiL Results Explanation:
Scope:

- As per the scope result when 0 to 1 seconds the right condition is true.
- And the 1 to 2 seconds left side turn is true and 2 to 3 seconds is straight turn is true
- As per the model design, we can achieve the correct scope results can be mentioned below.
Scope-2
- For more understanding of the results I can create another scope which is compacted with scope 1 and signal builder input at the same time it gives the same results so, I can subtract both values so if I got 0 values so I can assume my model is correct fig are shown below.

SIL (software in loop) Test:
- In this project, I can perform the SIL test to check the behavior of my model.

- To right, the subsystem to select the test harness and select the create option are shown above pic.
- After selecting this a pop-up display can open and ask for the inputs and output.
- In this case, I can give the inputs through the signal builder so, I can select the signal builder option and display the output as a graphical representation. so I can select the scope are shown in the below fig.

- After selecting the advanced option and change the op

SIL testing analysis:

- As per the test harness option selection, a signal-builder and scope results can be obtained, so I can create another scope to analyze the output with input
- The input can be imported from excel to the signal builder block are shown below.


SIL test Results Explanation:
Scope:

- As per the scope result when 0 to 1 seconds the right condition is true.
- And the 1 to 2 seconds left side turn is true and 2 to 3 seconds is straight turn is true
- As per the model design, we can achieve the correct scope results can be mentioned below.
Scope-2
- For more understanding of the results I can create another scope which is compacted with scope 1 and signal builder input at the same time it gives the same results so, I can subtract both values so if I got 0 values so I can assume my model is correct fig are shown below.

Code-generation:
- Once we complete the SIL test automatically it will generate the C-code for that and it would be stored in the respective folder can show the below fig.



- Once we call the MatLab window, we can take a look into the subsystem.c file shows the generated code in the MatLab window are shown in above fig.
Step-6: Model advisor
- A model advisor is a tool that automatically checks the model for errors using pre-defined checks.
- Model advisor as a tool is available in the core Simulink block set that automatically enables the user to check for common modeling mistakes which we miss out to notice during model development.
- The model advisor can analyze the entire model or a sub-set of the model. Upon selecting the model advisor option as shown below, the developer can choose which version he would like to test.

- After clicking this model adviser a new window can be opened in that window we can de-select all the guidance we can select the MAB guidence.

- If we press the run button which is mentioned in the above fig. after analyzing all the blocks it shows the results as no of pass, no of fail, and no of warnings.
- After that, we have to generate the report for that and it the report can explain our model very clearly can shown below fig.

Step-7 : Requirement Tagging:
- In this project, I can update my project details and block explanation in ms word which attach with this model hereafter anyone is able to know the definition and requirements of the block means just simply click the requirement option to Simulink and automatically open the ms word file and highlight the paragraph or points.
- Make sure while doing this requirement process your ms word application should be open.

- Once we right-click the subsystem then select the requirements option and select the link to the word or excel with our comfortable are shown above the fig.
- After linking the requirements with the word we have to check the requirements.


- Once we select the requirement 2 I can check the word when the requirement can be highlighted
- Mayur Salunkhevery nice explanation