Project 1 (Mini Project on Vehicle Direction Detection
Mini Project - Vehicle Direction Determination:-
AIM:-
Aim of the project is to develop a simulink model as per the given requirements in question and generate a Code using embedded coder and build a program to execute c program of the desired outputs.
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).
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 |
- |
- |
PROCEDURE:-
As per the question given in requirements 1 .
Created a model as shown below a subsystem with two inports and one outport.

Inside the subsystem create two subsystem as per the requirements 1 & 2 as shown below.

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).
By using the above points just created a model inside the subsystem Vehicle_turn_status_subsystem, Which as shown below.

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).
By using the above points just created a model in vehicle_direction_detection_subsystem,Which as shown below.

After completing model creation we need to assign values to the model.That can be done by using link to data dictionary under modeling tab.
After that need to create a new data dictionary as per the signals with values given in the question;

In the next step we can move to model settings by simply cliucking ctrl+E.
In model settings under solver selection - Type is to select fixed step solver ;& solver should be select to auto or discrete.

After solver settings we need to give code generation as :-
SYSTEM TARGET FILE IS TO :-ert.tlc Embedded coder .
TOOL CHAIN TO :- MinGW64.
then apply and ok.

Then give names to signal lines and select then to referance, resolve.

In the same give required signals to propogated signals. <sinal name >
Run the model with model adviser to check static error.

Model adviser test completed with no error then go to apps.
then finally check the model once again line by line for any mistakes then go to apps in top of simulink model window.

A new window will open select "build" option over there to generate code.

"C"code will be generated for the simulink model.




we can check codes by changing the directory of code .

