Challenge

Project 1 (Mini Project on Vehicle Direction Detection

Live Batch 2

Project 1

In this project there are two requirements. Two requirements are simulated using separate subsystems. The output of requirement 1 is given as one of the inputs to the second requirement. In the first requirement, the SteeringWheel_YawDegreeInput is compared with the three angular values namely Right_Turn_AngularLimit, Left_Turn_AngularLimit, Straight_Drive_Steering_Angle to say which specific direction the steering wheel is turning towards. Switch blocks are used to compare the angular values. The output of requirement one is the local signal Vehicle_Turn_Status.

In the second requirement the output of the requirement 1 is compared with 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).

Requirement 1

/*
 * Event Support License -- for demonstration use and event support.  Not
 * for government, research, commercial, or other organizational use.
 *
 * File: ert_main.c
 *
 * Code generated for Simulink model 'Subsystem'.
 *
 * Model version                  : 1.12
 * Simulink Coder version         : 9.7 (R2022a) 13-Nov-2021
 * C/C++ source code generated on : Thu Sep 22 14:43:09 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include <stddef.h>
#include <stdio.h>            /* This example main program uses printf/fflush */
#include "Subsystem.h"                 /* Model header file */

/*
 * Associating rt_OneStep with a real-time clock or interrupt service routine
 * is what makes the generated code "real-time".  The function rt_OneStep is
 * always associated with the base rate of the model.  Subrates are managed
 * by the base rate from inside the generated code.  Enabling/disabling
 * interrupts and floating point context switches are target specific.  This
 * example code indicates where these should take place relative to executing
 * the generated code step function.  Overrun behavior should be tailored to
 * your application needs.  This example simply sets an error status in the
 * real-time model and returns from rt_OneStep.
 */
void rt_OneStep(void);
void rt_OneStep(void)
{
  static boolean_T OverrunFlag = false;

  /* Disable interrupts here */

  /* Check for overrun */
  if (OverrunFlag) {
    rtmSetErrorStatus(Subsystem_M, "Overrun");
    return;
  }

  OverrunFlag = true;

  /* Save FPU context here (if necessary) */
  /* Re-enable timer or interrupt here */
  /* Set model inputs here */

  /* Step the model */
  Subsystem_step();

  /* Get model outputs here */

  /* Indicate task complete */
  OverrunFlag = false;

  /* Disable interrupts here */
  /* Restore FPU context here (if necessary) */
  /* Enable interrupts here */
}

/*
 * The example main function illustrates what is required by your
 * application code to initialize, execute, and terminate the generated code.
 * Attaching rt_OneStep to a real-time clock is target specific. This example
 * illustrates how you do this relative to initializing the model.
 */
int_T main(int_T argc, const char *argv[])
{
  /* Unused arguments */
  (void)(argc);
  (void)(argv);

  /* Initialize model */
  Subsystem_initialize();

  /* Attach rt_OneStep to a timer or interrupt service routine with
   * period 0.01 seconds (base rate of the model) here.
   * The call syntax for rt_OneStep is
   *
   *  rt_OneStep();
   */
  printf("Warning: The simulation will run forever. "
         "Generated ERT main won't simulate model step behavior. "
         "To change this behavior select the 'MAT-file logging' option.\n");
  fflush((NULL));
  while (rtmGetErrorStatus(Subsystem_M) == (NULL)) {
    /*  Perform application tasks here */
  }

  /* Terminate model */
  Subsystem_terminate();
  return 0;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
​
/*
 * Event Support License -- for demonstration use and event support.  Not
 * for government, research, commercial, or other organizational use.
 *
 * File: Subsystem.c
 *
 * Code generated for Simulink model 'Subsystem'.
 *
 * Model version                  : 1.12
 * Simulink Coder version         : 9.7 (R2022a) 13-Nov-2021
 * C/C++ source code generated on : Thu Sep 22 14:43:09 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "Subsystem.h"
#include "rtwtypes.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>/Constant1' */
const int16_T Right_Turn_AngularLimit = 30;/* Referenced by: '<S2>/Constant' */
const int16_T RigthTurn_RoadSign = 30; /* Referenced by: '<S3>/Constant' */
const int16_T Straight_Drive_Steering_angle = 0;/* Referenced by: '<S2>/Constant2' */
const int16_T Straight_RoadSign = 0;   /* Referenced by: '<S3>/Constant2' */

/* External inputs (root inport signals with default storage) */
ExtU_Subsystem_T Subsystem_U;

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

/* Real-time model */
static RT_MODEL_Subsystem_T Subsystem_M_;
RT_MODEL_Subsystem_T *const Subsystem_M = &Subsystem_M_;

/* Model step function */
void Subsystem_step(void)
{
  /* Switch: '<S2>/Switch' incorporates:
   *  Constant: '<S2>/Constant'
   *  Constant: '<S2>/Constant1'
   *  Inport: '<Root>/In1'
   *  RelationalOperator: '<S2>/Relational Operator'
   *  RelationalOperator: '<S2>/Relational Operator1'
   *  Switch: '<S2>/Switch1'
   */
  if (Right_Turn_AngularLimit == Subsystem_U.In1) {
    /* Switch: '<S2>/Switch' */
    Subsystem_Y.Vehicle_Turn_Status = Right_Turn_AngularLimit;
  } else if (Left_Turn_AngularLimit == Subsystem_U.In1) {
    /* Switch: '<S2>/Switch' incorporates:
     *  Constant: '<S2>/Constant1'
     *  Switch: '<S2>/Switch1'
     */
    Subsystem_Y.Vehicle_Turn_Status = Left_Turn_AngularLimit;
  } else {
    /* Switch: '<S2>/Switch' incorporates:
     *  Constant: '<S2>/Constant2'
     *  Switch: '<S2>/Switch1'
     */
    Subsystem_Y.Vehicle_Turn_Status = Straight_Drive_Steering_angle;
  }

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

  /* Outport: '<Root>/<signal1>' incorporates:
   *  Constant: '<S3>/Constant'
   *  Inport: '<Root>/CameraInput_RoadSign'
   *  Logic: '<S3>/Logical Operator'
   *  RelationalOperator: '<S3>/Relational Operator'
   */
  Subsystem_Y.signal1 = ((RigthTurn_RoadSign == Subsystem_Y.Vehicle_Turn_Status)
    && Subsystem_U.CameraInput_RoadSign);

  /* Outport: '<Root>/<signal2>' incorporates:
   *  Constant: '<S3>/Constant1'
   *  Inport: '<Root>/CameraInput_RoadSign'
   *  Logic: '<S3>/Logical Operator1'
   *  RelationalOperator: '<S3>/Relational Operator1'
   */
  Subsystem_Y.signal2 = ((LeftTurn_RoadSign == Subsystem_Y.Vehicle_Turn_Status) &&
    Subsystem_U.CameraInput_RoadSign);

  /* Outport: '<Root>/<signal3>' incorporates:
   *  Constant: '<S3>/Constant2'
   *  Inport: '<Root>/CameraInput_RoadSign'
   *  Logic: '<S3>/Logical Operator2'
   *  RelationalOperator: '<S3>/Relational Operator2'
   */
  Subsystem_Y.signal3 = ((Straight_RoadSign == Subsystem_Y.Vehicle_Turn_Status) &&
    Subsystem_U.CameraInput_RoadSign);
}

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

/* Model terminate function */
void Subsystem_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.