1/*
2 * Arduino_skal.cpp
3 *
4 * Academic License - for use in teaching, academic research, and meeting
5 * course requirements at degree granting institutions only. Not for
6 * government, commercial, or other organizational use.
7 *
8 * Code generation for model "Arduino_skal".
9 *
10 * Model version : 1.1
11 * Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
12 * C++ source code generated on : Thu Apr 15 15:56:50 2021
13 *
14 * Target selection: grt.tlc
15 * Note: GRT includes extra infrastructure and instrumentation for prototyping
16 * Embedded hardware selection: Intel->x86-64 (Windows64)
17 * Code generation objective: Debugging
18 * Validation result: Not run
19 */
20
21#include "Arduino_skal.h"
22#include "Arduino_skal_private.h"
23
24/*
25 * This function updates continuous states using the ODE3 fixed-step
26 * solver algorithm
27 */
28void Arduino_skalModelClass::rt_ertODEUpdateContinuousStates(RTWSolverInfo *si )
29{
30 /* Solver Matrices */
31 static const real_T rt_ODE3_A[3] = {
32 1.0/2.0, 3.0/4.0, 1.0
33 };
34
35 static const real_T rt_ODE3_B[3][3] = {
36 { 1.0/2.0, 0.0, 0.0 },
37
38 { 0.0, 3.0/4.0, 0.0 },
39
40 { 2.0/9.0, 1.0/3.0, 4.0/9.0 }
41 };
42
43 time_T t = rtsiGetT(si);
44 time_T tnew = rtsiGetSolverStopTime(si);
45 time_T h = rtsiGetStepSize(si);
46 real_T *x = rtsiGetContStates(si);
47 ODE3_IntgData *id = static_cast<ODE3_IntgData *>(rtsiGetSolverData(si));
48 real_T *y = id->y;
49 real_T *f0 = id->f[0];
50 real_T *f1 = id->f[1];
51 real_T *f2 = id->f[2];
52 real_T hB[3];
53 int_T i;
54 int_T nXc = 4;
55 rtsiSetSimTimeStep(si,MINOR_TIME_STEP);
56
57 /* Save the state values at time t in y, we'll use x as ynew. */
58 (void) std::memcpy(y, x,
59 static_cast<uint_T>(nXc)*sizeof(real_T));
60
61 /* Assumes that rtsiSetT and ModelOutputs are up-to-date */
62 /* f0 = f(t,y) */
63 rtsiSetdX(si, f0);
64 Arduino_skal_derivatives();
65
66 /* f(:,2) = feval(odefile, t + hA(1), y + f*hB(:,1), args(:)(*)); */
67 hB[0] = h * rt_ODE3_B[0][0];
68 for (i = 0; i < nXc; i++) {
69 x[i] = y[i] + (f0[i]*hB[0]);
70 }
71
72 rtsiSetT(si, t + h*rt_ODE3_A[0]);
73 rtsiSetdX(si, f1);
74 this->step();
75 Arduino_skal_derivatives();
76
77 /* f(:,3) = feval(odefile, t + hA(2), y + f*hB(:,2), args(:)(*)); */
78 for (i = 0; i <= 1; i++) {
79 hB[i] = h * rt_ODE3_B[1][i];
80 }
81
82 for (i = 0; i < nXc; i++) {
83 x[i] = y[i] + (f0[i]*hB[0] + f1[i]*hB[1]);
84 }
85
86 rtsiSetT(si, t + h*rt_ODE3_A[1]);
87 rtsiSetdX(si, f2);
88 this->step();
89 Arduino_skal_derivatives();
90
91 /* tnew = t + hA(3);
92 ynew = y + f*hB(:,3); */
93 for (i = 0; i <= 2; i++) {
94 hB[i] = h * rt_ODE3_B[2][i];
95 }
96
97 for (i = 0; i < nXc; i++) {
98 x[i] = y[i] + (f0[i]*hB[0] + f1[i]*hB[1] + f2[i]*hB[2]);
99 }
100
101 rtsiSetT(si, tnew);
102 rtsiSetSimTimeStep(si,MAJOR_TIME_STEP);
103}
104
105/* Model step function */
106void Arduino_skalModelClass::step()
107{
108 const real_T *tmp_3;
109 real_T currentTime;
110 real_T tmp;
111 real_T tmp_0;
112 real_T tmp_1;
113 real_T tmp_2;
114 real_T u0;
115 int32_T i;
116 int32_T i_0;
117 if (rtmIsMajorTimeStep((&Arduino_skal_M))) {
118 /* set solver stop time */
119 if (!((&Arduino_skal_M)->Timing.clockTick0+1)) {
120 rtsiSetSolverStopTime(&(&Arduino_skal_M)->solverInfo, (((&Arduino_skal_M
121 )->Timing.clockTickH0 + 1) * (&Arduino_skal_M)->Timing.stepSize0 *
122 4294967296.0));
123 } else {
124 rtsiSetSolverStopTime(&(&Arduino_skal_M)->solverInfo, (((&Arduino_skal_M
125 )->Timing.clockTick0 + 1) * (&Arduino_skal_M)->Timing.stepSize0 +
126 (&Arduino_skal_M)->Timing.clockTickH0 * (&Arduino_skal_M)
127 ->Timing.stepSize0 * 4294967296.0));
128 }
129 } /* end MajorTimeStep */
130
131 /* Update absolute time of base rate at minor time step */
132 if (rtmIsMinorTimeStep((&Arduino_skal_M))) {
133 (&Arduino_skal_M)->Timing.t[0] = rtsiGetT(&(&Arduino_skal_M)->solverInfo);
134 }
135
136 if (rtmIsMajorTimeStep((&Arduino_skal_M))) {
137 /* Constant: '<S1>/X0' */
138 Arduino_skal_B.X0[0] = Arduino_skal_P.X0_Value[0];
139 Arduino_skal_B.X0[1] = Arduino_skal_P.X0_Value[1];
140 Arduino_skal_B.X0[2] = Arduino_skal_P.X0_Value[2];
141 Arduino_skal_B.X0[3] = Arduino_skal_P.X0_Value[3];
142 }
143
144 /* Integrator: '<S1>/MemoryX' */
145 if (Arduino_skal_DW.MemoryX_IWORK != 0) {
146 Arduino_skal_X.MemoryX_CSTATE[0] = Arduino_skal_B.X0[0];
147 Arduino_skal_X.MemoryX_CSTATE[1] = Arduino_skal_B.X0[1];
148 Arduino_skal_X.MemoryX_CSTATE[2] = Arduino_skal_B.X0[2];
149 Arduino_skal_X.MemoryX_CSTATE[3] = Arduino_skal_B.X0[3];
150 }
151
152 /* Integrator: '<S1>/MemoryX' */
153 Arduino_skal_B.MemoryX[0] = Arduino_skal_X.MemoryX_CSTATE[0];
154
155 /* Gain: '<Root>/Gain' */
156 u0 = Arduino_skal_P.K[0] * Arduino_skal_B.MemoryX[0];
157
158 /* Integrator: '<S1>/MemoryX' */
159 Arduino_skal_B.MemoryX[1] = Arduino_skal_X.MemoryX_CSTATE[1];
160
161 /* Gain: '<Root>/Gain' */
162 u0 += Arduino_skal_P.K[1] * Arduino_skal_B.MemoryX[1];
163
164 /* Integrator: '<S1>/MemoryX' */
165 Arduino_skal_B.MemoryX[2] = Arduino_skal_X.MemoryX_CSTATE[2];
166
167 /* Gain: '<Root>/Gain' */
168 u0 += Arduino_skal_P.K[2] * Arduino_skal_B.MemoryX[2];
169
170 /* Integrator: '<S1>/MemoryX' */
171 Arduino_skal_B.MemoryX[3] = Arduino_skal_X.MemoryX_CSTATE[3];
172
173 /* Gain: '<Root>/Gain' */
174 u0 += Arduino_skal_P.K[3] * Arduino_skal_B.MemoryX[3];
175
176 /* Gain: '<Root>/Gain' */
177 Arduino_skal_B.Gain = u0;
178 if (rtmIsMajorTimeStep((&Arduino_skal_M))) {
179 /* MATLAB Function: '<S51>/SqrtUsedFcn' incorporates:
180 * Constant: '<S2>/CovarianceZ'
181 * Constant: '<S51>/isSqrtUsed'
182 */
183 /* : if isSqrtUsed */
184 if (Arduino_skal_P.isSqrtUsed_Value) {
185 /* : P = u*u.'; */
186 for (i = 0; i < 4; i++) {
187 for (i_0 = 0; i_0 < 4; i_0++) {
188 Arduino_skal_B.P[i_0 + (i << 2)] = 0.0;
189 Arduino_skal_B.P[i_0 + (i << 2)] +=
190 Arduino_skal_P.CovarianceZ_Value[i_0] *
191 Arduino_skal_P.CovarianceZ_Value[i];
192 Arduino_skal_B.P[i_0 + (i << 2)] +=
193 Arduino_skal_P.CovarianceZ_Value[i_0 + 4] *
194 Arduino_skal_P.CovarianceZ_Value[i + 4];
195 Arduino_skal_B.P[i_0 + (i << 2)] +=
196 Arduino_skal_P.CovarianceZ_Value[i_0 + 8] *
197 Arduino_skal_P.CovarianceZ_Value[i + 8];
198 Arduino_skal_B.P[i_0 + (i << 2)] +=
199 Arduino_skal_P.CovarianceZ_Value[i_0 + 12] *
200 Arduino_skal_P.CovarianceZ_Value[i + 12];
201 }
202 }
203 } else {
204 /* : else */
205 /* : P = u; */
206 std::memcpy(&Arduino_skal_B.P[0], &Arduino_skal_P.CovarianceZ_Value[0],
207 sizeof(real_T) << 4U);
208 }
209
210 /* End of MATLAB Function: '<S51>/SqrtUsedFcn' */
211 }
212
213 /* Product: '<S22>/A[k]*xhat[k|k-1]' incorporates:
214 * Constant: '<S1>/A'
215 */
216 tmp_3 = &Arduino_skal_P.A_Value[0];
217 tmp = Arduino_skal_B.MemoryX[0];
218 tmp_0 = Arduino_skal_B.MemoryX[1];
219 tmp_1 = Arduino_skal_B.MemoryX[2];
220 tmp_2 = Arduino_skal_B.MemoryX[3];
221 for (i = 0; i < 4; i++) {
222 u0 = tmp_3[i] * tmp;
223 u0 += tmp_3[i + 4] * tmp_0;
224 u0 += tmp_3[i + 8] * tmp_1;
225 u0 += tmp_3[i + 12] * tmp_2;
226
227 /* Product: '<S22>/A[k]*xhat[k|k-1]' */
228 Arduino_skal_B.Akxhatkk1[i] = u0;
229 }
230
231 /* End of Product: '<S22>/A[k]*xhat[k|k-1]' */
232
233 /* Step: '<Root>/Step' */
234 currentTime = (&Arduino_skal_M)->Timing.t[0];
235 if (currentTime < Arduino_skal_P.Step_Time) {
236 /* Step: '<Root>/Step' */
237 Arduino_skal_B.Step = Arduino_skal_P.Step_Y0;
238 } else {
239 /* Step: '<Root>/Step' */
240 Arduino_skal_B.Step = Arduino_skal_P.Step_YFinal;
241 }
242
243 /* End of Step: '<Root>/Step' */
244
245 /* Gain: '<Root>/Kr' */
246 Arduino_skal_B.Kr = Arduino_skal_P.Kr * Arduino_skal_B.Step;
247
248 /* Sum: '<Root>/Sum5' */
249 Arduino_skal_B.Sum5 = Arduino_skal_B.Kr - Arduino_skal_B.Gain;
250
251 /* Saturate: '<Root>/Saturation' */
252 u0 = Arduino_skal_B.Sum5;
253 tmp = Arduino_skal_P.Saturation_LowerSat;
254 tmp_0 = Arduino_skal_P.Saturation_UpperSat;
255 if (u0 > tmp_0) {
256 /* Saturate: '<Root>/Saturation' */
257 Arduino_skal_B.Saturation = tmp_0;
258 } else if (u0 < tmp) {
259 /* Saturate: '<Root>/Saturation' */
260 Arduino_skal_B.Saturation = tmp;
261 } else {
262 /* Saturate: '<Root>/Saturation' */
263 Arduino_skal_B.Saturation = u0;
264 }
265
266 /* End of Saturate: '<Root>/Saturation' */
267
268 /* Product: '<S22>/B[k]*u[k]' incorporates:
269 * Constant: '<S1>/B'
270 */
271 currentTime = Arduino_skal_B.Saturation;
272 u0 = Arduino_skal_P.B_Value[0];
273
274 /* Product: '<S22>/B[k]*u[k]' */
275 Arduino_skal_B.Bkuk[0] = u0 * currentTime;
276
277 /* Product: '<S22>/B[k]*u[k]' incorporates:
278 * Constant: '<S1>/B'
279 */
280 u0 = Arduino_skal_P.B_Value[1];
281
282 /* Product: '<S22>/B[k]*u[k]' */
283 Arduino_skal_B.Bkuk[1] = u0 * currentTime;
284
285 /* Product: '<S22>/B[k]*u[k]' incorporates:
286 * Constant: '<S1>/B'
287 */
288 u0 = Arduino_skal_P.B_Value[2];
289
290 /* Product: '<S22>/B[k]*u[k]' */
291 Arduino_skal_B.Bkuk[2] = u0 * currentTime;
292
293 /* Product: '<S22>/B[k]*u[k]' incorporates:
294 * Constant: '<S1>/B'
295 */
296 u0 = Arduino_skal_P.B_Value[3];
297
298 /* Product: '<S22>/B[k]*u[k]' */
299 Arduino_skal_B.Bkuk[3] = u0 * currentTime;
300
301 /* Outputs for Enabled SubSystem: '<S22>/MeasurementUpdate' incorporates:
302 * EnablePort: '<S53>/Enable'
303 */
304 if (rtmIsMajorTimeStep((&Arduino_skal_M)) && rtmIsMajorTimeStep
305 ((&Arduino_skal_M))) {
306 /* Constant: '<S1>/Enable' */
307 if (Arduino_skal_P.Enable_Value) {
308 Arduino_skal_DW.MeasurementUpdate_MODE = true;
309 } else if (Arduino_skal_DW.MeasurementUpdate_MODE) {
310 /* Disable for Product: '<S53>/Product3' incorporates:
311 * Outport: '<S53>/L*(y[k]-yhat[k|k-1])'
312 */
313 Arduino_skal_B.Product3[0] = Arduino_skal_P.Lykyhatkk1_Y0;
314 Arduino_skal_B.Product3[1] = Arduino_skal_P.Lykyhatkk1_Y0;
315 Arduino_skal_B.Product3[2] = Arduino_skal_P.Lykyhatkk1_Y0;
316 Arduino_skal_B.Product3[3] = Arduino_skal_P.Lykyhatkk1_Y0;
317 Arduino_skal_DW.MeasurementUpdate_MODE = false;
318 }
319
320 /* End of Constant: '<S1>/Enable' */
321 }
322
323 if (Arduino_skal_DW.MeasurementUpdate_MODE) {
324 /* Product: '<S53>/C[k]*xhat[k|k-1]' incorporates:
325 * Constant: '<S1>/C'
326 * Product: '<S53>/Product3'
327 */
328 tmp_3 = &Arduino_skal_P.C_Value[0];
329 tmp = Arduino_skal_B.MemoryX[0];
330 tmp_0 = Arduino_skal_B.MemoryX[1];
331 tmp_1 = Arduino_skal_B.MemoryX[2];
332 tmp_2 = Arduino_skal_B.MemoryX[3];
333
334 /* Product: '<S53>/D[k]*u[k]' */
335 currentTime = Arduino_skal_B.Saturation;
336 for (i = 0; i < 2; i++) {
337 /* Product: '<S53>/C[k]*xhat[k|k-1]' */
338 u0 = tmp_3[i] * tmp;
339 u0 += tmp_3[i + 2] * tmp_0;
340 u0 += tmp_3[i + 4] * tmp_1;
341 u0 += tmp_3[i + 6] * tmp_2;
342
343 /* Product: '<S53>/C[k]*xhat[k|k-1]' */
344 Arduino_skal_B.Ckxhatkk1[i] = u0;
345
346 /* Product: '<S53>/D[k]*u[k]' incorporates:
347 * Constant: '<S1>/D'
348 */
349 u0 = Arduino_skal_P.D_Value[i];
350
351 /* Product: '<S53>/D[k]*u[k]' */
352 Arduino_skal_B.Dkuk[i] = u0 * currentTime;
353
354 /* Sum: '<S53>/Add1' incorporates:
355 * Product: '<S53>/D[k]*u[k]'
356 */
357 Arduino_skal_B.yhatkk1[i] = Arduino_skal_B.Ckxhatkk1[i] +
358 Arduino_skal_B.Dkuk[i];
359
360 /* Sum: '<S53>/Sum' incorporates:
361 * Constant: '<Root>/Constant'
362 * Sum: '<S53>/Add1'
363 */
364 Arduino_skal_B.Sum[i] = Arduino_skal_P.Constant_Value[i] -
365 Arduino_skal_B.yhatkk1[i];
366 }
367
368 /* Product: '<S53>/Product3' incorporates:
369 * Constant: '<S2>/KalmanGainL'
370 * Product: '<S53>/C[k]*xhat[k|k-1]'
371 * Sum: '<S53>/Sum'
372 */
373 tmp_3 = &Arduino_skal_P.KalmanGainL_Value[0];
374 tmp = Arduino_skal_B.Sum[0];
375 tmp_0 = Arduino_skal_B.Sum[1];
376 for (i = 0; i < 4; i++) {
377 /* Product: '<S53>/Product3' */
378 Arduino_skal_B.Product3[i] = 0.0;
379 Arduino_skal_B.Product3[i] += tmp_3[i] * tmp;
380 Arduino_skal_B.Product3[i] += tmp_3[i + 4] * tmp_0;
381 }
382 }
383
384 /* End of Outputs for SubSystem: '<S22>/MeasurementUpdate' */
385
386 /* Sum: '<S22>/Add' incorporates:
387 * Product: '<S22>/B[k]*u[k]'
388 * Product: '<S53>/Product3'
389 */
390 Arduino_skal_B.Add[0] = (Arduino_skal_B.Bkuk[0] + Arduino_skal_B.Akxhatkk1[0])
391 + Arduino_skal_B.Product3[0];
392 Arduino_skal_B.Add[1] = (Arduino_skal_B.Bkuk[1] + Arduino_skal_B.Akxhatkk1[1])
393 + Arduino_skal_B.Product3[1];
394 Arduino_skal_B.Add[2] = (Arduino_skal_B.Bkuk[2] + Arduino_skal_B.Akxhatkk1[2])
395 + Arduino_skal_B.Product3[2];
396 Arduino_skal_B.Add[3] = (Arduino_skal_B.Bkuk[3] + Arduino_skal_B.Akxhatkk1[3])
397 + Arduino_skal_B.Product3[3];
398 if (rtmIsMajorTimeStep((&Arduino_skal_M))) {
399 /* Matfile logging */
400 rt_UpdateTXYLogVars((&Arduino_skal_M)->rtwLogInfo, ((&Arduino_skal_M)
401 ->Timing.t));
402 } /* end MajorTimeStep */
403
404 if (rtmIsMajorTimeStep((&Arduino_skal_M))) {
405 /* Update for Integrator: '<S1>/MemoryX' */
406 Arduino_skal_DW.MemoryX_IWORK = 0;
407 } /* end MajorTimeStep */
408
409 if (rtmIsMajorTimeStep((&Arduino_skal_M))) {
410 /* signal main to stop simulation */
411 { /* Sample time: [0.0s, 0.0s] */
412 if ((rtmGetTFinal((&Arduino_skal_M))!=-1) &&
413 !((rtmGetTFinal((&Arduino_skal_M))-((((&Arduino_skal_M)
414 ->Timing.clockTick1+(&Arduino_skal_M)->Timing.clockTickH1*
415 4294967296.0)) * 0.2)) > ((((&Arduino_skal_M)->Timing.clockTick1+
416 (&Arduino_skal_M)->Timing.clockTickH1* 4294967296.0)) * 0.2) *
417 (DBL_EPSILON))) {
418 rtmSetErrorStatus((&Arduino_skal_M), "Simulation finished");
419 }
420 }
421
422 rt_ertODEUpdateContinuousStates(&(&Arduino_skal_M)->solverInfo);
423
424 /* Update absolute time for base rate */
425 /* The "clockTick0" counts the number of times the code of this task has
426 * been executed. The absolute time is the multiplication of "clockTick0"
427 * and "Timing.stepSize0". Size of "clockTick0" ensures timer will not
428 * overflow during the application lifespan selected.
429 * Timer of this task consists of two 32 bit unsigned integers.
430 * The two integers represent the low bits Timing.clockTick0 and the high bits
431 * Timing.clockTickH0. When the low bit overflows to 0, the high bits increment.
432 */
433 if (!(++(&Arduino_skal_M)->Timing.clockTick0)) {
434 ++(&Arduino_skal_M)->Timing.clockTickH0;
435 }
436
437 (&Arduino_skal_M)->Timing.t[0] = rtsiGetSolverStopTime(&(&Arduino_skal_M)
438 ->solverInfo);
439
440 {
441 /* Update absolute timer for sample time: [0.2s, 0.0s] */
442 /* The "clockTick1" counts the number of times the code of this task has
443 * been executed. The resolution of this integer timer is 0.2, which is the step size
444 * of the task. Size of "clockTick1" ensures timer will not overflow during the
445 * application lifespan selected.
446 * Timer of this task consists of two 32 bit unsigned integers.
447 * The two integers represent the low bits Timing.clockTick1 and the high bits
448 * Timing.clockTickH1. When the low bit overflows to 0, the high bits increment.
449 */
450 (&Arduino_skal_M)->Timing.clockTick1++;
451 if (!(&Arduino_skal_M)->Timing.clockTick1) {
452 (&Arduino_skal_M)->Timing.clockTickH1++;
453 }
454 }
455 } /* end MajorTimeStep */
456}
457
458/* Derivatives for root system: '<Root>' */
459void Arduino_skalModelClass::Arduino_skal_derivatives()
460{
461 XDot_Arduino_skal_T *_rtXdot;
462 _rtXdot = ((XDot_Arduino_skal_T *) (&Arduino_skal_M)->derivs);
463
464 /* Derivatives for Integrator: '<S1>/MemoryX' */
465 _rtXdot->MemoryX_CSTATE[0] = Arduino_skal_B.Add[0];
466 _rtXdot->MemoryX_CSTATE[1] = Arduino_skal_B.Add[1];
467 _rtXdot->MemoryX_CSTATE[2] = Arduino_skal_B.Add[2];
468 _rtXdot->MemoryX_CSTATE[3] = Arduino_skal_B.Add[3];
469}
470
471/* Model initialize function */
472void Arduino_skalModelClass::initialize()
473{
474 /* Registration code */
475
476 /* initialize non-finites */
477 rt_InitInfAndNaN(sizeof(real_T));
478
479 {
480 /* Setup solver object */
481 rtsiSetSimTimeStepPtr(&(&Arduino_skal_M)->solverInfo, &(&Arduino_skal_M)
482 ->Timing.simTimeStep);
483 rtsiSetTPtr(&(&Arduino_skal_M)->solverInfo, &rtmGetTPtr((&Arduino_skal_M)));
484 rtsiSetStepSizePtr(&(&Arduino_skal_M)->solverInfo, &(&Arduino_skal_M)
485 ->Timing.stepSize0);
486 rtsiSetdXPtr(&(&Arduino_skal_M)->solverInfo, &(&Arduino_skal_M)->derivs);
487 rtsiSetContStatesPtr(&(&Arduino_skal_M)->solverInfo, (real_T **)
488 &(&Arduino_skal_M)->contStates);
489 rtsiSetNumContStatesPtr(&(&Arduino_skal_M)->solverInfo, &(&Arduino_skal_M)
490 ->Sizes.numContStates);
491 rtsiSetNumPeriodicContStatesPtr(&(&Arduino_skal_M)->solverInfo,
492 &(&Arduino_skal_M)->Sizes.numPeriodicContStates);
493 rtsiSetPeriodicContStateIndicesPtr(&(&Arduino_skal_M)->solverInfo,
494 &(&Arduino_skal_M)->periodicContStateIndices);
495 rtsiSetPeriodicContStateRangesPtr(&(&Arduino_skal_M)->solverInfo,
496 &(&Arduino_skal_M)->periodicContStateRanges);
497 rtsiSetErrorStatusPtr(&(&Arduino_skal_M)->solverInfo, (&rtmGetErrorStatus
498 ((&Arduino_skal_M))));
499 rtsiSetRTModelPtr(&(&Arduino_skal_M)->solverInfo, (&Arduino_skal_M));
500 }
501
502 rtsiSetSimTimeStep(&(&Arduino_skal_M)->solverInfo, MAJOR_TIME_STEP);
503 (&Arduino_skal_M)->intgData.y = (&Arduino_skal_M)->odeY;
504 (&Arduino_skal_M)->intgData.f[0] = (&Arduino_skal_M)->odeF[0];
505 (&Arduino_skal_M)->intgData.f[1] = (&Arduino_skal_M)->odeF[1];
506 (&Arduino_skal_M)->intgData.f[2] = (&Arduino_skal_M)->odeF[2];
507 (&Arduino_skal_M)->contStates = ((X_Arduino_skal_T *) &Arduino_skal_X);
508 rtsiSetSolverData(&(&Arduino_skal_M)->solverInfo, static_cast<void *>
509 (&(&Arduino_skal_M)->intgData));
510 rtsiSetSolverName(&(&Arduino_skal_M)->solverInfo,"ode3");
511 rtmSetTPtr((&Arduino_skal_M), &(&Arduino_skal_M)->Timing.tArray[0]);
512 rtmSetTFinal((&Arduino_skal_M), 10.0);
513 (&Arduino_skal_M)->Timing.stepSize0 = 0.2;
514 rtmSetFirstInitCond((&Arduino_skal_M), 1);
515
516 /* Setup for data logging */
517 {
518 static RTWLogInfo rt_DataLoggingInfo;
519 rt_DataLoggingInfo.loggingInterval = (NULL);
520 (&Arduino_skal_M)->rtwLogInfo = &rt_DataLoggingInfo;
521 }
522
523 /* Setup for data logging */
524 {
525 rtliSetLogXSignalInfo((&Arduino_skal_M)->rtwLogInfo, (NULL));
526 rtliSetLogXSignalPtrs((&Arduino_skal_M)->rtwLogInfo, (NULL));
527 rtliSetLogT((&Arduino_skal_M)->rtwLogInfo, "tout");
528 rtliSetLogX((&Arduino_skal_M)->rtwLogInfo, "");
529 rtliSetLogXFinal((&Arduino_skal_M)->rtwLogInfo, "");
530 rtliSetLogVarNameModifier((&Arduino_skal_M)->rtwLogInfo, "rt_");
531 rtliSetLogFormat((&Arduino_skal_M)->rtwLogInfo, 4);
532 rtliSetLogMaxRows((&Arduino_skal_M)->rtwLogInfo, 0);
533 rtliSetLogDecimation((&Arduino_skal_M)->rtwLogInfo, 1);
534 rtliSetLogY((&Arduino_skal_M)->rtwLogInfo, "");
535 rtliSetLogYSignalInfo((&Arduino_skal_M)->rtwLogInfo, (NULL));
536 rtliSetLogYSignalPtrs((&Arduino_skal_M)->rtwLogInfo, (NULL));
537 }
538
539 /* Matfile logging */
540 rt_StartDataLoggingWithStartTime((&Arduino_skal_M)->rtwLogInfo, 0.0,
541 rtmGetTFinal((&Arduino_skal_M)), (&Arduino_skal_M)->Timing.stepSize0,
542 (&rtmGetErrorStatus((&Arduino_skal_M))));
543
544 /* Start for Constant: '<S1>/X0' */
545 Arduino_skal_B.X0[0] = Arduino_skal_P.X0_Value[0];
546 Arduino_skal_B.X0[1] = Arduino_skal_P.X0_Value[1];
547 Arduino_skal_B.X0[2] = Arduino_skal_P.X0_Value[2];
548 Arduino_skal_B.X0[3] = Arduino_skal_P.X0_Value[3];
549
550 /* InitializeConditions for Integrator: '<S1>/MemoryX' */
551 if (rtmIsFirstInitCond((&Arduino_skal_M))) {
552 Arduino_skal_X.MemoryX_CSTATE[0] = 0.0;
553 Arduino_skal_X.MemoryX_CSTATE[1] = 0.0;
554 Arduino_skal_X.MemoryX_CSTATE[2] = 0.0;
555 Arduino_skal_X.MemoryX_CSTATE[3] = 0.0;
556 }
557
558 Arduino_skal_DW.MemoryX_IWORK = 1;
559
560 /* End of InitializeConditions for Integrator: '<S1>/MemoryX' */
561
562 /* SystemInitialize for Enabled SubSystem: '<S22>/MeasurementUpdate' */
563 /* SystemInitialize for Product: '<S53>/Product3' incorporates:
564 * Outport: '<S53>/L*(y[k]-yhat[k|k-1])'
565 */
566 Arduino_skal_B.Product3[0] = Arduino_skal_P.Lykyhatkk1_Y0;
567 Arduino_skal_B.Product3[1] = Arduino_skal_P.Lykyhatkk1_Y0;
568 Arduino_skal_B.Product3[2] = Arduino_skal_P.Lykyhatkk1_Y0;
569 Arduino_skal_B.Product3[3] = Arduino_skal_P.Lykyhatkk1_Y0;
570
571 /* End of SystemInitialize for SubSystem: '<S22>/MeasurementUpdate' */
572
573 /* set "at time zero" to false */
574 if (rtmIsFirstInitCond((&Arduino_skal_M))) {
575 rtmSetFirstInitCond((&Arduino_skal_M), 0);
576 }
577}
578
579/* Model terminate function */
580void Arduino_skalModelClass::terminate()
581{
582 /* (no terminate code required) */
583}
584
585/* Constructor */
586Arduino_skalModelClass::Arduino_skalModelClass() :
587 Arduino_skal_B(),
588 Arduino_skal_DW(),
589 Arduino_skal_X(),
590 Arduino_skal_M()
591{
592 /* Currently there is no constructor body generated.*/
593}
594
595/* Destructor */
596Arduino_skalModelClass::~Arduino_skalModelClass()
597{
598 /* Currently there is no destructor body generated.*/
599}
600
601/* Real-Time Model get method */
602RT_MODEL_Arduino_skal_T * Arduino_skalModelClass::getRTM()
603{
604 return (&Arduino_skal_M);
605}
606