Challenge

Project 1 (Mini Project on Vehicle Direction Detection

Mini Project - Vehicle Direction Determination

Aim:

The aim of the "Vehicle Direction Determination" mini-project is to develop a MATLAB Simulink model that can identify the direction a vehicle is taking based on steering wheel input and camera-detected road signs. The project focuses on creating a model that determines whether the vehicle is turning left, right, or continuing straight. It then verifies if the vehicle's movement aligns with the road signs, ultimately providing a direction indicator to the driver.

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_Signal 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).

Objectives of the project:

  1. Development of MATLAB Simulink model as per requirement.
  2. Tag the requirements to the simulink model; tagging requirement 1 & requirement 2 to their corresponding subsystems is fine.
  3. MBD compliant changes, Data Dictionary creation & code generation is added advantage, and that is not scope of this project.
  4. 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.
  5. Choose sample time for all signals as 0.01s

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

-

-

Simulink model:

  1. Traffic_assist.slx

SLDD_file:

The SLDD_file is created to store the calibration values and input and output signals.

  1. Trffic_assist.sldd
  2. sldd.png

Blocks used:

Blocks used to create a model are

Input Blocks: To provide the input signals

Output Blocks: To send the output signals

Constant Blocks: To define the calibration values

Logical operator Blocks: OR blocks are used to compare and the road signs with camera input and to get the boolean output.

Switch Blocks: To compare the input with the calibration values.

Mux Block: To combile the signals

Display Block: To display the results

Procedure:

The logic in the Requirement_1 is, If the input is >=30 (because the initial value is 30) the vehicle will take the Right turn, else If the input is less than zero (<0) the vehicle left_turn, else stright_drive (if the input is equal to zero).

The input yaw rate is given to the middle port of the switch, and the threshold value is 30. If the input is greater than threshold value then the switch will takes the True condition (Right_Turn_AngularLimit) else false condition. In the second switch the threshold value is zero, if the threshold value is not equal to zero then the switch will takes the true condition (Left_Turn_AngularLimit) else takes the false condition (Sitight_Drive steering_Angle). This output from the second switch is given as a false condition to the first switch. And the output for the Requirement_1 is "Vehicle_Turn_Status".

The logic in the Requirement_2 is to compare the "Vehicle_Turn_Status" (Output of Requirement_1) with "RoadSign" and an input signal from camera to get the Vehicle Direction indicaton.

After comparision with "Vehicle_Turn_Status" if each of them is found equal, then each of the three corresponding output is compared against the camera input signal, by using the 'logical OR' Blocks will get the true case and to take only one among them as output, the 'Mux' block is used.

And the final output from the Vehicle_Detection Model will indicates the vehicle_Direction indication.

Next by adding the SLDD_file to the model and by loading the calibration values and input/output values are defined.

By running the simulation will get the vehicle direction.

Results:

  • The signs are in the way that Right, Left and Straight respectively.
  • As the output is boolean, If we get the output as (0,0,1), Then the vehicle is moving in the straight drive.
  • If the output as (1,0,0), Then the vehicle is taking in the Right turn.
  • If the output is (0,1,0), Then the vehicle is taking the Left turn.
  • After running the simulation, we can clearly see that the vehicle is moving the straight direction
  • For the out please refer the files Bellow.

  1. straight_drive.png
  2. Right_turn.png
  3. Left_turn.png

MODEL ADVISOR

Get a Model Advisor Check>by task>ony check modelling standards with MAB>Run selected checks

  1. model_advisor.png

CODE GENERATION

/*

* Traffic_assist.c

*

* Trial License - for use to evaluate programs for possible purchase as

* an end-user only.

*

* Code generation for model "Traffic_assist".

*

* Model version : 1.5

* Simulink Coder version : 24.2 (R2024b) 21-Jun-2024

* C source code generated on : Tue Oct 15 09:30:49 2024

*

* Target selection: grt.tlc

* Note: GRT includes extra infrastructure and instrumentation for prototyping

* Embedded hardware selection: Intel->x86-64 (Windows64)

* Code generation objectives: Unspecified

* Validation result: Not run

*/

#include "Traffic_assist.h"

#include "rtwtypes.h"

#include <string.h>

#include "Traffic_assist_private.h"

/* Block signals (default storage) */

B_Traffic_assist_T Traffic_assist_B;

/* External outputs (root outports fed by signals with default storage) */

ExtY_Traffic_assist_T Traffic_assist_Y;

/* Real-time model */

static RT_MODEL_Traffic_assist_T Traffic_assist_M_;

RT_MODEL_Traffic_assist_T *const Traffic_assist_M = &Traffic_assist_M_;

/* Model step function */

void Traffic_assist_step(void)

