1/*
2 * File: ManageVehicleStates_sil_sil_ec.c
3 *
4 * Code generated for Simulink model 'ManageVehicleStates_sil_sil_ec'.
5 *
6 * Model version : 1.2
7 * Simulink Coder version : 9.0 (R2018b) 24-May-2018
8 * C/C++ source code generated on : Tue Oct 29 09:38:21 2019
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 "ManageVehicleStates_sil_sil_ec.h"
19
20/* Named constants for Chart: '<S1>/Chart' */
21#define IN_ControlledDrive ((uint8_T)1U)
22#define IN_EmergencyStop ((uint8_T)1U)
23#define IN_FWD ((uint8_T)1U)
24#define IN_ManualDrive ((uint8_T)2U)
25#define IN_NO_ACTIVE_CHILD ((uint8_T)0U)
26#define IN_REV ((uint8_T)2U)
27#define IN_VehicleControlOff ((uint8_T)2U)
28#define IN_VehicleControlOn ((uint8_T)3U)
29#define IN_VehicleIdle ((uint8_T)4U)
30
31/* Block signals and states (default storage) */
32DW rtDW;
33
34/* External inputs (root inport signals with default storage) */
35ExtU rtU;
36
37/* External outputs (root outports fed by signals with default storage) */
38ExtY rtY;
39
40/* Real-time model */
41RT_MODEL rtM_;
42RT_MODEL *const rtM = &rtM_;
43
44/* Model step function */
45void ManageVehicleStates_sil_sil_ec_step(void)
46{
47 int8_T rtb_remoteControl;
48
49 /* Switch: '<S3>/holdSwitch' incorporates:
50 * DataTypeConversion: '<S3>/DataTypeConversion'
51 * Inport: '<Root>/remoteCtrlCmd'
52 * UnitDelay: '<S3>/Unit Delay'
53 */
54 if (rtU.remoteCtrlCmd != 0) {
55 rtb_remoteControl = rtU.remoteCtrlCmd;
56 } else {
57 rtb_remoteControl = rtDW.UnitDelay_DSTATE;
58 }
59
60 /* End of Switch: '<S3>/holdSwitch' */
61
62 /* Chart: '<S1>/Chart' incorporates:
63 * Inport: '<Root>/emergencyStopObstacle'
64 * Inport: '<Root>/gyroReady'
65 */
66 /* Gateway: ManageVehicleStates_sil_sil_ec/Chart */
67 /* During: ManageVehicleStates_sil_sil_ec/Chart */
68 if (rtDW.is_active_c6_ManageVehicleState == 0U) {
69 /* Entry: ManageVehicleStates_sil_sil_ec/Chart */
70 rtDW.is_active_c6_ManageVehicleState = 1U;
71
72 /* Entry Internal: ManageVehicleStates_sil_sil_ec/Chart */
73 /* Transition: '<S2>:4' */
74 rtDW.is_c6_ManageVehicleStates_sil_s = IN_VehicleControlOff;
75 rtDW.VehicleControlOff = true;
76
77 /* Outport: '<Root>/gear' */
78 /* Entry 'VehicleControlOff': '<S2>:3' */
79 /* '<S2>:3:1' gear = 0; */
80 rtY.gear = 0.0;
81
82 /* Outport: '<Root>/autopilot' */
83 /* '<S2>:3:1' autopilot = false; */
84 rtY.autopilot = false;
85 } else {
86 switch (rtDW.is_c6_ManageVehicleStates_sil_s) {
87 case IN_EmergencyStop:
88 /* Outport: '<Root>/autopilot' */
89 rtY.autopilot = false;
90
91 /* During 'EmergencyStop': '<S2>:34' */
92 /* '<S2>:35:1' sf_internal_predicateOutput = remoteControl == REMOTE_STOP; */
93 if (rtb_remoteControl == rtP.REMOTE_STOP) {
94 /* Transition: '<S2>:35' */
95 rtDW.EmergencyStop = false;
96 rtDW.is_c6_ManageVehicleStates_sil_s = IN_VehicleControlOff;
97 rtDW.VehicleControlOff = true;
98
99 /* Outport: '<Root>/gear' */
100 /* Entry 'VehicleControlOff': '<S2>:3' */
101 /* '<S2>:3:1' gear = 0; */
102 rtY.gear = 0.0;
103
104 /* Outport: '<Root>/autopilot' */
105 /* '<S2>:3:1' autopilot = false; */
106 rtY.autopilot = false;
107 } else {
108 /* '<S2>:56:1' sf_internal_predicateOutput = remoteControl == REMOTE_DRIVE_REV; */
109 if (rtb_remoteControl == rtP.REMOTE_DRIVE_REV) {
110 /* Transition: '<S2>:56' */
111 rtDW.EmergencyStop = false;
112 rtDW.is_c6_ManageVehicleStates_sil_s = IN_VehicleControlOn;
113 rtDW.VehicleControlOn = true;
114
115 /* Entry Internal 'VehicleControlOn': '<S2>:5' */
116 /* Transition: '<S2>:47' */
117 rtDW.is_VehicleControlOn = IN_ManualDrive;
118
119 /* Outport: '<Root>/autopilot' */
120 /* Entry 'ManualDrive': '<S2>:37' */
121 /* '<S2>:37:1' gear = 0; */
122 /* '<S2>:37:1' autopilot = false; */
123 rtY.autopilot = false;
124
125 /* Entry Internal 'ManualDrive': '<S2>:37' */
126 /* Transition: '<S2>:61' */
127 rtDW.is_ManualDrive = IN_FWD;
128 rtDW.tp_FWD = 1U;
129
130 /* Outport: '<Root>/gear' */
131 /* Entry 'FWD': '<S2>:62' */
132 /* '<S2>:62:1' gear = 1; */
133 rtY.gear = 1.0;
134 }
135 }
136 break;
137
138 case IN_VehicleControlOff:
139 /* Outport: '<Root>/autopilot' */
140 rtY.autopilot = false;
141
142 /* During 'VehicleControlOff': '<S2>:3' */
143 /* '<S2>:50:1' sf_internal_predicateOutput = remoteControl == REMOTE_START; */
144 if (rtb_remoteControl == rtP.REMOTE_START) {
145 /* Transition: '<S2>:50' */
146 rtDW.VehicleControlOff = false;
147 rtDW.is_c6_ManageVehicleStates_sil_s = IN_VehicleControlOn;
148 rtDW.VehicleControlOn = true;
149
150 /* Entry Internal 'VehicleControlOn': '<S2>:5' */
151 /* Transition: '<S2>:47' */
152 rtDW.is_VehicleControlOn = IN_ManualDrive;
153
154 /* Outport: '<Root>/autopilot' */
155 /* Entry 'ManualDrive': '<S2>:37' */
156 /* '<S2>:37:1' gear = 0; */
157 /* '<S2>:37:1' autopilot = false; */
158 rtY.autopilot = false;
159
160 /* Entry Internal 'ManualDrive': '<S2>:37' */
161 /* Transition: '<S2>:61' */
162 rtDW.is_ManualDrive = IN_FWD;
163 rtDW.tp_FWD = 1U;
164
165 /* Outport: '<Root>/gear' */
166 /* Entry 'FWD': '<S2>:62' */
167 /* '<S2>:62:1' gear = 1; */
168 rtY.gear = 1.0;
169 } else {
170 /* '<S2>:8:1' sf_internal_predicateOutput = gyroReady == true && ... */
171 /* '<S2>:8:1' remoteControl ~= REMOTE_STOP; */
172 if (rtU.gyroReady && (rtb_remoteControl != rtP.REMOTE_STOP)) {
173 /* Transition: '<S2>:8' */
174 rtDW.VehicleControlOff = false;
175 rtDW.is_c6_ManageVehicleStates_sil_s = IN_VehicleIdle;
176 rtDW.VehicleIdle = true;
177
178 /* Outport: '<Root>/gear' */
179 /* Entry 'VehicleIdle': '<S2>:29' */
180 /* '<S2>:29:1' gear = 0; */
181 rtY.gear = 0.0;
182
183 /* Outport: '<Root>/autopilot' */
184 /* '<S2>:29:1' autopilot = false; */
185 rtY.autopilot = false;
186 }
187 }
188 break;
189
190 case IN_VehicleControlOn:
191 /* During 'VehicleControlOn': '<S2>:5' */
192 /* '<S2>:9:1' sf_internal_predicateOutput = remoteControl == REMOTE_STOP; */
193 if (rtb_remoteControl == rtP.REMOTE_STOP) {
194 /* Transition: '<S2>:9' */
195 /* Exit Internal 'VehicleControlOn': '<S2>:5' */
196 rtDW.tp_ControlledDrive = 0U;
197
198 /* Exit Internal 'ManualDrive': '<S2>:37' */
199 rtDW.tp_FWD = 0U;
200 rtDW.tp_REV = 0U;
201 rtDW.is_ManualDrive = IN_NO_ACTIVE_CHILD;
202 rtDW.is_VehicleControlOn = IN_NO_ACTIVE_CHILD;
203 rtDW.VehicleControlOn = false;
204 rtDW.is_c6_ManageVehicleStates_sil_s = IN_VehicleControlOff;
205 rtDW.VehicleControlOff = true;
206
207 /* Outport: '<Root>/gear' */
208 /* Entry 'VehicleControlOff': '<S2>:3' */
209 /* '<S2>:3:1' gear = 0; */
210 rtY.gear = 0.0;
211
212 /* Outport: '<Root>/autopilot' */
213 /* '<S2>:3:1' autopilot = false; */
214 rtY.autopilot = false;
215 } else {
216 /* '<S2>:21:1' sf_internal_predicateOutput = emergencyStopObstacle == true && ... */
217 /* '<S2>:21:1' remoteControl ~= REMOTE_DRIVE_REV; */
218 if (rtU.emergencyStopObstacle && (rtb_remoteControl !=
219 rtP.REMOTE_DRIVE_REV)) {
220 /* Transition: '<S2>:21' */
221 /* Exit Internal 'VehicleControlOn': '<S2>:5' */
222 rtDW.tp_ControlledDrive = 0U;
223
224 /* Exit Internal 'ManualDrive': '<S2>:37' */
225 rtDW.tp_FWD = 0U;
226 rtDW.tp_REV = 0U;
227 rtDW.is_ManualDrive = IN_NO_ACTIVE_CHILD;
228 rtDW.is_VehicleControlOn = IN_NO_ACTIVE_CHILD;
229 rtDW.VehicleControlOn = false;
230 rtDW.is_c6_ManageVehicleStates_sil_s = IN_EmergencyStop;
231 rtDW.EmergencyStop = true;
232
233 /* Outport: '<Root>/gear' */
234 /* Entry 'EmergencyStop': '<S2>:34' */
235 /* '<S2>:34:1' gear = 0; */
236 rtY.gear = 0.0;
237
238 /* Outport: '<Root>/autopilot' */
239 /* '<S2>:34:1' autopilot = false; */
240 rtY.autopilot = false;
241 } else if (rtDW.is_VehicleControlOn == IN_ControlledDrive) {
242 /* Outport: '<Root>/autopilot' */
243 rtY.autopilot = true;
244
245 /* During 'ControlledDrive': '<S2>:45' */
246 /* '<S2>:52:1' sf_internal_predicateOutput = remoteControl == REMOTE_DRIVE_AUTO_OFF; */
247 if (rtb_remoteControl == rtP.REMOTE_DRIVE_AUTO_OFF) {
248 /* Transition: '<S2>:52' */
249 rtDW.tp_ControlledDrive = 0U;
250 rtDW.is_VehicleControlOn = IN_ManualDrive;
251
252 /* Outport: '<Root>/autopilot' */
253 /* Entry 'ManualDrive': '<S2>:37' */
254 /* '<S2>:37:1' gear = 0; */
255 /* '<S2>:37:1' autopilot = false; */
256 rtY.autopilot = false;
257
258 /* Entry Internal 'ManualDrive': '<S2>:37' */
259 /* Transition: '<S2>:61' */
260 rtDW.is_ManualDrive = IN_FWD;
261 rtDW.tp_FWD = 1U;
262
263 /* Outport: '<Root>/gear' */
264 /* Entry 'FWD': '<S2>:62' */
265 /* '<S2>:62:1' gear = 1; */
266 rtY.gear = 1.0;
267 }
268 } else {
269 /* Outport: '<Root>/autopilot' */
270 rtY.autopilot = false;
271
272 /* During 'ManualDrive': '<S2>:37' */
273 /* '<S2>:51:1' sf_internal_predicateOutput = remoteControl == REMOTE_DRIVE_AUTO_ON; */
274 if (rtb_remoteControl == rtP.REMOTE_DRIVE_AUTO_ON) {
275 /* Transition: '<S2>:51' */
276 /* Exit Internal 'ManualDrive': '<S2>:37' */
277 rtDW.tp_FWD = 0U;
278 rtDW.tp_REV = 0U;
279 rtDW.is_ManualDrive = IN_NO_ACTIVE_CHILD;
280 rtDW.is_VehicleControlOn = IN_ControlledDrive;
281 rtDW.tp_ControlledDrive = 1U;
282
283 /* Outport: '<Root>/gear' */
284 /* Entry 'ControlledDrive': '<S2>:45' */
285 /* '<S2>:45:1' gear = 1; */
286 rtY.gear = 1.0;
287
288 /* Outport: '<Root>/autopilot' */
289 /* '<S2>:45:1' autopilot = true; */
290 rtY.autopilot = true;
291 } else if (rtDW.is_ManualDrive == IN_FWD) {
292 /* During 'FWD': '<S2>:62' */
293 /* '<S2>:64:1' sf_internal_predicateOutput = remoteControl == REMOTE_DRIVE_REV; */
294 if (rtb_remoteControl == rtP.REMOTE_DRIVE_REV) {
295 /* Transition: '<S2>:64' */
296 rtDW.tp_FWD = 0U;
297 rtDW.is_ManualDrive = IN_REV;
298 rtDW.tp_REV = 1U;
299
300 /* Outport: '<Root>/gear' */
301 /* Entry 'REV': '<S2>:63' */
302 /* '<S2>:63:1' gear = -1; */
303 rtY.gear = -1.0;
304 }
305 } else {
306 /* During 'REV': '<S2>:63' */
307 /* '<S2>:60:1' sf_internal_predicateOutput = remoteControl == REMOTE_DRIVE_FWD; */
308 if (rtb_remoteControl == rtP.REMOTE_DRIVE_FWD) {
309 /* Transition: '<S2>:60' */
310 rtDW.tp_REV = 0U;
311 rtDW.is_ManualDrive = IN_FWD;
312 rtDW.tp_FWD = 1U;
313
314 /* Outport: '<Root>/gear' */
315 /* Entry 'FWD': '<S2>:62' */
316 /* '<S2>:62:1' gear = 1; */
317 rtY.gear = 1.0;
318 }
319 }
320 }
321 }
322 break;
323
324 default:
325 /* Outport: '<Root>/autopilot' */
326 rtY.autopilot = false;
327
328 /* During 'VehicleIdle': '<S2>:29' */
329 /* '<S2>:31:1' sf_internal_predicateOutput = remoteControl == REMOTE_START; */
330 if (rtb_remoteControl == rtP.REMOTE_START) {
331 /* Transition: '<S2>:31' */
332 rtDW.VehicleIdle = false;
333 rtDW.is_c6_ManageVehicleStates_sil_s = IN_VehicleControlOn;
334 rtDW.VehicleControlOn = true;
335
336 /* Entry Internal 'VehicleControlOn': '<S2>:5' */
337 /* Transition: '<S2>:47' */
338 rtDW.is_VehicleControlOn = IN_ManualDrive;
339
340 /* Outport: '<Root>/autopilot' */
341 /* Entry 'ManualDrive': '<S2>:37' */
342 /* '<S2>:37:1' gear = 0; */
343 /* '<S2>:37:1' autopilot = false; */
344 rtY.autopilot = false;
345
346 /* Entry Internal 'ManualDrive': '<S2>:37' */
347 /* Transition: '<S2>:61' */
348 rtDW.is_ManualDrive = IN_FWD;
349 rtDW.tp_FWD = 1U;
350
351 /* Outport: '<Root>/gear' */
352 /* Entry 'FWD': '<S2>:62' */
353 /* '<S2>:62:1' gear = 1; */
354 rtY.gear = 1.0;
355 }
356 break;
357 }
358 }
359
360 /* End of Chart: '<S1>/Chart' */
361
362 /* BusCreator: '<S1>/Bus Creator' incorporates:
363 * Outport: '<Root>/VehicleStates'
364 */
365 rtY.VehicleStates_h.VehicleControlOn = rtDW.VehicleControlOn;
366 rtY.VehicleStates_h.VehicleControlOff = rtDW.VehicleControlOff;
367 rtY.VehicleStates_h.EmergencyStop = rtDW.EmergencyStop;
368 rtY.VehicleStates_h.VehicleIdle = rtDW.VehicleIdle;
369
370 /* Update for UnitDelay: '<S3>/Unit Delay' */
371 rtDW.UnitDelay_DSTATE = rtb_remoteControl;
372}
373
374/* Model initialize function */
375void ManageVehicleStates_sil_sil_ec_initialize(void)
376{
377 /* InitializeConditions for UnitDelay: '<S3>/Unit Delay' */
378 rtDW.UnitDelay_DSTATE = rtP.UnitDelay_InitialCondition;
379}
380
381/* Model terminate function */
382void ManageVehicleStates_sil_sil_ec_terminate(void)
383{
384 /* (no terminate code required) */
385}
386
387/*
388 * File trailer for generated code.
389 *
390 * [EOF]
391 */
392