Result:-
Thus The vehicle direction determination is modelled as per the requirement, all the signals are defined in Simulink data dictionary. All input and output signals are resolved and propagated Updated the model to check for static errors. Run the model advisor tool to see any errors. since there are no errors in Model Advisor Report. Code has been generated using Embedded Coder.
code for "direction_detection.c"
/*
* File: direction_detection.c
*
* Code generated for Simulink model 'direction_detection'.
*
* Model version : 1.9
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Wed Jan 12 22:56:50 2022
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "direction_detection.h"
#include "direction_detection_private.h"
/* Exported data definition */
/* Const memory section */
/* Definition for custom storage class: Const */
const int16_T Left_Turn_Angularlimit = -120;
/* Referenced by: '<S3>/Left_Turn_Angularlimit' */
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' */
/* External outputs (root outports fed by signals with default storage) */
ExtY_direction_detection_T direction_detection_Y;
/* Real-time model */
static RT_MODEL_direction_detection_T direction_detection_M_;
RT_MODEL_direction_detection_T *const direction_detection_M =
&direction_detection_M_;
/* Model step function */
void direction_detection_step(void)
{
/* local block i/o variables */
int16_T Vehicle_Turn_Status;
/* Switch: '<S3>/Switch' incorporates:
* Inport: '<Root>/Streeringwheel_YawDegreeInput'
* Switch: '<S3>/Switch1'
*/
if (Streeringwheel_YawDegreeInput > 25) {
/* Switch: '<S3>/Switch' incorporates:
* Constant: '<S3>/Right_Turn_Angularlimit'
*/
Vehicle_Turn_Status = Right_Turn_Angularlimit;
} else if (Streeringwheel_YawDegreeInput > 0) {
/* Switch: '<S3>/Switch1' incorporates:
* Constant: '<S3>/Straight_Drive_Steering_Angle'
* Switch: '<S3>/Switch'
*/
Vehicle_Turn_Status = Straight_Drive_Steering_Angle;
} else {
/* Switch: '<S3>/Switch' incorporates:
* Constant: '<S3>/Left_Turn_Angularlimit'
* Switch: '<S3>/Switch1'
*/
Vehicle_Turn_Status = Left_Turn_Angularlimit;
}
/* End of Switch: '<S3>/Switch' */
/* Outport: '<Root>/Vehicle_Direction_Indicator' incorporates:
* Inport: '<Root>/CameraInput_RoadSign'
* Logic: '<S2>/AND'
* Logic: '<S2>/AND1'
* Logic: '<S2>/AND2'
* Logic: '<S2>/OR'
* RelationalOperator: '<S2>/Equal'
* RelationalOperator: '<S2>/Equal1'
* RelationalOperator: '<S2>/Equal2'
*/
direction_detection_Y.Vehicle_Direction_Indicator = ((CameraInput_RoadSign &&
(Vehicle_Turn_Status == 30)) || (CameraInput_RoadSign &&
(Vehicle_Turn_Status == -120)) || (CameraInput_RoadSign &&
(Vehicle_Turn_Status == 0)));
}
/* Model initialize function */
void direction_detection_initialize(void)
{
/* (no initialization code required) */
}
/* Model terminate function */
void direction_detection_terminate(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
`code for "direction_detection.h"
/*
* File: direction_detection.h
*
* Code generated for Simulink model 'direction_detection'.
*
* Model version : 1.9
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Wed Jan 12 22:56:50 2022
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#ifndef RTW_HEADER_direction_detection_h_
#define RTW_HEADER_direction_detection_h_
#ifndef direction_detection_COMMON_INCLUDES_
#define direction_detection_COMMON_INCLUDES_
#include "rtwtypes.h"
#endif /* direction_detection_COMMON_INCLUDES_ */
#include "direction_detection_types.h"
/* Macros for accessing real-time model data structure */
#ifndef rtmGetErrorStatus
#define rtmGetErrorStatus(rtm) ((rtm)->errorStatus)
#endif
#ifndef rtmSetErrorStatus
#define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val))
#endif
/* External outputs (root outports fed by signals with default storage) */
typedef struct {
boolean_T Vehicle_Direction_Indicator;
/* '<Root>/Vehicle_Direction_Indicator' */
} ExtY_direction_detection_T;
/* Real-time Model Data Structure */
struct tag_RTM_direction_detection_T {
const char_T * volatile errorStatus;
};
/* External outputs (root outports fed by signals with default storage) */
extern ExtY_direction_detection_T direction_detection_Y;
/* Model entry point functions */
extern void direction_detection_initialize(void);
extern void direction_detection_step(void);
extern void direction_detection_terminate(void);
/* Exported data declaration */
/* Const memory section */
/* Declaration for custom storage class: Const */
extern const int16_T Left_Turn_Angularlimit;
/* Referenced by: '<S3>/Left_Turn_Angularlimit' */
extern const int16_T Right_Turn_Angularlimit;
/* Referenced by: '<S3>/Right_Turn_Angularlimit' */
extern const int16_T Straight_Drive_Steering_Angle;
/* Referenced by: '<S3>/Straight_Drive_Steering_Angle' */
/* Real-time Model object */
extern RT_MODEL_direction_detection_T *const direction_detection_M;
/*-
* The generated code includes comments that allow you to trace directly
* back to the appropriate location in the model. The basic format
* is <system>/block_name, where system is the system number (uniquely
* assigned by Simulink) and block_name is the name of the block.
*
* Use the MATLAB hilite_system command to trace the generated code back
* to the model. For example,
*
* hilite_system('<S3>') - opens system 3
* hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
*
* Here is the system hierarchy for this model
*
* '<Root>' : 'direction_detection'
* '<S1>' : 'direction_detection/Subsystem'
* '<S2>' : 'direction_detection/Subsystem/Vehicle_Direction_Indicator_Subsystem'
* '<S3>' : 'direction_detection/Subsystem/Vehicle_Turn_Status_Subsystem'
*/
#endif /* RTW_HEADER_direction_detection_h_ */
/*
* File trailer for generated code.
*
* [EOF]
*/
NOTE:-
CODE GENERATION FILE FOLDER IS CONVERTED INTO ZIP FILE AND UPLOADED HERE.