{

boolean_T rtb_AND1;

/* Switch: '<S3>/Switch' incorporates:

* Inport: '<Root>/SteeringWheel_YawDegreeInput'

* Switch: '<S3>/Switch1'

*/

if (SteeringWheel_YawDegreeInput >= Traffic_assist_P.Switch_Threshold) {

/* Switch: '<S3>/Switch' incorporates:

* Constant: '<S3>/Right_Turn_AngularLimit'

*/

Traffic_assist_B.Vehicle_Turn_Status =

Traffic_assist_P.Right_Turn_AngularLimit_Value;

} else if (SteeringWheel_YawDegreeInput >= Traffic_assist_P.Switch1_Threshold)

{

/* Switch: '<S3>/Switch1' incorporates:

* Constant: '<S3>/Straight_Drive_Steering_Angle'

* Switch: '<S3>/Switch'

*/

Traffic_assist_B.Vehicle_Turn_Status =

Traffic_assist_P.Straight_Drive_Steering_Angle_V;

} else {

/* Switch: '<S3>/Switch' incorporates:

* Constant: '<S3>/Left_Turn_AngularLimit'

*/

Traffic_assist_B.Vehicle_Turn_Status =

Traffic_assist_P.Left_Turn_AngularLimit_Value;

}

/* End of Switch: '<S3>/Switch' */

/* RelationalOperator: '<S2>/Equal1' incorporates:

* Constant: '<S2>/LeftTurn_RoadSign'

*/

rtb_AND1 = (Traffic_assist_B.Vehicle_Turn_Status ==

Traffic_assist_P.LeftTurn_RoadSign_Value);

/* Logic: '<S2>/AND1' incorporates:

* Inport: '<Root>/CameraInput_RoadSign'

*/

rtb_AND1 = (rtb_AND1 && CameraInput_RoadSign);

/* SignalConversion: '<Root>/Signal Conversion' incorporates:

* Constant: '<S2>/RightTurn_RoadSign'

* Constant: '<S2>/Straight_RoadSign'

* Inport: '<Root>/CameraInput_RoadSign'

* Logic: '<S2>/AND'

* Logic: '<S2>/AND2'

* RelationalOperator: '<S2>/Equal'

* RelationalOperator: '<S2>/Equal2'

*/

Traffic_assist_B.Vehicle_Direction_Indicator[0] =

((Traffic_assist_B.Vehicle_Turn_Status ==

Traffic_assist_P.RightTurn_RoadSign_Value) && CameraInput_RoadSign);

Traffic_assist_B.Vehicle_Direction_Indicator[1] = rtb_AND1;

Traffic_assist_B.Vehicle_Direction_Indicator[2] =

((Traffic_assist_B.Vehicle_Turn_Status ==

Traffic_assist_P.Straight_RoadSign_Value) && CameraInput_RoadSign);

/* Outport: '<Root>/Vehicle_Direction_Indicator' incorporates:

* SignalConversion: '<Root>/Signal Conversion'

*/

Traffic_assist_Y.Vehicle_Direction_Indicator[0] =

Traffic_assist_B.Vehicle_Direction_Indicator[0];

Traffic_assist_Y.Vehicle_Direction_Indicator[1] =

Traffic_assist_B.Vehicle_Direction_Indicator[1];

Traffic_assist_Y.Vehicle_Direction_Indicator[2] =

Traffic_assist_B.Vehicle_Direction_Indicator[2];

/* Matfile logging */

rt_UpdateTXYLogVars(Traffic_assist_M->rtwLogInfo,

(&Traffic_assist_M->Timing.taskTime0));

/* signal main to stop simulation */

{ /* Sample time: [180.0s, 0.0s] */

if ((rtmGetTFinal(Traffic_assist_M)!=-1) &&

!((rtmGetTFinal(Traffic_assist_M)-Traffic_assist_M->Timing.taskTime0) >

Traffic_assist_M->Timing.taskTime0 * (DBL_EPSILON))) {

rtmSetErrorStatus(Traffic_assist_M, "Simulation finished");

}

}

/* Update absolute time for base rate */

/* The "clockTick0" counts the number of times the code of this task has

* been executed. The absolute time is the multiplication of "clockTick0"

* and "Timing.stepSize0". Size of "clockTick0" ensures timer will not

* overflow during the application lifespan selected.

* Timer of this task consists of two 32 bit unsigned integers.

* The two integers represent the low bits Timing.clockTick0 and the high bits

* Timing.clockTickH0. When the low bit overflows to 0, the high bits increment.

*/

if (!(++Traffic_assist_M->Timing.clockTick0)) {

++Traffic_assist_M->Timing.clockTickH0;

}

Traffic_assist_M->Timing.taskTime0 = Traffic_assist_M->Timing.clockTick0 *

Traffic_assist_M->Timing.stepSize0 + Traffic_assist_M->Timing.clockTickH0 *

Traffic_assist_M->Timing.stepSize0 * 4294967296.0;

}

/* Model initialize function */

