Project 1 (Mini Project on Vehicle Direction Detection
Aim-
To identify the vehicle direction by using steering wheel input and the camera input.
Objective-
- As per the given requirement we have to develop the Simulink model.
- Tag the given requirement to the subsystems.
- Develop the SLDD file and set the MBD compliances in the model.
Blocks Required-
Switch block, Constant, Inport, Outport, Relational Operator, Logical Operator and Compare to constant.
Function of the block-
Switch Block-
It is used to compare the inputs.
Constant-
It is used to give constant inputs.
Inport and Outport-
It is used to represent signal attribute of the model.
Relational and Logical operator-
It is used to perform the condition.
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).
The model is as follow-



As we have to give the SLDD file as input the file input is as below.

Procedure –
- In first step we have to make the MBD environment changes means we have set the model as per MBD compliances as follow in modelling tab in model setting set the solver configuration and code generation settings. Select the solver as fixed step solver and sample time should be 0.01s and in code generation select the ert.tlc embedded coder.

- Develop the MATLAB model as per the given requirement
- Requirement 1 logic is as follows if the input is greater than 0 then vehicle turn right if the input is equal to zero then vehicle drive in straight line if the input is less than the zero then vehicle turns left by using the switch block, we can able to implement the above logic.
- Requirement 2 logic is as follows here vehicle turn status is taken as input from the first subsystem here relational operators are used when vehicle turn stats match the any of the three inputs then it provides the signal further, we can call it as a true condition.
- After that AND operator is used and the input to the AND operator is output of the relational operator and camera input AND block give the true condition when both the input is true. Means when the camera input shows the left turn and output of the relational operator gives the output left turn then in output the indicator indicates the vehicle turns left.
- And the constants value and calibration are defined in the SLDD file.
- Then as per the objective we have to do a requirement tagging. Requirement tagging is done as follow
- Right click on the subsystem and select the word file where requirement is saved.

- Now we have to run model advisory for to check the model is as per the MAB guidelines.
- For that go to the modelling tab and then click on the model advisor. And click on the model advisor.
- Then select the modelling standard for the MAB and then click run selected The report will generate automatically.

- By viewing the report, we can check the warning fault and pass checks on the model. The report is attached for the reference

- For the code generation click on the code generation tab and select the generate code option is as follow.l

