Challenge

Project 1- Traffic Jam Assistant Feature

1.Objective::

Requirement No 1:

  • Input Signal “Input_Voltage” is compared against voltage values “VOLTAGE_MINIMUM_RANGE” & “VOLTAGE_MAXIMUM_RANGE”.
  • Incoming input signal “Input_Voltage” must be greater than – equal to “VOLTAGE_MINIMUM_RANGE” and less than – equal to “VOLTAGE_MAXIMUM_RANGE”.
  • Output signal from here is “Optimum_Voltage” which will be one of the inputs to the subsystem “DisplayUnit”.

Requirement No 2 (DisplayUnit Subsystem):

  • Input Signals are “Optimum_Voltage”, “Input_Switch”,“Enable_Display”. Signal “Enable_Display” must be saturated between the range 0 – 7. Output signal from the subsystem is “Output_Display”.
  • Input Signal “Enable_Display” is compared against pre – defined set of values in a multiport switch. Total data ports in the multiport switch is 5.
  • Multiport switch inputs 1 & 2 is connected to calibration signal “ON_MODE”, Multiport switch inputs 3 & 4 is connected to calibration signal “OFF_MODE” while Multiport switch input 5 is connected to calibration signal “STANDBY_MODE”.
  • The output from Multiport switch is connected to the first input port of the Switch block. The third input port of the Switch block is connected to the calibration signal “NO_DISPLAY”.
  • Meanwhile NOT value of input signal “Input_Switch” is compared in an AND gate against input signal “Optimum_Voltage” and the output from comparing if calibration signals “INTERRUPT_1” & “INTERRUPT_2” are equal. The output of the AND gate is the second input of the switch block.

The output from the switch block is “Output_Display”.

Model:

Below Model consists of two requirements.

An Localized signal "optimum Voltage'' output from Req 1 is Connected as Input to Req2,with Input_Switch,Enable_Display.

Requiment 1 Subsystem:

Requirement 2:

Resolving:

Resolving the Input & Output signal also in Subsystem.

Code Generation:

Results:

Model Advisor Report:

Code Generation:

File: AUTOSAR_Prj1.c

