Project 1 (Mini Project on Vehicle Direction Detection
MINI PROJECT - VEHICLE DIRECTION DETECTION
Aim:
To develop the MATLAB Simulink model for Vehicle Direction Detection as per the requirement.
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 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
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.
Procedure:
First set the model settings.

Goto model settings

Change the solver type to : Fixed-step. Solver to: discrete(no contionous states). Fixed-step size i.e, sample time to 0.01sec.

Change the system target selection file to: ert.tlc i.e Embedded Coder

Now we have to make the Simulink Data Dictionary(SLDD) file and we have to link it with our model.For that go to modeling and under repocitories select the Link to Data Dictionary option.

Now a window will open and rename your SLDD file.And disable the option for model access to base workshop.

Next goto model explorer click vehicle_direction under that there is option called Design data.Now we can enter the data in to the sldd file according to our requirements,and here the data to be entered is given in question.


We can add a simulink signal by selecting the Simulink Signal option.

There are four types of signals we are using in this model.
- Input Signal
- Output Signal
- Local Signal
- Calibration signal
For input signal set the storage class as Imported extern.For output signal set the storage class as Export to File.For local signal select it as Localizable.Local signals are signal that are neither inputs nor output signals. And for Calibration signals select the storage class as const.
Calibration signals are from the constant blocks.For this we have to select the Simulink Parameter option.

In this project we have 2 input signals,1 output signals,1 local signal, and 6 calibration signals.
Steering wheel input as yaw rate is an input signal which is compared against three angular values one for left turn,right turn,straight drive to say which direction the steering wheel is turning towards.Output of this requirement is a local signal which is Vehicle turn status.Camera Input road sign is an input signal from the camera which confirms the occurrence of a road sign.
The Data type,dimension,Complexity,Value,Minimum and maximum values,Unit,Storage class are defined in the SLDD file.
The following details are defined in the SLDD file.
The use of SLDD file is that when we define the signals in our model the characteristics and properties are assigned to these signals.


Requirement 1 subsystem:

Steering wheel input can have range varying from -180 to 180.
- If steering wheel input is greater than zero,the vehicle turn status will be right turn value
- If steering wheel input is equal to zero,the vehicle turn status will be straight drive value
- Otherwise,the vehicle turn status will be left turn value

- 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 subsystem:

Output from the requirement 1 subsystem is given as input in the requirement 2 subsystem. And camera input road sign is given here.
- Vehicle turn status is checked whether it is equal to either right turn value, left turn value, straight value or not if yes it relational operator gives 1 and it is logically multiplied with the value of camera input and this three outputs are combined using the multiplexer and given to the signal conversion block ,signal conversion block is nothing but a dummy block,it has no functions. And it is outputted.

- Keep this requirement as a separate subsystem. Inputs to this requirement are local signals 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 an output signal (Signal Name: Vehicle_Direction_Indicator)

These two requirements are combined into a new subsystem;

Signal resolving & Signal Propogating:
For signal resolving right click on subsystem and select the properties
Give the name of the signal and select the above shown option.

For signal propogating enter the signal name and select the show propogated signal option.
While signal propogation and signal resolving the port name and signal name must be the same. The signal resolving is done at the starting of the every signals and propagating is done for continuing signals.This is done for giving properties from the SLDD file to the signals.
Requirement tagging:
We can understand about a subsystem,how it works and what are its functionality only when the subsystem is tagged.This can be made by highlighting the heading of the requirement word document and after that select the requirements and click on the Link to selection in word.

Now we can see that the requirement tagging is done.

Model advisor in Simulink:
It is a tool that automatically checks the models for errors using the predefined checks.Here we can run the selected checks and know whether there are any errors,warnings,test pass. Here we are doing only the MAAB(Mathworks Automotive Advisory Board ) checks. To know whether this model is obeying the MAAB guidelines.
For that go to Model Advisor under modeling tab.

Select all and click ok.

These are the various tests offered.

Select only Modeling Standards for MAB;

And click Run the selected checks

We can see that there are total of 144checks, in that there are 135 passed and 9 warnings.

Model Advisor report:
Now we can generate the Model Advisor Report. The model advisor report named 'MAAB_Model_Advisor_Report' is attached in the zip file below.It is in the form of HTML document.

Code Generation:
Code generation is converting the simulink model into a C-code.For this select the Embedded Coder option under the Apps.

And click Build option.

The C-code is generated after few minutes.
The Generated C-code:

/*
* File: Vehicle_Direction.c
*
* Code generated for Simulink model 'Vehicle_Direction'.
*
* Model version : 1.8
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Sun May 15 01:18:49 2022
*
* 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"
/* 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: '/Constant1' */
const int16_T Left_Turn_AngularLimit = -120;/* Referenced by: '/Constant1' */
const int16_T RightTurn_RoadSign = 30; /* Referenced by: '/Constant' */
const int16_T Right_Turn_AngularLimit = 30;/* Referenced by: '/Constant2' */
const int16_T Straight_Drive_Steering_Angle = 0;/* Referenced by: '/Constant' */
const int16_T Straight_RoadSign = 0; /* Referenced by: '/Constant2' */
/* 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)
{
/* local block i/o variables */
int16_T Vehicle_Turn_Status;
/* Switch: '/Switch1' incorporates:
* Constant: '/Constant'
* Constant: '/Constant'
* Inport: '/SteeringWheel_YawDegreeInput'
* RelationalOperator: '/Compare'
* RelationalOperator: '/Compare'
* Switch: '/Switch'
*/
if (SteeringWheel_YawDegreeInput > 0) {
/* Switch: '/Switch1' incorporates:
* Constant: '/Constant2'
*/
Vehicle_Turn_Status = Right_Turn_AngularLimit;
} else if (SteeringWheel_YawDegreeInput == 0) {
/* Switch: '/Switch' incorporates:
* Constant: '/Constant'
* Switch: '/Switch1'
*/
Vehicle_Turn_Status = Straight_Drive_Steering_Angle;
} else {
/* Switch: '/Switch1' incorporates:
* Constant: '/Constant1'
* Switch: '/Switch'
*/
Vehicle_Turn_Status = Left_Turn_AngularLimit;
}
/* End of Switch: '/Switch1' */
/* SignalConversion: '/Signal_Conversion' incorporates:
* Constant: '/Constant'
* Constant: '/Constant1'
* Constant: '/Constant2'
* Inport: '/CameraInput_RoadSign'
* Logic: '/AND'
* Logic: '/AND1'
* Logic: '/AND2'
* 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);
}
/* 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]
*/
This generated code is pasted in the attachment named 'Vehicle_Direction.c'.
This C-code is flashed in to the hardware after MIL and SIL tests.
Performing the Model-In-Loop Tests and Software-In-Loop Tests:
For MIL and SIL tests perform the following operations.Right click the subsystem and select the Test Harness.


For MIL tests verification mode is Normal.


The signal builder block is fed with the test cases written in the excel sheet.

Perform the following operations:


Connect a demultiplexer block to demultiplex the three signals that is vehicle direction indicator which consists of right turn value,left turn value,straight. And sum blocks and scope for seeing whether there are any errors.

The scope outputs:

Here we can clearly see that there are no errors and error is zero.
Repeat the same procedure for SIL tests also:

Select the subsystem as atomic unit,set the sample time as 0.01sec.


select the Software-In-Loop verification mode.

Output:
Here we can see errors are zero.
We can see the two Internal Test Harnesses inside the subsystem.
Conclusion:
- Development of Adaptive Cruise Control (ACC) MBD compliant Simulink model as per the requirements specified.
- The developed ACC feature allows the host vehicle to adapt to the speed in line with the flow of traffic.
- Created Simulink Data Dictionary file for the Simulink model.
- Performed Requirement Tagging, Model Advisor tool check on the developed model for MAAB guidelines.
- Performed Model-In-Loop (MIL) and Software-In-Loop (SIL) tests to validate the developed model.
- Auto code generation through Embedded Coder tool in Simulink.