Challenge

Project 1 (Mini Project on Vehicle Direction Detection

Model:

Requirement 1:

  • If angle >30 Output = Right_Turn_AngularLimit
  • If angle <-120 Output = Left_Turn_Angular_Limit
  • If angle in between these angles Output =Straight_Drive_Steering_Angle

Requirement 2:

  • Relational block along with Logical AND block compares output of first subsystem with RightTurnRoadSign, LeftTurn_RoadSign, and Straight_RoadSign values and followed by AND ing CameraInput_Roadsign input to get Vehicle Direction indicator value
  • A MUX block used to join signals to single output

Test Harness:

Input given as signal builder. Values imported from excell file. Output is connected to scope

Excell sheet

Out put values

From the output values we can identify that it meets the requirements.

  • For angle greater than 30 Right turn signal is provided
  • For signal less than -120 Left turn is provided
  • Else Straight signal is provided

Model advisor check for MAAB guidelines is done and report generated and attached. No fail conditions 18 warnings only.

Code generation is done

Generated code

/*
 * File: vehicle_direction_detection_1.c
 *
 * Code generated for Simulink model 'vehicle_direction_detection_1'.
 *
 * Model version                  : 1.3
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Mon Apr  4 14:25:26 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "vehicle_direction_detection_1.h"
#include "vehicle_direction_detection_1_private.h"

/* Exported data definition */

/* Const memory section */
/* Definition for custom storage class: Const */
const int16_T LeftTurn_RoadSign = -120;/* Referenced by: '<S3>/Constant1' */
const int16_T Left_Turn_AngularLimit = -120;/* Referenced by: '<S2>/Constant' */
const int16_T RightTurn_RoadSign = 30; /* Referenced by: '<S3>/Constant' */
const int16_T Right_Turn_AngularLimit = 30;/* Referenced by: '<S2>/Constant2' */
const int16_T Straight_Drive_Steering_Angle = 0;/* Referenced by: '<S2>/Constant1' */
const int16_T Straight_RoadSign = 0;   /* Referenced by: '<S3>/Constant2' */

/* External inputs (root inport signals with default storage) */
ExtU_vehicle_direction_detect_T vehicle_direction_detection_1_U;

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

/* Real-time model */
static RT_MODEL_vehicle_direction_de_T vehicle_direction_detection__M_;
RT_MODEL_vehicle_direction_de_T *const vehicle_direction_detection__M =
  &vehicle_direction_detection__M_;

/* Model step function */
void vehicle_direction_detection_1_step(void)
{
  int16_T rtb_Switch;

  /* Outputs for Atomic SubSystem: '<Root>/Vehicle Direction' */
  /* Switch: '<S2>/Switch' incorporates:
   *  Constant: '<S2>/Constant'
   *  Constant: '<S2>/Constant2'
   *  Inport: '<Root>/SteeringWheel_YawDegreeInput'
   *  Switch: '<S2>/Switch2'
   */
  if (vehicle_direction_detection_1_U.SteeringWheel_YawDegreeInput > 30.0) {
    rtb_Switch = Right_Turn_AngularLimit;
  } else if (vehicle_direction_detection_1_U.SteeringWheel_YawDegreeInput >
             -120.0) {
    /* Switch: '<S2>/Switch2' incorporates:
     *  Constant: '<S2>/Constant1'
     */
    rtb_Switch = Straight_Drive_Steering_Angle;
  } else {
    rtb_Switch = Left_Turn_AngularLimit;
  }

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

  /* Outport: '<Root>/Vehicle_Direction_Indicator' incorporates:
   *  Constant: '<S3>/Constant'
   *  Constant: '<S3>/Constant1'
   *  Constant: '<S3>/Constant2'
   *  Inport: '<Root>/CameraInput_RoadSign'
   *  Logic: '<S3>/AND'
   *  Logic: '<S3>/AND1'
   *  Logic: '<S3>/AND2'
   *  RelationalOperator: '<S3>/Relational Operator'
   *  RelationalOperator: '<S3>/Relational Operator1'
   *  RelationalOperator: '<S3>/Relational Operator2'
   */
  vehicle_direction_detection_1_Y.Vehicle_Direction_Indicator[0] = ((rtb_Switch ==
    RightTurn_RoadSign) && vehicle_direction_detection_1_U.CameraInput_RoadSign);
  vehicle_direction_detection_1_Y.Vehicle_Direction_Indicator[1] = ((rtb_Switch ==
    LeftTurn_RoadSign) && vehicle_direction_detection_1_U.CameraInput_RoadSign);
  vehicle_direction_detection_1_Y.Vehicle_Direction_Indicator[2] = ((rtb_Switch ==
    Straight_RoadSign) && vehicle_direction_detection_1_U.CameraInput_RoadSign);

  /* End of Outputs for SubSystem: '<Root>/Vehicle Direction' */
}

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

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

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
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.