Challenge

Project 1 (Mini Project on Vehicle Direction Detection

Aim: To Develop a MATLAB Simulink Model for Vehicle Direction Detection as per requirement and generate a C-Code for it.

Objective:

  • Development of MATLAB Simulink model as per requirement
  • Create a Simulink Data Dictionary
  • Configuration of Parameters
  • Code Generation

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

Requirements:

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 and Calibration Data:

Model :

For the Vehicle Direction Detection, we have 2 inputs(SteeringWheel_YawDegreeInput and CameraInput_RoadSign) and 1 output(Vehicle_Direction_Indicator). The Vehicle_Direction_Detection Subsystem consists all the requirements logic.

In Steering_Wheel_Direction subsystem, SteeringWheel_YawDegreeInput 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.

The Vehicle_Turn_Status will act as input to the Direction_Indicator_Logic subsystem where, Calibration Values are compared(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.

Simulink DATA DICTIONARY:

All the Signals and Calibration data are stored in the SLDD and the model is ready for simulation.

CODE Generation:

/*
 * File: Vehicle_Direction_det.c
 *
 * Code generated for Simulink model 'Vehicle_Direction_det'.
 *
 * Model version                  : 1.2
 * Simulink Coder version         : 9.3 (R2020a) 18-Nov-2019
 * C/C++ source code generated on : Mon Sep  6 14:39:57 2021
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "Vehicle_Direction_det.h"
#include "Vehicle_Direction_det_private.h"

/* External inputs (root inport signals with default storage) */
ExtU_Vehicle_Direction_det_T Vehicle_Direction_det_U;

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

/* Real-time model */
RT_MODEL_Vehicle_Direction_de_T Vehicle_Direction_det_M_;
RT_MODEL_Vehicle_Direction_de_T *const Vehicle_Direction_det_M =
  &Vehicle_Direction_det_M_;

/* Model step function */
void Vehicle_Direction_det_step(void)
{
  int16_T rtb_Vehicle_Turn_Status;

  /* Switch: '/Switch1' incorporates:
   *  Constant: '/Constant'
   *  Constant: '/Constant2'
   *  Inport: '/SteeringWheel_YawDegreeInput'
   *  Switch: '/Switch'
   */
  if (Vehicle_Direction_det_U.SteeringWheel_YawDegreeInput >= 30.0) {
    rtb_Vehicle_Turn_Status = Right_Turn_AngularLimit;
  } else if (Vehicle_Direction_det_U.SteeringWheel_YawDegreeInput != 0.0) {
    /* Switch: '/Switch' incorporates:
     *  Constant: '/Constant1'
     */
    rtb_Vehicle_Turn_Status = Left_Turn_AngularLimit;
  } else {
    rtb_Vehicle_Turn_Status = Straight_Drive_Steering_Angle;
  }

  /* End of Switch: '/Switch1' */

  /* Outport: '/Vehicle_Direction_Indicator' incorporates:
   *  Constant: '/Constant'
   *  Constant: '/Constant'
   *  Constant: '/Constant'
   *  Inport: '/CameraInput_RoadSign'
   *  Logic: '/LogicalOperator'
   *  Logic: '/LogicalOperator1'
   *  Logic: '/LogicalOperator2'
   *  Logic: '/LogicalOperator3'
   *  RelationalOperator: '/Compare'
   *  RelationalOperator: '/Compare'
   *  RelationalOperator: '/Compare'
   */
  Vehicle_Direction_det_Y.Vehicle_Direction_Indicator =
    (((rtb_Vehicle_Turn_Status == RightTurn_RoadSign) &&
      Vehicle_Direction_det_U.CameraInput_RoadSign) || ((rtb_Vehicle_Turn_Status
       == LeftTurn_RoadSign) && Vehicle_Direction_det_U.CameraInput_RoadSign) ||
     ((rtb_Vehicle_Turn_Status == Straight_RoadSign) &&
      Vehicle_Direction_det_U.CameraInput_RoadSign));
}

/* Model initialize function */
void Vehicle_Direction_det_initialize(void)
{
  /* (no initialization code required) */
}

/* Model terminate function */
void Vehicle_Direction_det_terminate(void)
{
  /* (no terminate code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */

Conclusion:

The required model for Vehicle Direction Detection is developed and a Simulink Data Dictionary file has been created. The model is Simulated and the code is generated using Embedded Coder in Simulink.

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.

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.