Project 1 (Mini Project on Vehicle Direction Detection
Project -1 Vehicle Direction Determination
Aim: To identify the direction of vehicle based on steering and camera inputs
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
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 |
|
Min |
Max |
Initial Value |
Unit |
||
|
SteeringWheel_YawDegreeInput |
Input |
Int16 |
1 |
-180 |
180 |
- |
deg |
||
|
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 |
deg |
||
|
LeftTurn_RoadSign |
Calibration |
Int16 |
[1 1] |
-180 |
180 |
-120 |
deg |
||
|
Straight_RoadSign |
Calibration |
Int16 |
[1 1] |
-180 |
180 |
0 |
deg |
||
|
Vehicle_Direction_Indicator |
Output |
Boolean |
3 |
0 |
1 |
- |
- |
Solution:
In the given project, we have been tasked to determine the direction of a vehicle based on inputs from the camera and the steering wheel. Two requirements have been provided and our model needs to satisfy both of them.
Firstly, we begin by defining the data dictionary for the signals to be used. For it, we follow:
Modeling->Model properties->Click on New->Name the SLDD and save it
After creating the SLDD, we add all the signals to it as per the given details. Next, we move on to building the model. According to the given requirements, it is clear that the model should have two subsystems, corresponding to the two given requirements. Heading to the first requirement, steering wheel input is the only input to this system. This input is to be compared against three values for the left, right and straight angular limits. This can be done using the compare to constant blocks. Corresponding to the outputs of the given comparators, only the true conditions should pass through the subsystem as outputs. For it, the switch block is used. Here the multiport switch is used for better feasibility. The output of the subsystem would thus be the vehicle turn status, indicating in which direction the vehicle is moving based on the steering wheel yaw degree input. The subsystem can thus be modelled as:


Next, we move on to requirement no 2. For this also there would be a separate subsystem and the output of the first subsystem (i.e. the vehicle turn status) alongwith the camera inputs (regarding the road signs) are fed as inputs to the system. The turn status is compared against the road sign and then is verified against the camera input. If the camera input is available, then based on the input and the turn status, our system will prompt the user as to what action needs to be taken. The second subsystem can thus be modelled as:


SLDD:

Model:


Requirement Tagging:


Also, code can be generated for this model. The steps to be followed for it are:
In Model Settings, under the Code generation section select the target file as Embedded coder. Then
Go to Apps-> Embedded Coder-> New C-Code tab will appear -> Build
The code will be generated. For our model the generated code is as:
/*
* File: Veh_Direction_Detection.c
*
* Code generated for Simulink model 'Veh_Direction_Detection'.
*
* Model version : 1.45
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Mon Nov 21 10:30:12 2022
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "Veh_Direction_Detection.h"
#include "Veh_Direction_Detection_private.h"
/* Exported data definition */
/* Const memory section */
/* Definition for custom storage class: Const */
const int16_T LeftTurn_RoadSign = -120;/* Referenced by:
* '/Constant'
* '/Constant'
*/
const int16_T Left_Turn_AngularLimit = -120;/* Referenced by:
* '/Constant5'
* '/Constant'
*/
const int16_T RightTurn_RoadSign = 30; /* Referenced by:
* '/Constant'
* '/Constant'
*/
const int16_T Right_Turn_AngularLimit = 30;/* Referenced by:
* '/Constant4'
* '/Constant'
*/
const int16_T Straight_Drive_Steering_Angle = 0;/* Referenced by: '/Constant6' */
const int16_T Straight_RoadSign = 0; /* Referenced by: '/Constant' */
/* Block signals (default storage) */
B_Veh_Direction_Detection_T Veh_Direction_Detection_B;
/* External inputs (root inport signals with default storage) */
ExtU_Veh_Direction_Detection_T Veh_Direction_Detection_U;
/* External outputs (root outports fed by signals with default storage) */
ExtY_Veh_Direction_Detection_T Veh_Direction_Detection_Y;
/* Real-time model */
static RT_MODEL_Veh_Direction_Detect_T Veh_Direction_Detection_M_;
RT_MODEL_Veh_Direction_Detect_T *const Veh_Direction_Detection_M =
&Veh_Direction_Detection_M_;
/* Model step function */
void Veh_Direction_Detection_step(void)
{
int32_T tmp;
int16_T rtb_Vehicle_Turn_Status;
boolean_T rtb_Compare_l;
boolean_T rtb_Compare_o;
/* Switch: '/Switch2' incorporates:
* Constant: '/Left_Turn'
* Constant: '/Straight_Drive'
* Constant: '/Constant'
* Constant: '/Constant'
* Inport: '/SteeringWheel_YawDegreeInput'
* RelationalOperator: '/Compare'
* RelationalOperator: '/Compare'
* Switch: '/Switch'
*/
if (Veh_Direction_Detection_U.SteeringWheel_YawDegreeInput <=
Left_Turn_AngularLimit) {
tmp = 2;
} else if (Veh_Direction_Detection_U.SteeringWheel_YawDegreeInput >=
Right_Turn_AngularLimit) {
/* Switch: '/Switch' incorporates:
* Constant: '/Right_Turn'
*/
tmp = 1;
} else {
tmp = 3;
}
/* End of Switch: '/Switch2' */
/* MultiPortSwitch: '/Multiport Switch' incorporates:
* Constant: '/Constant4'
* Constant: '/Constant5'
* Constant: '/Constant6'
*/
switch (tmp) {
case 1:
rtb_Vehicle_Turn_Status = Right_Turn_AngularLimit;
break;
case 2:
rtb_Vehicle_Turn_Status = Left_Turn_AngularLimit;
break;
default:
rtb_Vehicle_Turn_Status = Straight_Drive_Steering_Angle;
break;
}
/* End of MultiPortSwitch: '/Multiport Switch' */
/* RelationalOperator: '/Compare' incorporates:
* Constant: '/Constant'
*/
rtb_Compare_l = (rtb_Vehicle_Turn_Status >= RightTurn_RoadSign);
/* Outputs for Enabled SubSystem: '/Right_Turn' incorporates:
* EnablePort: '/Enable'
*/
if (rtb_Compare_l) {
/* Merge: '/Merge' incorporates:
* Constant: '/Constant'
* Inport: '/CameraInput_RoadSign'
* Logic: '/AND'
* RelationalOperator: '/Compare'
*/
Veh_Direction_Detection_B.Merge = ((rtb_Vehicle_Turn_Status >=
RightTurn_RoadSign) && Veh_Direction_Detection_U.CameraInput_RoadSign);
}
/* End of Outputs for SubSystem: '/Right_Turn' */
/* RelationalOperator: '/Compare' incorporates:
* Constant: '/Constant'
*/
rtb_Compare_o = (rtb_Vehicle_Turn_Status <= LeftTurn_RoadSign);
/* Outputs for Enabled SubSystem: '/Left_Turn' incorporates:
* EnablePort: '/Enable'
*/
if (rtb_Compare_o) {
/* Merge: '/Merge' incorporates:
* Constant: '/Constant'
* Inport: '/CameraInput_RoadSign'
* Logic: '/AND'
* RelationalOperator: '/Compare'
*/
Veh_Direction_Detection_B.Merge = ((rtb_Vehicle_Turn_Status <=
LeftTurn_RoadSign) && Veh_Direction_Detection_U.CameraInput_RoadSign);
}
/* End of Outputs for SubSystem: '/Left_Turn' */
/* Outputs for Enabled SubSystem: '/Straight_Drive' incorporates:
* EnablePort: '/Enable'
*/
/* Logic: '/AND' incorporates:
* Logic: '/NOT'
* Logic: '/NOT1'
*/
if ((!rtb_Compare_l) && (!rtb_Compare_o)) {
/* Merge: '/Merge' incorporates:
* Constant: '/Constant'
* Inport: '/CameraInput_RoadSign'
* Logic: '/AND'
* RelationalOperator: '/Compare'
*/
Veh_Direction_Detection_B.Merge = ((rtb_Vehicle_Turn_Status ==
Straight_RoadSign) && Veh_Direction_Detection_U.CameraInput_RoadSign);
}
/* End of Logic: '/AND' */
/* End of Outputs for SubSystem: '/Straight_Drive' */
/* Outport: '/Vehicle_Direction_Indicator' */
Veh_Direction_Detection_Y.Vehicle_Direction_Indicator =
Veh_Direction_Detection_B.Merge;
}
/* Model initialize function */
void Veh_Direction_Detection_initialize(void)
{
/* (no initialization code required) */
}
/* Model terminate function */
void Veh_Direction_Detection_terminate(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
Outputs:


When the camera input is available, 'True' state persists and the system prompts the user with the corresponding suggestions regarding the action to be taken.


When the camera input isn't available, 'False' state persists and the system doesnot prompt the user.
Reference:
MATLAB Documentation