1 /*
2 * File: AUTOSAR_Prj1.c
3 *
4 * Code generated for Simulink model 'AUTOSAR_Prj1'.
5 *
6 * Model version : 2.2
7 * Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
8 * C/C++ source code generated on : Mon Dec 27 21:15:20 2021
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 "AUTOSAR_Prj1.h"
17 #include "AUTOSAR_Prj1_private.h"
18
19 /* Exported data definition */
20
21 /* Definition for custom storage class: ExportToFile */
22 uint8_T Output_Display; /* '<S2>/Switch' */
23
24 /* ConstVolatile memory section */
25 /* Definition for custom storage class: ConstVolatile */
26 const volatile boolean_T INTERRUPT_1 = 1;/* Referenced by: '<S2>/Constant4' */
27 const volatile boolean_T INTERRUPT_2 = 1;/* Referenced by: '<S2>/Constant5' */
28 const volatile uint8_T NO_DISPLAY = 0U;/* Referenced by: '<S2>/Constant3' */
29 const volatile uint8_T OFF_MODE = 2U; /* Referenced by: '<S2>/Constant1' */
30 const volatile uint8_T ON_MODE = 1U; /* Referenced by: '<S2>/Constant' */
31 const volatile uint8_T STANDBY_MODE = 3U;/* Referenced by: '<S2>/Constant2' */
32 const volatile uint8_T VOLTAGE_MAXIMUM_RANGE = 50U;/* Referenced by: '<S1>/Constant1' */
33 const volatile uint8_T VOLTAGE_MINIMUM_RANGE = 30U;/* Referenced by: '<S1>/Constant' */
34
35 /* Real-time model */
36 static RT_MODEL_AUTOSAR_Prj1_T AUTOSAR_Prj1_M_;
37 RT_MODEL_AUTOSAR_Prj1_T *const AUTOSAR_Prj1_M = &AUTOSAR_Prj1_M_;
38
39 /* Model step function */
40 void AUTOSAR_Prj1_step(void)
41 {
42 /* local block i/o variables */
43 boolean_T Optimum_Voltage;
44 uint8_T tmp;
45
46 /* Logic: '<S1>/AND' incorporates:
47 * Constant: '<S1>/Constant'
48 * Constant: '<S1>/Constant1'
49 * Inport: '<Root>/Input_Voltage'
50 * RelationalOperator: '<S1>/Relational Operator'
51 * RelationalOperator: '<S1>/Relational Operator1'
52 */
53 Optimum_Voltage = ((Input_Voltage <= VOLTAGE_MAXIMUM_RANGE) && (Input_Voltage >=
54 VOLTAGE_MINIMUM_RANGE));
55
56 /* Switch: '<S2>/Switch' incorporates:
57 * Constant: '<S2>/Constant4'
58 * Constant: '<S2>/Constant5'
59 * Inport: '<Root>/Input_Switch'
60 * Logic: '<S2>/AND'
61 * Logic: '<S2>/AND1'
62 * Logic: '<S2>/Logical Operator'
63 * RelationalOperator: '<S2>/Relational Operator'
64 */
65 if ((!Input_Switch) && Optimum_Voltage && (INTERRUPT_1 == INTERRUPT_2)) {
66 /* Saturate: '<S2>/Saturation' incorporates:
67 * Inport: '<Root>/Enable_Display'
68 */
69 if (Enable_Display < 7) {
70 tmp = Enable_Display;
71 } else {
72 tmp = 7U;
73 }
74
75 /* End of Saturate: '<S2>/Saturation' */
76
77 /* MultiPortSwitch: '<S2>/Multiport Switch' */
78 switch (tmp) {
79 case 1:
80 /* Switch: '<S2>/Switch' incorporates:
81 * Constant: '<S2>/Constant'
82 */
83 Output_Display = ON_MODE;
84 break;
85
86 case 2:
87 /* Switch: '<S2>/Switch' incorporates:
88 * Constant: '<S2>/Constant'
89 */
90 Output_Display = ON_MODE;
91 break;
92
93 case 3:
94 /* Switch: '<S2>/Switch' incorporates:
95 * Constant: '<S2>/Constant1'
96 */
97 Output_Display = OFF_MODE;
98 break;
99
100 case 4:
101 /* Switch: '<S2>/Switch' incorporates:
102 * Constant: '<S2>/Constant1'
103 */
104 Output_Display = OFF_MODE;
105 break;
106
107 default:
108 /* Switch: '<S2>/Switch' incorporates:
109 * Constant: '<S2>/Constant2'
110 */
111 Output_Display = STANDBY_MODE;
112 break;
113 }
114
115 /* End of MultiPortSwitch: '<S2>/Multiport Switch' */
116 } else {
117 /* Switch: '<S2>/Switch' incorporates:
118 * Constant: '<S2>/Constant3'
119 */
120 Output_Display = NO_DISPLAY;
121 }
122
123 /* End of Switch: '<S2>/Switch' */
124 }
125
126 /* Model initialize function */
127 void AUTOSAR_Prj1_initialize(void)
128 {
129 /* (no initialization code required) */
130 }
131
132 /* Model terminate function */
133 void AUTOSAR_Prj1_terminate(void)
134 {
135 /* (no terminate code required) */
136 }
137
138 /*
139 * File trailer for generated code.
140 *

Header File:

File: AUTOSAR_Prj1.h

1 /*
2 * File: AUTOSAR_Prj1.h
3 *
4 * Code generated for Simulink model 'AUTOSAR_Prj1'.
5 *
6 * Model version : 2.2
7 * Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
8 * C/C++ source code generated on : Mon Dec 27 21:15:20 2021
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_AUTOSAR_Prj1_h_
17 #define RTW_HEADER_AUTOSAR_Prj1_h_
18 #ifndef AUTOSAR_Prj1_COMMON_INCLUDES_
19 #define AUTOSAR_Prj1_COMMON_INCLUDES_
20 #include "rtwtypes.h"
21 #endif /* AUTOSAR_Prj1_COMMON_INCLUDES_ */
22
23 #include "AUTOSAR_Prj1_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_AUTOSAR_Prj1_T {
36 const char_T * volatile errorStatus;
37 };
38
39 /* Model entry point functions */
40 extern void AUTOSAR_Prj1_initialize(void);
41 extern void AUTOSAR_Prj1_step(void);
42 extern void AUTOSAR_Prj1_terminate(void);
43
44 /* Exported data declaration */
45
46 /* Declaration for custom storage class: ExportToFile */
47 extern uint8_T Output_Display; /* '<S2>/Switch' */
48
49 /* ConstVolatile memory section */
50 /* Declaration for custom storage class: ConstVolatile */
51 extern const volatile boolean_T INTERRUPT_1;/* Referenced by: '<S2>/Constant4' */
52 extern const volatile boolean_T INTERRUPT_2;/* Referenced by: '<S2>/Constant5' */
53 extern const volatile uint8_T NO_DISPLAY;/* Referenced by: '<S2>/Constant3' */
54 extern const volatile uint8_T OFF_MODE;/* Referenced by: '<S2>/Constant1' */
55 extern const volatile uint8_T ON_MODE; /* Referenced by: '<S2>/Constant' */
56 extern const volatile uint8_T STANDBY_MODE;/* Referenced by: '<S2>/Constant2' */
57 extern const volatile uint8_T VOLTAGE_MAXIMUM_RANGE;/* Referenced by: '<S1>/Constant1' */
58 extern const volatile uint8_T VOLTAGE_MINIMUM_RANGE;/* Referenced by: '<S1>/Constant' */
59
60 /* Real-time Model object */
61 extern RT_MODEL_AUTOSAR_Prj1_T *const AUTOSAR_Prj1_M;
62
63 /*-
64 * The generated code includes comments that allow you to trace directly
65 * back to the appropriate location in the model. The basic format
66 * is <system>/block_name, where system is the system number (uniquely
67 * assigned by Simulink) and block_name is the name of the block.
68 *
69 * Use the MATLAB hilite_system command to trace the generated code back
70 * to the model. For example,
71 *
72 * hilite_system('<S3>') - opens system 3
73 * hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
74 *
75 * Here is the system hierarchy for this model
76 *
77 * '<Root>' : 'AUTOSAR_Prj1'
78 * '<S1>' : 'AUTOSAR_Prj1/Requirement1'
79 * '<S2>' : 'AUTOSAR_Prj1/Requirement2'
80 */
81 #endif /* RTW_HEADER_AUTOSAR_Prj1_h_ */
82
83 /*
84 * File trailer for generated code.
85 *
86 * [EOF]
87 */
88

Conclusion:

Thus based on the requirements we had created the model,SLDD file attached with the model,model advisor check taken up and finally embedded code had been Generated Sucessfully.

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.