Project 1 (Mini Project on Vehicle Direction Detection
Aim:
- To Model the Simulink model according to the mentioned requirements.
- To build the Data Dictionary of the model and do the requirement tagging.
- To generate the code for the above model.
Simulink Model:

Requiremt-1 logic:

- The straightWheel_YawDegreeInput is compared against 3 canstants, Right_Turn_AngleInput, Left_Turn_AngleInput and Straight_Drive_Steering_Angle.
- Whichever is equal that input will be passed to the vehicle_Turn_Status
- If input is equal to none of them, then the vehicle_Turn_Status value is given by a constant block other than -120, 0, 30 is given (in our case 180 is given).
Requirement-2 logic:

- The vehicle_turn_Status is compared with the 3 logics Right_Turn_RoadSign, Left_Turn_RoadSign and Straight_RoadSign .
- Any one of them can be 1 at a time.
- The input from the CameraInput_RoadSign is a Boolean and is always 1.
- We will AND the 3 logic from above with the CameraInput_RoadSign and OR the 3 output. Thus we will get Vehicle_Direction_Indicator.
- To generate the code for the above model.
SLDD data:

- The SLDD signals and constants are shown in the above fig.

Ert.main
|
/* |
|
|
2 |
* File: ert_main.c |
|
3 |
* |
|
4 |
* Code generated for Simulink model 'Project_1'. |
|
5 |
* |
|
6 |
* Model version : 1.4 |
|
7 |
* Simulink Coder version : 8.14 (R2018a) 06-Feb-2018 |
|
8 |
* C/C++ source code generated on : Tue Dec 7 12:53:55 2021 |
|
9 |
* |
|
10 |
* Target selection: ert.tlc |
|
11 |
* Embedded hardware selection: Intel->x86-64 (Windows64) |
|
12 |
* Code generation objectives: |
|
13 |
* 1. Execution efficiency |
|
14 |
* 2. RAM efficiency |
|
15 |
* Validation result: Not run |
|
16 |
*/ |
|
17 |
|
|
18 |
#include |
|
19 |
#include /* This ert_main.c example uses printf/fflush */ |
|
20 |
#include "Project_1.h" /* Model's header file */ |
|
21 |
#include "rtwtypes.h" |
|
22 |
|
|
23 |
/* |
|
24 |
* Associating rt_OneStep with a real-time clock or interrupt service routine |
|
25 |
* is what makes the generated code "real-time". The function rt_OneStep is |
|
26 |
* always associated with the base rate of the model. Subrates are managed |
|
27 |
* by the base rate from inside the generated code. Enabling/disabling |
|
28 |
* interrupts and floating point context switches are target specific. This |
|
29 |
* example code indicates where these should take place relative to executing |
|
30 |
* the generated code step function. Overrun behavior should be tailored to |
|
31 |
* your application needs. This example simply sets an error status in the |
|
32 |
* real-time model and returns from rt_OneStep. |
|
33 |
*/ |
|
34 |
void rt_OneStep(void); |
|
35 |
void rt_OneStep(void) |
|
36 |
{ |
|
37 |
static boolean_T OverrunFlag = false; |
|
38 |
|
|
39 |
/* Disable interrupts here */ |
|
40 |
|
|
41 |
/* Check for overrun */ |
|
42 |
if (OverrunFlag) { |
|
43 |
rtmSetErrorStatus(rtM, "Overrun"); |
|
44 |
return; |
|
45 |
} |
|
46 |
|
|
47 |
OverrunFlag = true; |
|
48 |
|
|
49 |
/* Save FPU context here (if necessary) */ |
|
50 |
/* Re-enable timer or interrupt here */ |
|
51 |
/* Set model inputs here */ |
|
52 |
|
|
53 |
/* Step the model */ |
|
54 |
Project_1_step(); |
|
55 |
|
|
56 |
/* Get model outputs here */ |
|
57 |
|
|
58 |
/* Indicate task complete */ |
|
59 |
OverrunFlag = false; |
|
60 |
|
|
61 |
/* Disable interrupts here */ |
|
62 |
/* Restore FPU context here (if necessary) */ |
|
63 |
/* Enable interrupts here */ |
|
64 |
} |
|
65 |
|
|
66 |
/* |
|
67 |
* The example "main" function illustrates what is required by your |
|
68 |
* application code to initialize, execute, and terminate the generated code. |
|
69 |
* Attaching rt_OneStep to a real-time clock is target specific. This example |
|
70 |
* illustrates how you do this relative to initializing the model. |
|
71 |
*/ |
|
72 |
int_T main(int_T argc, const char *argv[]) |
|
73 |
{ |
|
74 |
/* Unused arguments */ |
|
75 |
(void)(argc); |
|
76 |
(void)(argv); |
|
77 |
|
|
78 |
/* Initialize model */ |
|
79 |
Project_1_initialize(); |
|
80 |
|
|
81 |
/* Attach rt_OneStep to a timer or interrupt service routine with |
|
82 |
* period 0.2 seconds (the model's base sample time) here. The |
|
83 |
* call syntax for rt_OneStep is |
|
84 |
* |
|
85 |
* rt_OneStep(); |
|
86 |
*/ |
|
87 |
printf("Warning: The simulation will run forever. " |
|
88 |
"Generated ERT main won't simulate model step behavior. " |
|
89 |
"To change this behavior select the 'MAT-file logging' option.\n"); |
|
90 |
fflush((NULL)); |
|
91 |
while (rtmGetErrorStatus(rtM) == (NULL)) { |
|
92 |
/* Perform other application tasks here */ |
|
93 |
} |
|
94 |
|
|
95 |
/* Disable rt_OneStep() here */ |
|
96 |
return 0; |
|
97 |
} |
|
98 |
|
|
99 |
/* |
|
100 |
* File trailer for generated code. |
|
101 |
* |
|
102 |
* [EOF] |
|
103 |
*/ |
|
104 |
Project_1.c
|
/* |
|
|
2 |
* File: Project_1.c |
|
3 |
* |
|
4 |
* Code generated for Simulink model 'Project_1'. |
|
5 |
* |
|
6 |
* Model version : 1.4 |
|
7 |
* Simulink Coder version : 8.14 (R2018a) 06-Feb-2018 |
|
8 |
* C/C++ source code generated on : Tue Dec 7 12:53:55 2021 |
|
9 |
* |
|
10 |
* Target selection: ert.tlc |
|
11 |
* Embedded hardware selection: Intel->x86-64 (Windows64) |
|
12 |
* Code generation objectives: |
|
13 |
* 1. Execution efficiency |
|
14 |
* 2. RAM efficiency |
|
15 |
* Validation result: Not run |
|
16 |
*/ |
|
17 |
|
|
18 |
#include "Project_1.h" |
|
19 |
|
|
20 |
/* Exported data definition */ |
|
21 |
|
|
22 |
/* Const memory section */ |
|
23 |
/* Definition for custom storage class: Const */ |
|
24 |
const real_T LeftTurn_RoadSign = -120.0; |
|
25 |
const real_T Left_Turn_AngularLimit = -120.0; |
|
26 |
const real_T RightTurn_RoadSign = 30.0; |
|
27 |
const int16_T Right_Turn_AngularLimit = 30; |
|
28 |
const real_T Straight_Drive_Steering_Angle = 0.0; |
|
29 |
const real_T Straight_RoadSign = 0.0; |
|
30 |
|
|
31 |
/* External inputs (root inport signals with default storage) */ |
|
32 |
ExtU rtU; |
|
33 |
|
|
34 |
/* External outputs (root outports fed by signals with default storage) */ |
|
35 |
ExtY rtY; |
|
36 |
|
|
37 |
/* Real-time model */ |
|
38 |
RT_MODEL rtM_; |
|
39 |
RT_MODEL *const rtM = &rtM_; |
|
40 |
|
|
41 |
/* Model step function */ |
|
42 |
void Project_1_step(void) |
|
43 |
{ |
|
44 |
real_T rtb_Switch2; |
|
45 |
|
|
46 |
/* Switch: '/Switch2' incorporates: |
|
47 |
* Constant: '/Constant1' |
|
48 |
* Constant: '/Constant2' |
|
49 |
* Constant: '/Constant3' |
|
50 |
* Inport: '/SteeringWheel_YawDegreeInput' |
|
51 |
* RelationalOperator: '/Relational Operator' |
|
52 |
* RelationalOperator: '/Relational Operator1' |
|
53 |
* RelationalOperator: '/Relational Operator2' |
|
54 |
* Switch: '/Switch' |
|
55 |
* Switch: '/Switch1' |
|
56 |
*/ |
|
if (rtU.SteeringWheel_YawDegreeInput == Right_Turn_AngularLimit) { |
|
|
rtb_Switch2 = Right_Turn_AngularLimit; |
|
|
} else if (rtU.SteeringWheel_YawDegreeInput == Left_Turn_AngularLimit) { |
|
|
60 |
/* Switch: '/Switch1' incorporates: |
|
61 |
* Constant: '/Constant2' |
|
62 |
*/ |
|
rtb_Switch2 = Left_Turn_AngularLimit; |
|
|
} else if (rtU.SteeringWheel_YawDegreeInput == Straight_Drive_Steering_Angle) |
|
|
65 |
{ |
|
66 |
/* Switch: '/Switch' incorporates: |
|
67 |
* Constant: '/Constant3' |
|
68 |
* Switch: '/Switch1' |
|
69 |
*/ |
|
rtb_Switch2 = Straight_Drive_Steering_Angle; |
|
|
71 |
} else { |
|
72 |
/* Switch: '/Switch1' incorporates: |
|
73 |
* Constant: '/Constant' |
|
74 |
* Switch: '/Switch' |
|
75 |
*/ |
|
rtb_Switch2 = 180.0; |
|
|
77 |
} |
|
78 |
|
|
79 |
/* End of Switch: '/Switch2' */ |
|
80 |
|
|
81 |
/* Outport: '/Vehicle_Direction_Indicator' incorporates: |
|
82 |
* Constant: '/Constant' |
|
83 |
* Constant: '/Constant1' |
|
84 |
* Constant: '/Constant2' |
|
85 |
* Inport: '/CameraInput_RoadSign' |
|
86 |
* Logic: '/AND' |
|
87 |
* Logic: '/AND1' |
|
88 |
* Logic: '/AND2' |
|
89 |
* Logic: '/AND3' |
|
90 |
* RelationalOperator: '/Relational Operator' |
|
91 |
* RelationalOperator: '/Relational Operator1' |
|
92 |
* RelationalOperator: '/Relational Operator2' |
|
93 |
*/ |
|
rtY.Vehicle_Direction_Indicator = ((rtU.CameraInput_RoadSign && (rtb_Switch2 == |
|
|
RightTurn_RoadSign)) || (rtU.CameraInput_RoadSign && (rtb_Switch2 == |
|
|
LeftTurn_RoadSign)) || (rtU.CameraInput_RoadSign && (rtb_Switch2 == |
|
|
Straight_RoadSign))); |
|
|
98 |
} |
|
99 |
|
|
100 |
/* Model initialize function */ |
|
101 |
void Project_1_initialize(void) |
|
102 |
{ |
|
103 |
/* (no initialization code required) */ |
|
104 |
} |
|
105 |
|
|
106 |
/* |
|
107 |
* File trailer for generated code. |
|
108 |
* |
|
109 |
* [EOF] |
|
110 |
*/ |
|
111 |
Project_1.h
|
/* |
|
|
2 |
* File: Project_1.h |
|
3 |
* |
|
4 |
* Code generated for Simulink model 'Project_1'. |
|
5 |
* |
|
6 |
* Model version : 1.4 |
|
7 |
* Simulink Coder version : 8.14 (R2018a) 06-Feb-2018 |
|
8 |
* C/C++ source code generated on : Tue Dec 7 12:53:55 2021 |
|
9 |
* |
|
10 |
* Target selection: ert.tlc |
|
11 |
* Embedded hardware selection: Intel->x86-64 (Windows64) |
|
12 |
* Code generation objectives: |
|
13 |
* 1. Execution efficiency |
|
14 |
* 2. RAM efficiency |
|
15 |
* Validation result: Not run |
|
16 |
*/ |
|
17 |
|
|
18 |
#ifndef RTW_HEADER_Project_1_h_ |
|
19 |
#define RTW_HEADER_Project_1_h_ |
|
20 |
#ifndef Project_1_COMMON_INCLUDES_ |
|
21 |
# define Project_1_COMMON_INCLUDES_ |
|
22 |
#include "rtwtypes.h" |
|
23 |
#include "rtw_continuous.h" |
|
24 |
#include "rtw_solver.h" |
|
25 |
#endif /* Project_1_COMMON_INCLUDES_ */ |
|
26 |
|
|
27 |
/* Macros for accessing real-time model data structure */ |
|
28 |
#ifndef rtmGetErrorStatus |
|
29 |
# define rtmGetErrorStatus(rtm) ((rtm)->errorStatus) |
|
30 |
#endif |
|
31 |
|
|
32 |
#ifndef rtmSetErrorStatus |
|
33 |
# define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val)) |
|
34 |
#endif |
|
35 |
|
|
36 |
/* Forward declaration for rtModel */ |
|
37 |
typedef struct tag_RTM RT_MODEL; |
|
38 |
|
|
39 |
/* External inputs (root inport signals with default storage) */ |
|
40 |
typedef struct { |
|
41 |
real_T SteeringWheel_YawDegreeInput; /* '/SteeringWheel_YawDegreeInput' */ |
|
42 |
boolean_T CameraInput_RoadSign; /* '/CameraInput_RoadSign' */ |
|
43 |
} ExtU; |
|
44 |
|
|
45 |
/* External outputs (root outports fed by signals with default storage) */ |
|
46 |
typedef struct { |
|
47 |
boolean_T Vehicle_Direction_Indicator;/* '/Vehicle_Direction_Indicator' */ |
|
48 |
} ExtY; |
|
49 |
|
|
50 |
/* Real-time Model Data Structure */ |
|
51 |
struct tag_RTM { |
|
52 |
const char_T * volatile errorStatus; |
|
53 |
}; |
|
54 |
|
|
55 |
/* External inputs (root inport signals with default storage) */ |
|
56 |
extern ExtU rtU; |
|
57 |
|
|
58 |
/* External outputs (root outports fed by signals with default storage) */ |
|
59 |
extern ExtY rtY; |
|
60 |
|
|
61 |
/* Model entry point functions */ |
|
62 |
extern void Project_1_initialize(void); |
|
63 |
extern void Project_1_step(void); |
|
64 |
|
|
65 |
/* Exported data declaration */ |
|
66 |
|
|
67 |
/* Const memory section */ |
|
68 |
/* Declaration for custom storage class: Const */ |
|
69 |
extern const real_T LeftTurn_RoadSign; |
|
70 |
extern const real_T Left_Turn_AngularLimit; |
|
71 |
extern const real_T RightTurn_RoadSign; |
|
72 |
extern const int16_T Right_Turn_AngularLimit; |
|
73 |
extern const real_T Straight_Drive_Steering_Angle; |
|
74 |
extern const real_T Straight_RoadSign; |
|
75 |
|
|
76 |
/* Real-time Model object */ |
|
77 |
extern RT_MODEL *const rtM; |
|
78 |
|
|
79 |
/*- |
|
80 |
* The generated code includes comments that allow you to trace directly |
|
81 |
* back to the appropriate location in the model. The basic format |
|
82 |
* is /block_name, where system is the system number (uniquely |
|
83 |
* assigned by Simulink) and block_name is the name of the block. |
|
84 |
* |
|
85 |
* Use the MATLAB hilite_system command to trace the generated code back |
|
86 |
* to the model. For example, |
|
87 |
* |
|
88 |
* hilite_system('') - opens system 3 |
|
89 |
* hilite_system('/Kp') - opens and selects block Kp which resides in S3 |
|
90 |
* |
|
91 |
* Here is the system hierarchy for this model |
|
92 |
* |
|
93 |
* '' : 'Project_1' |
|
94 |
* '' : 'Project_1/Requirement_2' |
|
95 |
* '' : 'Project_1/Requiremnt_1' |
|
96 |
*/ |
|
97 |
#endif /* RTW_HEADER_Project_1_h_ */ |
|
98 |
|
|
99 |
/* |
|
100 |
* File trailer for generated code. |
|
101 |
* |
|
102 |
* [EOF] |
|
103 |
*/ |
|
104 |