void Traffic_assist_initialize(void)

{

/* Registration code */

/* initialize real-time model */

(void) memset((void *)Traffic_assist_M, 0,

sizeof(RT_MODEL_Traffic_assist_T));

rtmSetTFinal(Traffic_assist_M, 180.0);

Traffic_assist_M->Timing.stepSize0 = 180.0;

/* Setup for data logging */

{

static RTWLogInfo rt_DataLoggingInfo;

rt_DataLoggingInfo.loggingInterval = (NULL);

Traffic_assist_M->rtwLogInfo = &rt_DataLoggingInfo;

}

/* Setup for data logging */

{

rtliSetLogXSignalInfo(Traffic_assist_M->rtwLogInfo, (NULL));

rtliSetLogXSignalPtrs(Traffic_assist_M->rtwLogInfo, (NULL));

rtliSetLogT(Traffic_assist_M->rtwLogInfo, "tout");

rtliSetLogX(Traffic_assist_M->rtwLogInfo, "");

rtliSetLogXFinal(Traffic_assist_M->rtwLogInfo, "");

rtliSetLogVarNameModifier(Traffic_assist_M->rtwLogInfo, "rt_");

rtliSetLogFormat(Traffic_assist_M->rtwLogInfo, 4);

rtliSetLogMaxRows(Traffic_assist_M->rtwLogInfo, 0);

rtliSetLogDecimation(Traffic_assist_M->rtwLogInfo, 1);

rtliSetLogY(Traffic_assist_M->rtwLogInfo, "");

rtliSetLogYSignalInfo(Traffic_assist_M->rtwLogInfo, (NULL));

rtliSetLogYSignalPtrs(Traffic_assist_M->rtwLogInfo, (NULL));

}

/* block I/O */

{

Traffic_assist_B.Vehicle_Turn_Status = 0;

Traffic_assist_B.Vehicle_Direction_Indicator[0] = false;

Traffic_assist_B.Vehicle_Direction_Indicator[1] = false;

Traffic_assist_B.Vehicle_Direction_Indicator[2] = false;

}

/* external outputs */

(void)memset(&Traffic_assist_Y, 0, sizeof(ExtY_Traffic_assist_T));

/* Matfile logging */

rt_StartDataLoggingWithStartTime(Traffic_assist_M->rtwLogInfo, 0.0,

rtmGetTFinal(Traffic_assist_M), Traffic_assist_M->Timing.stepSize0,

(&rtmGetErrorStatus(Traffic_assist_M)));

}

/* Model terminate function */

void Traffic_assist_terminate(void)

{

/* (no terminate code required) */

}

Justification of the Project

The "Vehicle Direction Determination" project is essential because it addresses a critical aspect of autonomous driving and Advanced Driver Assistance Systems (ADAS), enhancing vehicle safety and navigation. Here’s the justification for the project:

  1. Improved Safety and Compliance:
    • The system helps ensure that the vehicle is following the correct direction according to road signs. This is especially important in autonomous driving scenarios, where the vehicle needs to make decisions based on the environment without human intervention.
    • By providing feedback to the driver regarding the direction (left, right, or straight), it ensures compliance with road regulations and can potentially prevent accidents due to wrong-way driving or missed turns.
  2. Integration with Other ADAS Features:
    • Vehicle direction determination can work alongside other ADAS features such as lane detection, ramp entry/exit warnings, and GPS-based navigation. This integration contributes to creating a more comprehensive driver assistance system.
    • For example, the system can aid in identifying whether the vehicle is taking the correct exit on a highway ramp or if it is driving in the wrong direction.
  3. Enhancement of Navigation Systems:
    • Coupling this feature with GPS navigation can improve route optimization by confirming whether the vehicle is taking the right path. It adds another layer of validation, ensuring that the driver or autonomous system is heading towards the destination in an optimal manner.
  4. Model-Based Design and Automotive Standards:
    • The project emphasizes the use of Model-Based Design (MBD), which is a widely adopted approach in the automotive industry for developing safety-critical systems. MBD allows for rapid prototyping, simulation, and verification of the system behavior before deployment.
    • The use of Simulink and a data dictionary ensures that the system is developed in a structured manner, with clearly defined signal and calibration data. This improves maintainability and supports compliance with automotive standards like ISO 26262.
  5. Scalability and Flexibility:
    • The modular approach to building the system using Simulink subsystems allows for easy expansion. New features (e.g., additional sensor integration) can be added without significant redesign.
    • It also makes the system adaptable to different vehicle types and environments by simply adjusting the calibration parameters.

Summary

The "Vehicle Direction Determination" project aims to develop a Simulink-based model that accurately identifies the vehicle's driving direction using yaw rate and camera-detected road signs, improving safety, compliance, and integration with other ADAS features. The project supports Model-Based Design principles, making the system scalable, flexible, and aligned with automotive standards.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.