- The code is as follows
- ert main C
1 /*
2 * File: ert_main.c
3 *
4 * Code generated for Simulink model 'Vehicle_detection'.
5 *
6 * Model version : 1.6
7 * Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
8 * C/C++ source code generated on : Mon Oct 3 10:34:28 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #include <stddef.h>
17 #include <stdio.h> /* This ert_main.c example uses printf/fflush */
18 #include "Vehicle_detection.h" /* Model's header file */
19 #include "rtwtypes.h"
20
21 /*
22 * Associating rt_OneStep with a real-time clock or interrupt service routine
23 * is what makes the generated code "real-time". The function rt_OneStep is
24 * always associated with the base rate of the model. Subrates are managed
25 * by the base rate from inside the generated code. Enabling/disabling
26 * interrupts and floating point context switches are target specific. This
27 * example code indicates where these should take place relative to executing
28 * the generated code step function. Overrun behavior should be tailored to
29 * your application needs. This example simply sets an error status in the
30 * real-time model and returns from rt_OneStep.
31 */
32 void rt_OneStep(void);
33 void rt_OneStep(void)
34 {
35 static boolean_T OverrunFlag = false;
36
37 /* Disable interrupts here */
38
39 /* Check for overrun */
40 if (OverrunFlag) {
41 rtmSetErrorStatus(Vehicle_detection_M, "Overrun");
42 return;
43 }
44
45 OverrunFlag = true;
46
47 /* Save FPU context here (if necessary) */
48 /* Re-enable timer or interrupt here */
49 /* Set model inputs here */
50
51 /* Step the model */
52 Vehicle_detection_step();
53
54 /* Get model outputs here */
55
56 /* Indicate task complete */
57 OverrunFlag = false;
58
59 /* Disable interrupts here */
60 /* Restore FPU context here (if necessary) */
61 /* Enable interrupts here */
62 }
63
64 /*
65 * The example "main" function illustrates what is required by your
66 * application code to initialize, execute, and terminate the generated code.
67 * Attaching rt_OneStep to a real-time clock is target specific. This example
68 * illustrates how you do this relative to initializing the model.
69 */
70 int_T main(int_T argc, const char *argv[])
71 {
72 /* Unused arguments */
73 (void)(argc);
74 (void)(argv);
75
76 /* Initialize model */
77 Vehicle_detection_initialize();
78
79 /* Attach rt_OneStep to a timer or interrupt service routine with
80 * period 0.01 seconds (the model's base sample time) here. The
81 * call syntax for rt_OneStep is
82 *
83 * rt_OneStep();
84 */
85 printf("Warning: The simulation will run forever. "
86 "Generated ERT main won't simulate model step behavior. "
87 "To change this behavior select the 'MAT-file logging' option.\n");
88 fflush((NULL));
89 while (rtmGetErrorStatus(Vehicle_detection_M) == (NULL)) {
90 /* Perform other application tasks here */
91 }
92
93 /* Disable rt_OneStep() here */
94
95 /* Terminate model */
96 Vehicle_detection_terminate();
97 return 0;
98 }
99
100 /*
101 * File trailer for generated code.
102 *
103 * [EOF]
104 */
105
17.Vehicle detection.c
1 /*
2 * File: Vehicle_detection.c
3 *
4 * Code generated for Simulink model 'Vehicle_detection'.
5 *
6 * Model version : 1.6
7 * Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
8 * C/C++ source code generated on : Mon Oct 3 10:34:28 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #include "Vehicle_detection.h"
17 #include "Vehicle_detection_private.h"
18
19 /* Exported data definition */
20
21 /* Definition for custom storage class: ExportToFile */
22 boolean_T Vehicle_Direction_Indicator; /* '<S3>/AND3' */
23
24 /* Const memory section */
25 /* Definition for custom storage class: Const */
26 const int16_T LeftTurn_RoadSign = -120;/* Referenced by: '<S3>/Constant1' */
27 const int16_T Left_Turn_AngularLimit = -120;/* Referenced by: '<S2>/Constant2' */
28 const int16_T RightTurn_RoadSign = 30; /* Referenced by: '<S3>/Constant' */
29 const int16_T Right_Turn_AngularLimit = 30;/* Referenced by: '<S2>/Constant' */
30 const int16_T Straight_Drive_Steering_Angle = 0;/* Referenced by: '<S2>/Constant1' */
31 const int16_T Straight_RoadSign = 0; /* Referenced by: '<S3>/Constant2' */
32
33 /* Real-time model */
34 static RT_MODEL_Vehicle_detection_T Vehicle_detection_M_;
35 RT_MODEL_Vehicle_detection_T *const Vehicle_detection_M = &Vehicle_detection_M_;
36
37 /* Model step function */
38 void Vehicle_detection_step(void)
39 {
40 /* local block i/o variables */
41 int16_T Vehicle_Turn_Status;
42
43 /* Switch: '<S2>/Switch' incorporates:
44 * Constant: '<S4>/Constant'
45 * Constant: '<S5>/Constant'
46 * Inport: '<Root>/SteeringWheel_YawDegreeInput'
47 * RelationalOperator: '<S4>/Compare'
48 * RelationalOperator: '<S5>/Compare'
49 * Switch: '<S2>/Switch1'
50 */
51 if (SteeringWheel_YawDegreeInput >= 0) {
52 /* Switch: '<S2>/Switch' incorporates:
53 * Constant: '<S2>/Constant'
54 */
55 Vehicle_Turn_Status = Right_Turn_AngularLimit;
56 } else if (SteeringWheel_YawDegreeInput == 0) {
57 /* Switch: '<S2>/Switch1' incorporates:
58 * Constant: '<S2>/Constant1'
59 * Switch: '<S2>/Switch'
60 */
61 Vehicle_Turn_Status = Straight_Drive_Steering_Angle;
62 } else {
63 /* Switch: '<S2>/Switch' incorporates:
64 * Constant: '<S2>/Constant2'
65 * Switch: '<S2>/Switch1'
66 */
67 Vehicle_Turn_Status = Left_Turn_AngularLimit;
68 }
69
70 /* End of Switch: '<S2>/Switch' */
71
72 /* Logic: '<S3>/AND3' incorporates:
73 * Constant: '<S3>/Constant'
74 * Constant: '<S3>/Constant1'
75 * Constant: '<S3>/Constant2'
76 * Inport: '<Root>/CameraInput_RoadSign'
77 * Logic: '<S3>/AND'
78 * Logic: '<S3>/AND1'
79 * Logic: '<S3>/AND2'
80 * RelationalOperator: '<S3>/Equal'
81 * RelationalOperator: '<S3>/Equal1'
82 * RelationalOperator: '<S3>/Equal2'
83 */
84 Vehicle_Direction_Indicator = (((Vehicle_Turn_Status == RightTurn_RoadSign) &&
85 CameraInput_RoadSign) || ((Vehicle_Turn_Status == LeftTurn_RoadSign) &&
86 CameraInput_RoadSign) || ((Vehicle_Turn_Status == Straight_RoadSign) &&
87 CameraInput_RoadSign));
88 }
89
90 /* Model initialize function */
91 void Vehicle_detection_initialize(void)
92 {
93 /* (no initialization code required) */
94 }
95
96 /* Model terminate function */
97 void Vehicle_detection_terminate(void)
98 {
99 /* (no terminate code required) */
100 }
101
102 /*
103 * File trailer for generated code.
104 *
105 * [EOF]
106 */
18.vehicle detection.h
1 /*
2 * File: Vehicle_detection.h
3 *
4 * Code generated for Simulink model 'Vehicle_detection'.
5 *
6 * Model version : 1.6
7 * Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
8 * C/C++ source code generated on : Mon Oct 3 10:34:28 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #ifndef RTW_HEADER_Vehicle_detection_h_
17 #define RTW_HEADER_Vehicle_detection_h_
18 #ifndef Vehicle_detection_COMMON_INCLUDES_
19 #define Vehicle_detection_COMMON_INCLUDES_
20 #include "rtwtypes.h"
21 #endif /* Vehicle_detection_COMMON_INCLUDES_ */
22
23 #include "Vehicle_detection_types.h"
24
25 /* Macros for accessing real-time model data structure */
26 #ifndef rtmGetErrorStatus
27 #define rtmGetErrorStatus(rtm) ((rtm)->errorStatus)
28 #endif
29
30 #ifndef rtmSetErrorStatus
31 #define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val))
32 #endif
33
34 /* Real-time Model Data Structure */
35 struct tag_RTM_Vehicle_detection_T {
36 const char_T * volatile errorStatus;
37 };
38
39 /* Model entry point functions */
40 extern void Vehicle_detection_initialize(void);
41 extern void Vehicle_detection_step(void);
42 extern void Vehicle_detection_terminate(void);
43
44 /* Exported data declaration */
45
46 /* Declaration for custom storage class: ExportToFile */
47 extern boolean_T Vehicle_Direction_Indicator;/* '<S3>/AND3' */
48
49 /* Const memory section */
50 /* Declaration for custom storage class: Const */
51 extern const int16_T LeftTurn_RoadSign;/* Referenced by: '<S3>/Constant1' */
52 extern const int16_T Left_Turn_AngularLimit;/* Referenced by: '<S2>/Constant2' */
53 extern const int16_T RightTurn_RoadSign;/* Referenced by: '<S3>/Constant' */
54 extern const int16_T Right_Turn_AngularLimit;/* Referenced by: '<S2>/Constant' */
55 extern const int16_T Straight_Drive_Steering_Angle;/* Referenced by: '<S2>/Constant1' */
56 extern const int16_T Straight_RoadSign;/* Referenced by: '<S3>/Constant2' */
57
58 /* Real-time Model object */
59 extern RT_MODEL_Vehicle_detection_T *const Vehicle_detection_M;
60
61 /*-
62 * The generated code includes comments that allow you to trace directly
63 * back to the appropriate location in the model. The basic format
64 * is <system>/block_name, where system is the system number (uniquely
65 * assigned by Simulink) and block_name is the name of the block.
66 *
67 * Use the MATLAB hilite_system command to trace the generated code back
68 * to the model. For example,
69 *
70 * hilite_system('<S3>') - opens system 3
71 * hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
72 *
73 * Here is the system hierarchy for this model
74 *
75 * '<Root>' : 'Vehicle_detection'
76 * '<S1>' : 'Vehicle_detection/Subsystem1'
77 * '<S2>' : 'Vehicle_detection/Subsystem1/Requirement 1'
78 * '<S3>' : 'Vehicle_detection/Subsystem1/Requirement 2'
79 * '<S4>' : 'Vehicle_detection/Subsystem1/Requirement 1/Compare To Constant'
80 * '<S5>' : 'Vehicle_detection/Subsystem1/Requirement 1/Compare To Constant1'
81 */
82 #endif /* RTW_HEADER_Vehicle_detection_h_ */
83
84 /*
85 * File trailer for generated code.
86 *
87 * [EOF]
88 */
89
19.Vehicle detection private.h
1 /*
2 * File: Vehicle_detection_private.h
3 *
4 * Code generated for Simulink model 'Vehicle_detection'.
5 *
6 * Model version : 1.6
7 * Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
8 * C/C++ source code generated on : Mon Oct 3 10:34:28 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #ifndef RTW_HEADER_Vehicle_detection_private_h_
17 #define RTW_HEADER_Vehicle_detection_private_h_
18 #include "rtwtypes.h"
19
20 /* Imported (extern) block signals */
21 extern int16_T SteeringWheel_YawDegreeInput;
22 /* '<Root>/SteeringWheel_YawDegreeInput' */
23 extern boolean_T CameraInput_RoadSign; /* '<Root>/CameraInput_RoadSign' */
24
25 #endif /* RTW_HEADER_Vehicle_detection_private_h_ */
26
27 /*
28 * File trailer for generated code.
29 *
30 * [EOF]
31 */
32
20. Vehicle detection type.h
1 /*
2 * File: Vehicle_detection_types.h
3 *
4 * Code generated for Simulink model 'Vehicle_detection'.
5 *
6 * Model version : 1.6
7 * Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
8 * C/C++ source code generated on : Mon Oct 3 10:34:28 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #ifndef RTW_HEADER_Vehicle_detection_types_h_
17 #define RTW_HEADER_Vehicle_detection_types_h_
18
19 /* Model Code Variants */
20
21 /* Forward declaration for rtModel */
22 typedef struct tag_RTM_Vehicle_detection_T RT_MODEL_Vehicle_detection_T;
23
24 #endif /* RTW_HEADER_Vehicle_detection_types_h_ */
25
26 /*
27 * File trailer for generated code.
28 *
29 * [EOF]
30 */
31
Conclusion-
Thus we have perform the model of vehicle direction indicator which will able to tell us the where the vehicle take turns and it is depend upon the camera signal when condition get satisfy the vehicle able to perform a turn.