Project 1 (Mini Project on Vehicle Direction Detection
MINI PROJECT - VEHICLE DIRECTION DETERMINATION
About Vehicle direction determination
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:

Inside view:

Working of model (Subystem wise):
1. Vehicle_turn_logic

- 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).
2. Camerainput_Vehicleturn_logic

- 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 isa true signal (Signal Name: Vehicle_Direction_Indicator).
With that said about model, one can also learn more about it by checking the requirement as requirement tagging is done here. Right click on any subsytem<<Requirement<<select the first heading line that appears.
Creating data in Simulink data dictionary:
Path:Right click<< Model properties<< external data<<Browse(If already availabel) or New (if you want to create new sldd file)

Coverage analysis:
As our model is ready now we will do a coverage analysis of it to confirm that our logic can model implementation is right. We will also see the output using scope blog.
Inputs: Two repeating seuence blocks.
1) For yaw rate : [0 2 4 6 8 10] & [0 30 -120 30 0 -120]
2) For camera input: [0 2 4 6 8 10] & [0 1 1 1 0 0]
Ultimately this inputs are not part of the model this are only to do coverage analysis so that we can confirm that our logic serves the purpose


Hence this confirms that our model has the right implementation of the logic.
Coverage report snapshot:

Model advisor report snapshot:

Warning sign was deliberately hoped here to see the MAAB guidelines followed by our model. Hence can be rectified by updating the diagnostics option under model properties/configuration parameters.
Code Generation:
For code generation follow the below procedure:
Configuration parameters<<Code generation:
Select<<
System Target file: ert.tlc
Language: C
Check mark the build code.
Then press build icon (as shown below) to generate code:

Generated code:
/*
* File: Mini_proj_vdd.c
*
* Code generated for Simulink model 'Mini_proj_vdd'.
*
* Model version : 1.6
* Simulink Coder version : 9.3 (R2020a) 18-Nov-2019
* C/C++ source code generated on : Sat Oct 2 18:10:47 2021
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "Mini_proj_vdd.h"
#include "Mini_proj_vdd_private.h"
/* Exported data definition */
/* Const memory section */
/* Definition for custom storage class: Const */
const int16_T LeftTurn_RoadSign = -120;/* Referenced by: '<S2>/Constant1' */
const int16_T Left_Turn_AngularLimit = -120;
/* Referenced by: '<S3>/Left_Turn_AngularLimit' */
const int16_T RightTurn_RoadSign = 30; /* Referenced by: '<S2>/Constant' */
const int16_T Right_Turn_AngularLimit = 30;
/* Referenced by: '<S3>/Right_Turn_AngularLimit' */
const int16_T Straight_Drive_Steering_Angle = 0;
/* Referenced by: '<S3>/Straight_Drive_Steering_Angle' */
const int16_T Straight_RoadSign = 0; /* Referenced by: '<S2>/Constant2' */
/* External outputs (root outports fed by signals with default storage) */
ExtY_Mini_proj_vdd_T Mini_proj_vdd_Y;
/* Real-time model */
RT_MODEL_Mini_proj_vdd_T Mini_proj_vdd_M_;
RT_MODEL_Mini_proj_vdd_T *const Mini_proj_vdd_M = &Mini_proj_vdd_M_;
/* Model step function */
void Mini_proj_vdd_step(void)
{
int16_T rtb_Switch;
/* Switch: '<S3>/Switch' incorporates:
* Constant: '<S3>/Left_Turn_AngularLimit'
* Constant: '<S3>/Right_Turn_AngularLimit'
* Inport: '<Root>/SteeringWheel_YawDegreeInput '
* Switch: '<S3>/Switch1'
*/
if (SteeringWheel_YawDegreeInput >= 30) {
rtb_Switch = Right_Turn_AngularLimit;
} else if (SteeringWheel_YawDegreeInput >= 0) {
/* Switch: '<S3>/Switch1' incorporates:
* Constant: '<S3>/Straight_Drive_Steering_Angle'
*/
rtb_Switch = Straight_Drive_Steering_Angle;
} else {
rtb_Switch = Left_Turn_AngularLimit;
}
/* End of Switch: '<S3>/Switch' */
/* Outport: '<Root>/Vehicle_Direction_Indicator' incorporates:
* Constant: '<S2>/Constant'
* Constant: '<S2>/Constant1'
* Constant: '<S2>/Constant2'
* Inport: '<Root>/CameraInput_RoadSign'
* Logic: '<S2>/AND3'
* Logic: '<S2>/AND4'
* Logic: '<S2>/AND5'
* RelationalOperator: '<S2>/Equal'
* RelationalOperator: '<S2>/Equal1'
* RelationalOperator: '<S2>/Equal2'
*/
Mini_proj_vdd_Y.Vehicle_Direction_Indicator[0] = ((rtb_Switch ==
RightTurn_RoadSign) && CameraInput_RoadSign);
Mini_proj_vdd_Y.Vehicle_Direction_Indicator[1] = ((Straight_RoadSign ==
rtb_Switch) && CameraInput_RoadSign);
Mini_proj_vdd_Y.Vehicle_Direction_Indicator[2] = ((LeftTurn_RoadSign ==
rtb_Switch) && CameraInput_RoadSign);
}
/* Model initialize function */
void Mini_proj_vdd_initialize(void)
{
/* (no initialization code required) */
}
/* Model terminate function */
void Mini_proj_vdd_terminate(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
Hence we have sucessfully implementated the logic, created sldd file for datas, did coverage analysis to confirm, created model advisor report and generated the code.