Challenge

Project 1 (Mini Project on Vehicle Direction Detection

step 1: sldd file has to be inserted 

step 2: signals and parameters are to be added

step 3: block modeling is being done:

Requirement-1 subsystem:

  • Steering wheel input as  SteeringWheel_YawDegreeInput
  • This is compared against 3 angular values, one each for left turn, right turn & straight drive: 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 & develop this requirement. output of the system is Vehicle_Turn_Status.

Requirement-2 subsystem:

  • Inputs to this requirement are Vehicle_Turn_Status & a CameraInput_RoadSign, which confirms the occurrence of a road sign.
  • Signal Vehicle_Turn_Status is compared against 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 Vehicle_Direction_Indicator.

 subsystem has been created using the 2 requirement blocks:

Simulink model:

step 4: right click on requirement 1 model : go to requirements- link to selection in word. do the same with requirement 2 block.

step 5: check for model advisor report if any error is there or not.

step 6: check solver with 0.01 step size and code generation. 

7. click on  generate code

code:

/*
 
 
* Academic License - for use in teaching, academic research, and meeting
 
 
* course requirements at degree granting institutions only. Not for
 
 
* government, commercial, or other organizational use.
 
 
*
 
 
* File: project1.c
 
 
*
 
 
* Code generated for Simulink model 'project1'.
 
 
*
 
 
* Model version : 1.2
 
 
* Simulink Coder version : 9.7 (R2022a) 13-Nov-2021
 
 
* C/C++ source code generated on : Mon Sep 26 12:02:42 2022
 
 
*
 
 
* Target selection: ert.tlc
 
 
* Embedded hardware selection: Intel->x86-64 (Windows64)
 
 
* Code generation objectives: Unspecified
 
 
* Validation result: Not run
 
 
*/
 
 
 
 
 
#include "project1.h"
 
 
#include "rtwtypes.h"
 
 
#include "project1_private.h"
 
 
 
 
 
/* Exported data definition */
 
 
 
 
 
/* Const memory section */
 
 
/* Definition for custom storage class: Const */
 
 
const int16_T LeftTurn_RoadSign = -120;/* Referenced by: '/Constant1' */
 
 
const int16_T Left_Turn_AngularLimit = -120;/* Referenced by:
 
 
* '/Constant1'
 
 
* '/Constant4'
 
 
*/
 
 
const int16_T RightTurn_RoadSign = 30; /* Referenced by: '/Constant' */
 
 
const int16_T Right_Turn_AngularLimit = 30;/* Referenced by:
 
 
* '/Constant'
 
 
* '/Constant3'
 
 
*/
 
 
const int16_T Straight_Drive_Steering_Angle = 0;/* Referenced by:
 
 
* '/Constant2'
 
 
* '/Constant5'
 
 
*/
 
 
const int16_T Straight_RoadSign = 0; /* Referenced by: '/Constant2' */
 
 
 
 
 
/* External inputs (root inport signals with default storage) */
 
 
ExtU_project1_T project1_U;
 
 
 
 
 
/* External outputs (root outports fed by signals with default storage) */
 
 
ExtY_project1_T project1_Y;
 
 
 
 
 
/* Real-time model */
 
 
static RT_MODEL_project1_T project1_M_;
 
 
RT_MODEL_project1_T *const project1_M = &project1_M_;
 
 
 
 
 
/* Model step function */
 
 
void project1_step(void)
 
 
{
 
 
/* local block i/o variables */
 
 
int16_T Vehicle_Turn_Status;
 
 
 
 
 
/* Outputs for Atomic SubSystem: '/Subsystem' */
 
 
/* Switch: '/Switch' incorporates:
 
 
* Constant: '/Constant'
 
 
* Constant: '/Constant1'
 
 
* Constant: '/Constant2'
 
 
* Inport: '/SteeringWheel_YawDegreeInput'
 
 
* RelationalOperator: '/Relational Operator'
 
 
* RelationalOperator: '/Relational Operator1'
 
 
* RelationalOperator: '/Relational Operator2'
 
 
* Switch: '/Switch1'
 
 
* Switch: '/Switch2'
 
 
*/
 
 
if (Right_Turn_AngularLimit == SteeringWheel_YawDegreeInput) {
 
 
/* Switch: '/Switch' incorporates:
 
 
* Constant: '/Constant3'
 
 
*/
 
 
Vehicle_Turn_Status = Right_Turn_AngularLimit;
 
 
} else if (Left_Turn_AngularLimit == SteeringWheel_YawDegreeInput) {
 
 
/* Switch: '/Switch1' incorporates:
 
 
* Constant: '/Constant4'
 
 
* Switch: '/Switch'
 
 
*/
 
 
Vehicle_Turn_Status = Left_Turn_AngularLimit;
 
 
} else if (Straight_Drive_Steering_Angle == SteeringWheel_YawDegreeInput) {
 
 
/* Switch: '/Switch2' incorporates:
 
 
* Constant: '/Constant5'
 
 
* Switch: '/Switch'
 
 
* Switch: '/Switch1'
 
 
*/
 
 
Vehicle_Turn_Status = Straight_Drive_Steering_Angle;
 
 
} else {
 
 
/* Switch: '/Switch' incorporates:
 
 
* Constant: '/Constant6'
 
 
* Switch: '/Switch1'
 
 
* Switch: '/Switch2'
 
 
*/
 
 
Vehicle_Turn_Status = 0;
 
 
}
 
 
 
 
 
/* End of Switch: '/Switch' */
 
 
 
 
 
/* Outport: '/Vehicle_Direction_Indicator' incorporates:
 
 
* Constant: '/Constant'
 
 
* Constant: '/Constant1'
 
 
* Constant: '/Constant2'
 
 
* Inport: '/CameraInput_RoadSign'
 
 
* Logic: '/Logical Operator'
 
 
* Logic: '/Logical Operator1'
 
 
* Logic: '/Logical Operator2'
 
 
* RelationalOperator: '/Relational Operator'
 
 
* RelationalOperator: '/Relational Operator1'
 
 
* RelationalOperator: '/Relational Operator2'
 
 
*/
 
 
project1_Y.Vehicle_Direction_Indicator[0] = ((RightTurn_RoadSign ==
 
 
Vehicle_Turn_Status) && project1_U.CameraInput_RoadSign);
 
 
project1_Y.Vehicle_Direction_Indicator[1] = ((LeftTurn_RoadSign ==
 
 
Vehicle_Turn_Status) && project1_U.CameraInput_RoadSign);
 
 
project1_Y.Vehicle_Direction_Indicator[2] = ((Straight_RoadSign ==
 
 
Vehicle_Turn_Status) && project1_U.CameraInput_RoadSign);
 
 
 
 
 
/* End of Outputs for SubSystem: '/Subsystem' */
 
 
}
 
 
 
 
 
/* Model initialize function */
 
 
void project1_initialize(void)
 
 
{
 
 
/* (no initialization code required) */
 
 
}
 
 
 
 
 
/* Model terminate function */
 
 
void project1_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.