-
Notifications
You must be signed in to change notification settings - Fork 4
/
obstacleStopper.cpp
320 lines (253 loc) · 10.2 KB
/
obstacleStopper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
//
// 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: obstacleStopper.cpp
//
// Code generated for Simulink model 'obstacleStopper'.
//
// Model version : 1.8
// Simulink Coder version : 8.10 (R2016a) 10-Feb-2016
// C/C++ source code generated on : Fri Jan 27 11:14:49 2017
//
// Target selection: ert.tlc
// Embedded hardware selection: Generic->Unspecified (assume 32-bit Generic)
// Code generation objectives: Unspecified
// Validation result: Not run
//
#include "obstacleStopper.h"
#include "obstacleStopper_private.h"
#define obstacleStopper_MessageQueueLen (1)
// Block signals (auto storage)
B_obstacleStopper_T obstacleStopper_B;
// Block states (auto storage)
DW_obstacleStopper_T obstacleStopper_DW;
// Real-time model
RT_MODEL_obstacleStopper_T obstacleStopper_M_;
RT_MODEL_obstacleStopper_T *const obstacleStopper_M = &obstacleStopper_M_;
// Model step function
void obstacleStopper_step(void)
{
boolean_T timedOut;
SL_Bus_obstacleStopper_std_msgs_Float32 varargout_2;
boolean_T varargout_1;
real_T rtb_safeValue;
real_T u0;
// Outputs for Atomic SubSystem: '<Root>/Subscribe'
// Start for MATLABSystem: '<S5>/SourceBlock' incorporates:
// Inport: '<S8>/In1'
// MATLABSystem: '<S5>/SourceBlock'
varargout_1 = Sub_obstacleStopper_12.getLatestMessage(&varargout_2);
// Outputs for Enabled SubSystem: '<S5>/Enabled Subsystem' incorporates:
// EnablePort: '<S8>/Enable'
if (varargout_1) {
obstacleStopper_B.In1_d = varargout_2;
}
// End of Start for MATLABSystem: '<S5>/SourceBlock'
// End of Outputs for SubSystem: '<S5>/Enabled Subsystem'
// End of Outputs for SubSystem: '<Root>/Subscribe'
// Outputs for Atomic SubSystem: '<Root>/Subscribe1'
// Start for MATLABSystem: '<S6>/SourceBlock' incorporates:
// Inport: '<S9>/In1'
// MATLABSystem: '<S6>/SourceBlock'
varargout_1 = Sub_obstacleStopper_13.getLatestMessage
(&obstacleStopper_B.BusAssignment);
// Outputs for Enabled SubSystem: '<S6>/Enabled Subsystem' incorporates:
// EnablePort: '<S9>/Enable'
if (varargout_1) {
obstacleStopper_B.In1 = obstacleStopper_B.BusAssignment;
}
// End of Outputs for SubSystem: '<S6>/Enabled Subsystem'
// End of Outputs for SubSystem: '<Root>/Subscribe1'
// Outputs for Atomic SubSystem: '<Root>/Dead Man's Switch'
// MATLAB Function: '<S2>/timeout set to 0 output' incorporates:
// MATLABSystem: '<S6>/SourceBlock'
// Start for MATLABSystem: '<S6>/SourceBlock'
// MATLAB Function 'Dead Man\'s Switch/timeout set to 0 output': '<S7>:1'
// '<S7>:1:4' timedOut=true;
timedOut = true;
// '<S7>:1:5' if isempty(sinceLastMsg)
if (!obstacleStopper_DW.sinceLastMsg_not_empty) {
// '<S7>:1:6' sinceLastMsg=(timeout/stepSize)+1;
obstacleStopper_DW.sinceLastMsg = obstacleStopper_P.DeadMansSwitch_timeout /
obstacleStopper_P.DeadMansSwitch_stepSize + 1.0;
obstacleStopper_DW.sinceLastMsg_not_empty = true;
}
// '<S7>:1:9' safeValue=0;
rtb_safeValue = 0.0;
// Outputs for Atomic SubSystem: '<Root>/Subscribe1'
// if no new message
// after timeout, we output 0
// '<S7>:1:12' if( isNew == true )
if (varargout_1) {
// '<S7>:1:13' sinceLastMsg = 0;
obstacleStopper_DW.sinceLastMsg = 0.0;
} else {
// '<S7>:1:14' else
// '<S7>:1:15' sinceLastMsg = sinceLastMsg+1;
obstacleStopper_DW.sinceLastMsg++;
}
// End of Outputs for SubSystem: '<Root>/Subscribe1'
// Note: we require step size as an input here, and depend on our
// system being executed at a regular rate, or bad things will happen
// '<S7>:1:20' if( sinceLastMsg < timeout/stepSize )
if (obstacleStopper_DW.sinceLastMsg < obstacleStopper_P.DeadMansSwitch_timeout
/ obstacleStopper_P.DeadMansSwitch_stepSize) {
// '<S7>:1:21' timedOut = false;
timedOut = false;
}
// '<S7>:1:24' if( timedOut == false )
if (!timedOut) {
// '<S7>:1:25' safeValue = value;
rtb_safeValue = obstacleStopper_B.In1.Linear.X;
}
// End of MATLAB Function: '<S2>/timeout set to 0 output'
// End of Outputs for SubSystem: '<Root>/Dead Man's Switch'
// BusAssignment: '<Root>/Bus Assignment' incorporates:
// Constant: '<S1>/Constant'
obstacleStopper_B.BusAssignment = obstacleStopper_P.Constant_Value_h;
// Sum: '<S3>/Subtract' incorporates:
// Constant: '<S3>/Constant'
u0 = obstacleStopper_B.In1_d.Data - obstacleStopper_P.Constant_Value_e;
// Saturate: '<S3>/Saturation'
if (u0 > obstacleStopper_P.Saturation_UpperSat) {
u0 = obstacleStopper_P.Saturation_UpperSat;
} else {
if (u0 < obstacleStopper_P.Saturation_LowerSat) {
u0 = obstacleStopper_P.Saturation_LowerSat;
}
}
// End of Saturate: '<S3>/Saturation'
// Signum: '<S3>/Sign'
if (u0 < 0.0) {
u0 = -1.0;
} else if (u0 > 0.0) {
u0 = 1.0;
} else {
if (u0 == 0.0) {
u0 = 0.0;
}
}
// BusAssignment: '<Root>/Bus Assignment' incorporates:
// Product: '<S3>/Product'
// Signum: '<S3>/Sign'
obstacleStopper_B.BusAssignment.Linear.X = u0 * rtb_safeValue;
obstacleStopper_B.BusAssignment.Angular.Z = obstacleStopper_B.In1.Angular.Z;
// Outputs for Atomic SubSystem: '<Root>/Publish'
// Start for MATLABSystem: '<S4>/SinkBlock' incorporates:
// MATLABSystem: '<S4>/SinkBlock'
Pub_obstacleStopper_17.publish(&obstacleStopper_B.BusAssignment);
// End of Outputs for SubSystem: '<Root>/Publish'
}
// Model initialize function
void obstacleStopper_initialize(void)
{
// Registration code
// initialize error status
rtmSetErrorStatus(obstacleStopper_M, (NULL));
// block I/O
(void) memset(((void *) &obstacleStopper_B), 0,
sizeof(B_obstacleStopper_T));
// states (dwork)
(void) memset((void *)&obstacleStopper_DW, 0,
sizeof(DW_obstacleStopper_T));
{
static const char_T tmp[24] = { '/', 'c', 'a', 't', 'v', 'e', 'h', 'i', 'c',
'l', 'e', '/', 'c', 'm', 'd', '_', 'v', 'e', 'l', '_', 's', 'a', 'f', 'e'
};
static const char_T tmp_0[19] = { '/', 'c', 'a', 't', 'v', 'e', 'h', 'i',
'c', 'l', 'e', '/', 'c', 'm', 'd', '_', 'v', 'e', 'l' };
static const char_T tmp_1[34] = { '/', 'c', 'a', 't', 'v', 'e', 'h', 'i',
'c', 'l', 'e', '/', 'd', 'i', 's', 't', 'a', 'n', 'c', 'e', 'E', 's', 't',
'i', 'm', 'a', 't', 'o', 'r', '/', 'd', 'i', 's', 't' };
char_T tmp_2[25];
char_T tmp_3[20];
int32_T i;
// Start for Atomic SubSystem: '<Root>/Subscribe'
// Start for MATLABSystem: '<S5>/SourceBlock'
obstacleStopper_DW.obj_e.isInitialized = 0;
obstacleStopper_DW.obj_e.isInitialized = 1;
for (i = 0; i < 34; i++) {
obstacleStopper_B.cv0[i] = tmp_1[i];
}
obstacleStopper_B.cv0[34] = '\x00';
Sub_obstacleStopper_12.createSubscriber(obstacleStopper_B.cv0,
obstacleStopper_MessageQueueLen);
// End of Start for MATLABSystem: '<S5>/SourceBlock'
// End of Start for SubSystem: '<Root>/Subscribe'
// Start for Atomic SubSystem: '<Root>/Subscribe1'
// Start for MATLABSystem: '<S6>/SourceBlock'
obstacleStopper_DW.obj_l.isInitialized = 0;
obstacleStopper_DW.obj_l.isInitialized = 1;
for (i = 0; i < 19; i++) {
tmp_3[i] = tmp_0[i];
}
tmp_3[19] = '\x00';
Sub_obstacleStopper_13.createSubscriber(tmp_3,
obstacleStopper_MessageQueueLen);
// End of Start for MATLABSystem: '<S6>/SourceBlock'
// End of Start for SubSystem: '<Root>/Subscribe1'
// Start for Atomic SubSystem: '<Root>/Publish'
// Start for MATLABSystem: '<S4>/SinkBlock'
obstacleStopper_DW.obj.isInitialized = 0;
obstacleStopper_DW.obj.isInitialized = 1;
for (i = 0; i < 24; i++) {
tmp_2[i] = tmp[i];
}
tmp_2[24] = '\x00';
Pub_obstacleStopper_17.createPublisher(tmp_2,
obstacleStopper_MessageQueueLen);
// End of Start for MATLABSystem: '<S4>/SinkBlock'
// End of Start for SubSystem: '<Root>/Publish'
// SystemInitialize for Atomic SubSystem: '<Root>/Subscribe'
// SystemInitialize for Enabled SubSystem: '<S5>/Enabled Subsystem'
// SystemInitialize for Outport: '<S8>/Out1'
obstacleStopper_B.In1_d = obstacleStopper_P.Out1_Y0_h;
// End of SystemInitialize for SubSystem: '<S5>/Enabled Subsystem'
// End of SystemInitialize for SubSystem: '<Root>/Subscribe'
// SystemInitialize for Atomic SubSystem: '<Root>/Subscribe1'
// SystemInitialize for Enabled SubSystem: '<S6>/Enabled Subsystem'
// SystemInitialize for Outport: '<S9>/Out1'
obstacleStopper_B.In1 = obstacleStopper_P.Out1_Y0;
// End of SystemInitialize for SubSystem: '<S6>/Enabled Subsystem'
// End of SystemInitialize for SubSystem: '<Root>/Subscribe1'
// SystemInitialize for Atomic SubSystem: '<Root>/Dead Man's Switch'
// SystemInitialize for MATLAB Function: '<S2>/timeout set to 0 output'
obstacleStopper_DW.sinceLastMsg_not_empty = false;
// End of SystemInitialize for SubSystem: '<Root>/Dead Man's Switch'
}
}
// Model terminate function
void obstacleStopper_terminate(void)
{
// Terminate for Atomic SubSystem: '<Root>/Subscribe'
// Start for MATLABSystem: '<S5>/SourceBlock' incorporates:
// Terminate for MATLABSystem: '<S5>/SourceBlock'
if (obstacleStopper_DW.obj_e.isInitialized == 1) {
obstacleStopper_DW.obj_e.isInitialized = 2;
}
// End of Start for MATLABSystem: '<S5>/SourceBlock'
// End of Terminate for SubSystem: '<Root>/Subscribe'
// Terminate for Atomic SubSystem: '<Root>/Subscribe1'
// Start for MATLABSystem: '<S6>/SourceBlock' incorporates:
// Terminate for MATLABSystem: '<S6>/SourceBlock'
if (obstacleStopper_DW.obj_l.isInitialized == 1) {
obstacleStopper_DW.obj_l.isInitialized = 2;
}
// End of Start for MATLABSystem: '<S6>/SourceBlock'
// End of Terminate for SubSystem: '<Root>/Subscribe1'
// Terminate for Atomic SubSystem: '<Root>/Publish'
// Start for MATLABSystem: '<S4>/SinkBlock' incorporates:
// Terminate for MATLABSystem: '<S4>/SinkBlock'
if (obstacleStopper_DW.obj.isInitialized == 1) {
obstacleStopper_DW.obj.isInitialized = 2;
}
// End of Start for MATLABSystem: '<S4>/SinkBlock'
// End of Terminate for SubSystem: '<Root>/Publish'
}
//
// File trailer for generated code.
//
// [EOF]
//