fork download
  1. /*
  2.  * vehicle_behavior_model.c
  3.  *
  4.  * Trial License - for use to evaluate programs for possible purchase as
  5.  * an end-user only.
  6.  *
  7.  * Code generation for model "vehicle_behavior_model".
  8.  *
  9.  * Model version : 1.0
  10.  * Simulink Coder version : 24.1 (R2024a) 19-Nov-2023
  11.  * C source code generated on : Mon Jun 3 16:39:46 2024
  12.  *
  13.  * Target selection: grt.tlc
  14.  * Note: GRT includes extra infrastructure and instrumentation for prototyping
  15.  * Embedded hardware selection: Intel->x86-64 (Windows64)
  16.  * Code generation objectives: Unspecified
  17.  * Validation result: Not run
  18.  */
  19.  
  20. #include "vehicle_behavior_model.h"
  21. #include "vehicle_behavior_model_private.h"
  22.  
  23. /* Block signals (default storage) */
  24. B_vehicle_behavior_model_T vehicle_behavior_model_B;
  25.  
  26. /* Continuous states */
  27. X_vehicle_behavior_model_T vehicle_behavior_model_X;
  28.  
  29. /* Disabled State Vector */
  30. XDis_vehicle_behavior_model_T vehicle_behavior_model_XDis;
  31.  
  32. /* Real-time model */
  33. static RT_MODEL_vehicle_behavior_mod_T vehicle_behavior_model_M_;
  34. RT_MODEL_vehicle_behavior_mod_T *const vehicle_behavior_model_M =
  35. &vehicle_behavior_model_M_;
  36.  
  37. /*
  38.  * This function updates continuous states using the ODE3 fixed-step
  39.  * solver algorithm
  40.  */
  41. static void rt_ertODEUpdateContinuousStates(RTWSolverInfo *si )
  42. {
  43. /* Solver Matrices */
  44. static const real_T rt_ODE3_A[3] = {
  45. 1.0/2.0, 3.0/4.0, 1.0
  46. };
  47.  
  48. static const real_T rt_ODE3_B[3][3] = {
  49. { 1.0/2.0, 0.0, 0.0 },
  50.  
  51. { 0.0, 3.0/4.0, 0.0 },
  52.  
  53. { 2.0/9.0, 1.0/3.0, 4.0/9.0 }
  54. };
  55.  
  56. time_T t = rtsiGetT(si);
  57. time_T tnew = rtsiGetSolverStopTime(si);
  58. time_T h = rtsiGetStepSize(si);
  59. real_T *x = rtsiGetContStates(si);
  60. ODE3_IntgData *id = (ODE3_IntgData *)rtsiGetSolverData(si);
  61. real_T *y = id->y;
  62. real_T *f0 = id->f[0];
  63. real_T *f1 = id->f[1];
  64. real_T *f2 = id->f[2];
  65. real_T hB[3];
  66. int_T i;
  67. int_T nXc = 1;
  68. rtsiSetSimTimeStep(si,MINOR_TIME_STEP);
  69.  
  70. /* Save the state values at time t in y, we'll use x as ynew. */
  71. (void) memcpy(y, x,
  72. (uint_T)nXc*sizeof(real_T));
  73.  
  74. /* Assumes that rtsiSetT and ModelOutputs are up-to-date */
  75. /* f0 = f(t,y) */
  76. rtsiSetdX(si, f0);
  77. vehicle_behavior_model_derivatives();
  78.  
  79. /* f(:,2) = feval(odefile, t + hA(1), y + f*hB(:,1), args(:)(*)); */
  80. hB[0] = h * rt_ODE3_B[0][0];
  81. for (i = 0; i < nXc; i++) {
  82. x[i] = y[i] + (f0[i]*hB[0]);
  83. }
  84.  
  85. rtsiSetT(si, t + h*rt_ODE3_A[0]);
  86. rtsiSetdX(si, f1);
  87. vehicle_behavior_model_step();
  88. vehicle_behavior_model_derivatives();
  89.  
  90. /* f(:,3) = feval(odefile, t + hA(2), y + f*hB(:,2), args(:)(*)); */
  91. for (i = 0; i <= 1; i++) {
  92. hB[i] = h * rt_ODE3_B[1][i];
  93. }
  94.  
  95. for (i = 0; i < nXc; i++) {
  96. x[i] = y[i] + (f0[i]*hB[0] + f1[i]*hB[1]);
  97. }
  98.  
  99. rtsiSetT(si, t + h*rt_ODE3_A[1]);
  100. rtsiSetdX(si, f2);
  101. vehicle_behavior_model_step();
  102. vehicle_behavior_model_derivatives();
  103.  
  104. /* tnew = t + hA(3);
  105.   ynew = y + f*hB(:,3); */
  106. for (i = 0; i <= 2; i++) {
  107. hB[i] = h * rt_ODE3_B[2][i];
  108. }
  109.  
  110. for (i = 0; i < nXc; i++) {
  111. x[i] = y[i] + (f0[i]*hB[0] + f1[i]*hB[1] + f2[i]*hB[2]);
  112. }
  113.  
  114. rtsiSetT(si, tnew);
  115. rtsiSetSimTimeStep(si,MAJOR_TIME_STEP);
  116. }
  117.  
  118. /* Model step function */
  119. void vehicle_behavior_model_step(void)
  120. {
  121. if (rtmIsMajorTimeStep(vehicle_behavior_model_M)) {
  122. /* set solver stop time */
  123. if (!(vehicle_behavior_model_M->Timing.clockTick0+1)) {
  124. rtsiSetSolverStopTime(&vehicle_behavior_model_M->solverInfo,
  125. ((vehicle_behavior_model_M->Timing.clockTickH0 + 1) *
  126. vehicle_behavior_model_M->Timing.stepSize0 * 4294967296.0));
  127. } else {
  128. rtsiSetSolverStopTime(&vehicle_behavior_model_M->solverInfo,
  129. ((vehicle_behavior_model_M->Timing.clockTick0 + 1) *
  130. vehicle_behavior_model_M->Timing.stepSize0 +
  131. vehicle_behavior_model_M->Timing.clockTickH0 *
  132. vehicle_behavior_model_M->Timing.stepSize0 * 4294967296.0));
  133. }
  134. } /* end MajorTimeStep */
  135.  
  136. /* Update absolute time of base rate at minor time step */
  137. if (rtmIsMinorTimeStep(vehicle_behavior_model_M)) {
  138. vehicle_behavior_model_M->Timing.t[0] = rtsiGetT
  139. (&vehicle_behavior_model_M->solverInfo);
  140. }
  141.  
  142. /* Integrator: '<Root>/Integrator' */
  143. vehicle_behavior_model_B.Integrator =
  144. vehicle_behavior_model_X.Integrator_CSTATE;
  145. if (rtmIsMajorTimeStep(vehicle_behavior_model_M)) {
  146. /* Switch: '<Root>/Switch' incorporates:
  147.   * Constant: '<Root>/Braking Force'
  148.   */
  149. if (vehicle_behavior_model_P.BrakingForce_Value != 0.0) {
  150. /* Switch: '<Root>/Switch' incorporates:
  151.   * Constant: '<Root>/Engine Force'
  152.   */
  153. vehicle_behavior_model_B.Switch =
  154. vehicle_behavior_model_P.EngineForce_Value;
  155. } else {
  156. /* Switch: '<Root>/Switch' */
  157. vehicle_behavior_model_B.Switch = 0.0;
  158. }
  159.  
  160. /* End of Switch: '<Root>/Switch' */
  161. }
  162.  
  163. /* Gain: '<Root>/Acceleration' incorporates:
  164.   * Gain: '<Root>/Damping Force'
  165.   * Sum: '<Root>/Sum'
  166.   */
  167. vehicle_behavior_model_B.Acceleration = (vehicle_behavior_model_B.Switch -
  168. vehicle_behavior_model_P.DampingForce_Gain *
  169. vehicle_behavior_model_B.Integrator) *
  170. vehicle_behavior_model_P.Acceleration_Gain;
  171. if (rtmIsMajorTimeStep(vehicle_behavior_model_M)) {
  172. /* Matfile logging */
  173. rt_UpdateTXYLogVars(vehicle_behavior_model_M->rtwLogInfo,
  174. (vehicle_behavior_model_M->Timing.t));
  175. } /* end MajorTimeStep */
  176.  
  177. if (rtmIsMajorTimeStep(vehicle_behavior_model_M)) {
  178. /* signal main to stop simulation */
  179. { /* Sample time: [0.0s, 0.0s] */
  180. if ((rtmGetTFinal(vehicle_behavior_model_M)!=-1) &&
  181. !((rtmGetTFinal(vehicle_behavior_model_M)-
  182. (((vehicle_behavior_model_M->Timing.clockTick1+
  183. vehicle_behavior_model_M->Timing.clockTickH1* 4294967296.0)) *
  184. 0.2)) > (((vehicle_behavior_model_M->Timing.clockTick1+
  185. vehicle_behavior_model_M->Timing.clockTickH1*
  186. 4294967296.0)) * 0.2) * (DBL_EPSILON))) {
  187. rtmSetErrorStatus(vehicle_behavior_model_M, "Simulation finished");
  188. }
  189. }
  190.  
  191. rt_ertODEUpdateContinuousStates(&vehicle_behavior_model_M->solverInfo);
  192.  
  193. /* Update absolute time for base rate */
  194. /* The "clockTick0" counts the number of times the code of this task has
  195.   * been executed. The absolute time is the multiplication of "clockTick0"
  196.   * and "Timing.stepSize0". Size of "clockTick0" ensures timer will not
  197.   * overflow during the application lifespan selected.
  198.   * Timer of this task consists of two 32 bit unsigned integers.
  199.   * The two integers represent the low bits Timing.clockTick0 and the high bits
  200.   * Timing.clockTickH0. When the low bit overflows to 0, the high bits increment.
  201.   */
  202. if (!(++vehicle_behavior_model_M->Timing.clockTick0)) {
  203. ++vehicle_behavior_model_M->Timing.clockTickH0;
  204. }
  205.  
  206. vehicle_behavior_model_M->Timing.t[0] = rtsiGetSolverStopTime
  207. (&vehicle_behavior_model_M->solverInfo);
  208.  
  209. {
  210. /* Update absolute timer for sample time: [0.2s, 0.0s] */
  211. /* The "clockTick1" counts the number of times the code of this task has
  212.   * been executed. The resolution of this integer timer is 0.2, which is the step size
  213.   * of the task. Size of "clockTick1" ensures timer will not overflow during the
  214.   * application lifespan selected.
  215.   * Timer of this task consists of two 32 bit unsigned integers.
  216.   * The two integers represent the low bits Timing.clockTick1 and the high bits
  217.   * Timing.clockTickH1. When the low bit overflows to 0, the high bits increment.
  218.   */
  219. vehicle_behavior_model_M->Timing.clockTick1++;
  220. if (!vehicle_behavior_model_M->Timing.clockTick1) {
  221. vehicle_behavior_model_M->Timing.clockTickH1++;
  222. }
  223. }
  224. } /* end MajorTimeStep */
  225. }
  226.  
  227. /* Derivatives for root system: '<Root>' */
  228. void vehicle_behavior_model_derivatives(void)
  229. {
  230. XDot_vehicle_behavior_model_T *_rtXdot;
  231. _rtXdot = ((XDot_vehicle_behavior_model_T *) vehicle_behavior_model_M->derivs);
  232.  
  233. /* Derivatives for Integrator: '<Root>/Integrator' */
  234. _rtXdot->Integrator_CSTATE = vehicle_behavior_model_B.Acceleration;
  235. }
  236.  
  237. /* Model initialize function */
  238. void vehicle_behavior_model_initialize(void)
  239. {
  240. /* Registration code */
  241.  
  242. /* initialize real-time model */
  243. (void) memset((void *)vehicle_behavior_model_M, 0,
  244. sizeof(RT_MODEL_vehicle_behavior_mod_T));
  245.  
  246. {
  247. /* Setup solver object */
  248. rtsiSetSimTimeStepPtr(&vehicle_behavior_model_M->solverInfo,
  249. &vehicle_behavior_model_M->Timing.simTimeStep);
  250. rtsiSetTPtr(&vehicle_behavior_model_M->solverInfo, &rtmGetTPtr
  251. (vehicle_behavior_model_M));
  252. rtsiSetStepSizePtr(&vehicle_behavior_model_M->solverInfo,
  253. &vehicle_behavior_model_M->Timing.stepSize0);
  254. rtsiSetdXPtr(&vehicle_behavior_model_M->solverInfo,
  255. &vehicle_behavior_model_M->derivs);
  256. rtsiSetContStatesPtr(&vehicle_behavior_model_M->solverInfo, (real_T **)
  257. &vehicle_behavior_model_M->contStates);
  258. rtsiSetNumContStatesPtr(&vehicle_behavior_model_M->solverInfo,
  259. &vehicle_behavior_model_M->Sizes.numContStates);
  260. rtsiSetNumPeriodicContStatesPtr(&vehicle_behavior_model_M->solverInfo,
  261. &vehicle_behavior_model_M->Sizes.numPeriodicContStates);
  262. rtsiSetPeriodicContStateIndicesPtr(&vehicle_behavior_model_M->solverInfo,
  263. &vehicle_behavior_model_M->periodicContStateIndices);
  264. rtsiSetPeriodicContStateRangesPtr(&vehicle_behavior_model_M->solverInfo,
  265. &vehicle_behavior_model_M->periodicContStateRanges);
  266. rtsiSetContStateDisabledPtr(&vehicle_behavior_model_M->solverInfo,
  267. (boolean_T**) &vehicle_behavior_model_M->contStateDisabled);
  268. rtsiSetErrorStatusPtr(&vehicle_behavior_model_M->solverInfo,
  269. (&rtmGetErrorStatus(vehicle_behavior_model_M)));
  270. rtsiSetRTModelPtr(&vehicle_behavior_model_M->solverInfo,
  271. vehicle_behavior_model_M);
  272. }
  273.  
  274. rtsiSetSimTimeStep(&vehicle_behavior_model_M->solverInfo, MAJOR_TIME_STEP);
  275. rtsiSetIsMinorTimeStepWithModeChange(&vehicle_behavior_model_M->solverInfo,
  276. false);
  277. rtsiSetIsContModeFrozen(&vehicle_behavior_model_M->solverInfo, false);
  278. vehicle_behavior_model_M->intgData.y = vehicle_behavior_model_M->odeY;
  279. vehicle_behavior_model_M->intgData.f[0] = vehicle_behavior_model_M->odeF[0];
  280. vehicle_behavior_model_M->intgData.f[1] = vehicle_behavior_model_M->odeF[1];
  281. vehicle_behavior_model_M->intgData.f[2] = vehicle_behavior_model_M->odeF[2];
  282. vehicle_behavior_model_M->contStates = ((X_vehicle_behavior_model_T *)
  283. &vehicle_behavior_model_X);
  284. vehicle_behavior_model_M->contStateDisabled = ((XDis_vehicle_behavior_model_T *)
  285. &vehicle_behavior_model_XDis);
  286. vehicle_behavior_model_M->Timing.tStart = (0.0);
  287. rtsiSetSolverData(&vehicle_behavior_model_M->solverInfo, (void *)
  288. &vehicle_behavior_model_M->intgData);
  289. rtsiSetSolverName(&vehicle_behavior_model_M->solverInfo,"ode3");
  290. rtmSetTPtr(vehicle_behavior_model_M, &vehicle_behavior_model_M->Timing.tArray
  291. [0]);
  292. rtmSetTFinal(vehicle_behavior_model_M, 10.0);
  293. vehicle_behavior_model_M->Timing.stepSize0 = 0.2;
  294.  
  295. /* Setup for data logging */
  296. {
  297. static RTWLogInfo rt_DataLoggingInfo;
  298. rt_DataLoggingInfo.loggingInterval = (NULL);
  299. vehicle_behavior_model_M->rtwLogInfo = &rt_DataLoggingInfo;
  300. }
  301.  
  302. /* Setup for data logging */
  303. {
  304. rtliSetLogXSignalInfo(vehicle_behavior_model_M->rtwLogInfo, (NULL));
  305. rtliSetLogXSignalPtrs(vehicle_behavior_model_M->rtwLogInfo, (NULL));
  306. rtliSetLogT(vehicle_behavior_model_M->rtwLogInfo, "tout");
  307. rtliSetLogX(vehicle_behavior_model_M->rtwLogInfo, "");
  308. rtliSetLogXFinal(vehicle_behavior_model_M->rtwLogInfo, "");
  309. rtliSetLogVarNameModifier(vehicle_behavior_model_M->rtwLogInfo, "rt_");
  310. rtliSetLogFormat(vehicle_behavior_model_M->rtwLogInfo, 4);
  311. rtliSetLogMaxRows(vehicle_behavior_model_M->rtwLogInfo, 0);
  312. rtliSetLogDecimation(vehicle_behavior_model_M->rtwLogInfo, 1);
  313. rtliSetLogY(vehicle_behavior_model_M->rtwLogInfo, "");
  314. rtliSetLogYSignalInfo(vehicle_behavior_model_M->rtwLogInfo, (NULL));
  315. rtliSetLogYSignalPtrs(vehicle_behavior_model_M->rtwLogInfo, (NULL));
  316. }
  317.  
  318. /* block I/O */
  319. (void) memset(((void *) &vehicle_behavior_model_B), 0,
  320. sizeof(B_vehicle_behavior_model_T));
  321.  
  322. /* states (continuous) */
  323. {
  324. (void) memset((void *)&vehicle_behavior_model_X, 0,
  325. sizeof(X_vehicle_behavior_model_T));
  326. }
  327.  
  328. /* disabled states */
  329. {
  330. (void) memset((void *)&vehicle_behavior_model_XDis, 0,
  331. sizeof(XDis_vehicle_behavior_model_T));
  332. }
  333.  
  334. /* Matfile logging */
  335. rt_StartDataLoggingWithStartTime(vehicle_behavior_model_M->rtwLogInfo, 0.0,
  336. rtmGetTFinal(vehicle_behavior_model_M),
  337. vehicle_behavior_model_M->Timing.stepSize0, (&rtmGetErrorStatus
  338. (vehicle_behavior_model_M)));
  339.  
  340. /* InitializeConditions for Integrator: '<Root>/Integrator' */
  341. vehicle_behavior_model_X.Integrator_CSTATE =
  342. vehicle_behavior_model_P.Integrator_IC;
  343. }
  344.  
  345. /* Model terminate function */
  346. void vehicle_behavior_model_terminate(void)
  347. {
  348. /* (no terminate code required) */
  349. }
  350.  
Success #stdin #stdout 0.02s 25684KB
stdin
Standard input is empty
stdout
/*
 * vehicle_behavior_model.c
 *
 * Trial License - for use to evaluate programs for possible purchase as
 * an end-user only.
 *
 * Code generation for model "vehicle_behavior_model".
 *
 * Model version              : 1.0
 * Simulink Coder version : 24.1 (R2024a) 19-Nov-2023
 * C source code generated on : Mon Jun  3 16:39:46 2024
 *
 * Target selection: grt.tlc
 * Note: GRT includes extra infrastructure and instrumentation for prototyping
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "vehicle_behavior_model.h"
#include "vehicle_behavior_model_private.h"

/* Block signals (default storage) */
B_vehicle_behavior_model_T vehicle_behavior_model_B;

/* Continuous states */
X_vehicle_behavior_model_T vehicle_behavior_model_X;

/* Disabled State Vector */
XDis_vehicle_behavior_model_T vehicle_behavior_model_XDis;

/* Real-time model */
static RT_MODEL_vehicle_behavior_mod_T vehicle_behavior_model_M_;
RT_MODEL_vehicle_behavior_mod_T *const vehicle_behavior_model_M =
  &vehicle_behavior_model_M_;

/*
 * This function updates continuous states using the ODE3 fixed-step
 * solver algorithm
 */
static void rt_ertODEUpdateContinuousStates(RTWSolverInfo *si )
{
  /* Solver Matrices */
  static const real_T rt_ODE3_A[3] = {
    1.0/2.0, 3.0/4.0, 1.0
  };

  static const real_T rt_ODE3_B[3][3] = {
    { 1.0/2.0, 0.0, 0.0 },

    { 0.0, 3.0/4.0, 0.0 },

    { 2.0/9.0, 1.0/3.0, 4.0/9.0 }
  };

  time_T t = rtsiGetT(si);
  time_T tnew = rtsiGetSolverStopTime(si);
  time_T h = rtsiGetStepSize(si);
  real_T *x = rtsiGetContStates(si);
  ODE3_IntgData *id = (ODE3_IntgData *)rtsiGetSolverData(si);
  real_T *y = id->y;
  real_T *f0 = id->f[0];
  real_T *f1 = id->f[1];
  real_T *f2 = id->f[2];
  real_T hB[3];
  int_T i;
  int_T nXc = 1;
  rtsiSetSimTimeStep(si,MINOR_TIME_STEP);

  /* Save the state values at time t in y, we'll use x as ynew. */
  (void) memcpy(y, x,
                (uint_T)nXc*sizeof(real_T));

  /* Assumes that rtsiSetT and ModelOutputs are up-to-date */
  /* f0 = f(t,y) */
  rtsiSetdX(si, f0);
  vehicle_behavior_model_derivatives();

  /* f(:,2) = feval(odefile, t + hA(1), y + f*hB(:,1), args(:)(*)); */
  hB[0] = h * rt_ODE3_B[0][0];
  for (i = 0; i < nXc; i++) {
    x[i] = y[i] + (f0[i]*hB[0]);
  }

  rtsiSetT(si, t + h*rt_ODE3_A[0]);
  rtsiSetdX(si, f1);
  vehicle_behavior_model_step();
  vehicle_behavior_model_derivatives();

  /* f(:,3) = feval(odefile, t + hA(2), y + f*hB(:,2), args(:)(*)); */
  for (i = 0; i <= 1; i++) {
    hB[i] = h * rt_ODE3_B[1][i];
  }

  for (i = 0; i < nXc; i++) {
    x[i] = y[i] + (f0[i]*hB[0] + f1[i]*hB[1]);
  }

  rtsiSetT(si, t + h*rt_ODE3_A[1]);
  rtsiSetdX(si, f2);
  vehicle_behavior_model_step();
  vehicle_behavior_model_derivatives();

  /* tnew = t + hA(3);
     ynew = y + f*hB(:,3); */
  for (i = 0; i <= 2; i++) {
    hB[i] = h * rt_ODE3_B[2][i];
  }

  for (i = 0; i < nXc; i++) {
    x[i] = y[i] + (f0[i]*hB[0] + f1[i]*hB[1] + f2[i]*hB[2]);
  }

  rtsiSetT(si, tnew);
  rtsiSetSimTimeStep(si,MAJOR_TIME_STEP);
}

/* Model step function */
void vehicle_behavior_model_step(void)
{
  if (rtmIsMajorTimeStep(vehicle_behavior_model_M)) {
    /* set solver stop time */
    if (!(vehicle_behavior_model_M->Timing.clockTick0+1)) {
      rtsiSetSolverStopTime(&vehicle_behavior_model_M->solverInfo,
                            ((vehicle_behavior_model_M->Timing.clockTickH0 + 1) *
        vehicle_behavior_model_M->Timing.stepSize0 * 4294967296.0));
    } else {
      rtsiSetSolverStopTime(&vehicle_behavior_model_M->solverInfo,
                            ((vehicle_behavior_model_M->Timing.clockTick0 + 1) *
        vehicle_behavior_model_M->Timing.stepSize0 +
        vehicle_behavior_model_M->Timing.clockTickH0 *
        vehicle_behavior_model_M->Timing.stepSize0 * 4294967296.0));
    }
  }                                    /* end MajorTimeStep */

  /* Update absolute time of base rate at minor time step */
  if (rtmIsMinorTimeStep(vehicle_behavior_model_M)) {
    vehicle_behavior_model_M->Timing.t[0] = rtsiGetT
      (&vehicle_behavior_model_M->solverInfo);
  }

  /* Integrator: '<Root>/Integrator' */
  vehicle_behavior_model_B.Integrator =
    vehicle_behavior_model_X.Integrator_CSTATE;
  if (rtmIsMajorTimeStep(vehicle_behavior_model_M)) {
    /* Switch: '<Root>/Switch' incorporates:
     *  Constant: '<Root>/Braking Force'
     */
    if (vehicle_behavior_model_P.BrakingForce_Value != 0.0) {
      /* Switch: '<Root>/Switch' incorporates:
       *  Constant: '<Root>/Engine Force'
       */
      vehicle_behavior_model_B.Switch =
        vehicle_behavior_model_P.EngineForce_Value;
    } else {
      /* Switch: '<Root>/Switch' */
      vehicle_behavior_model_B.Switch = 0.0;
    }

    /* End of Switch: '<Root>/Switch' */
  }

  /* Gain: '<Root>/Acceleration' incorporates:
   *  Gain: '<Root>/Damping Force'
   *  Sum: '<Root>/Sum'
   */
  vehicle_behavior_model_B.Acceleration = (vehicle_behavior_model_B.Switch -
    vehicle_behavior_model_P.DampingForce_Gain *
    vehicle_behavior_model_B.Integrator) *
    vehicle_behavior_model_P.Acceleration_Gain;
  if (rtmIsMajorTimeStep(vehicle_behavior_model_M)) {
    /* Matfile logging */
    rt_UpdateTXYLogVars(vehicle_behavior_model_M->rtwLogInfo,
                        (vehicle_behavior_model_M->Timing.t));
  }                                    /* end MajorTimeStep */

  if (rtmIsMajorTimeStep(vehicle_behavior_model_M)) {
    /* signal main to stop simulation */
    {                                  /* Sample time: [0.0s, 0.0s] */
      if ((rtmGetTFinal(vehicle_behavior_model_M)!=-1) &&
          !((rtmGetTFinal(vehicle_behavior_model_M)-
             (((vehicle_behavior_model_M->Timing.clockTick1+
                vehicle_behavior_model_M->Timing.clockTickH1* 4294967296.0)) *
              0.2)) > (((vehicle_behavior_model_M->Timing.clockTick1+
                         vehicle_behavior_model_M->Timing.clockTickH1*
                         4294967296.0)) * 0.2) * (DBL_EPSILON))) {
        rtmSetErrorStatus(vehicle_behavior_model_M, "Simulation finished");
      }
    }

    rt_ertODEUpdateContinuousStates(&vehicle_behavior_model_M->solverInfo);

    /* Update absolute time for base rate */
    /* The "clockTick0" counts the number of times the code of this task has
     * been executed. The absolute time is the multiplication of "clockTick0"
     * and "Timing.stepSize0". Size of "clockTick0" ensures timer will not
     * overflow during the application lifespan selected.
     * Timer of this task consists of two 32 bit unsigned integers.
     * The two integers represent the low bits Timing.clockTick0 and the high bits
     * Timing.clockTickH0. When the low bit overflows to 0, the high bits increment.
     */
    if (!(++vehicle_behavior_model_M->Timing.clockTick0)) {
      ++vehicle_behavior_model_M->Timing.clockTickH0;
    }

    vehicle_behavior_model_M->Timing.t[0] = rtsiGetSolverStopTime
      (&vehicle_behavior_model_M->solverInfo);

    {
      /* Update absolute timer for sample time: [0.2s, 0.0s] */
      /* The "clockTick1" counts the number of times the code of this task has
       * been executed. The resolution of this integer timer is 0.2, which is the step size
       * of the task. Size of "clockTick1" ensures timer will not overflow during the
       * application lifespan selected.
       * Timer of this task consists of two 32 bit unsigned integers.
       * The two integers represent the low bits Timing.clockTick1 and the high bits
       * Timing.clockTickH1. When the low bit overflows to 0, the high bits increment.
       */
      vehicle_behavior_model_M->Timing.clockTick1++;
      if (!vehicle_behavior_model_M->Timing.clockTick1) {
        vehicle_behavior_model_M->Timing.clockTickH1++;
      }
    }
  }                                    /* end MajorTimeStep */
}

/* Derivatives for root system: '<Root>' */
void vehicle_behavior_model_derivatives(void)
{
  XDot_vehicle_behavior_model_T *_rtXdot;
  _rtXdot = ((XDot_vehicle_behavior_model_T *) vehicle_behavior_model_M->derivs);

  /* Derivatives for Integrator: '<Root>/Integrator' */
  _rtXdot->Integrator_CSTATE = vehicle_behavior_model_B.Acceleration;
}

/* Model initialize function */
void vehicle_behavior_model_initialize(void)
{
  /* Registration code */

  /* initialize real-time model */
  (void) memset((void *)vehicle_behavior_model_M, 0,
                sizeof(RT_MODEL_vehicle_behavior_mod_T));

  {
    /* Setup solver object */
    rtsiSetSimTimeStepPtr(&vehicle_behavior_model_M->solverInfo,
                          &vehicle_behavior_model_M->Timing.simTimeStep);
    rtsiSetTPtr(&vehicle_behavior_model_M->solverInfo, &rtmGetTPtr
                (vehicle_behavior_model_M));
    rtsiSetStepSizePtr(&vehicle_behavior_model_M->solverInfo,
                       &vehicle_behavior_model_M->Timing.stepSize0);
    rtsiSetdXPtr(&vehicle_behavior_model_M->solverInfo,
                 &vehicle_behavior_model_M->derivs);
    rtsiSetContStatesPtr(&vehicle_behavior_model_M->solverInfo, (real_T **)
                         &vehicle_behavior_model_M->contStates);
    rtsiSetNumContStatesPtr(&vehicle_behavior_model_M->solverInfo,
      &vehicle_behavior_model_M->Sizes.numContStates);
    rtsiSetNumPeriodicContStatesPtr(&vehicle_behavior_model_M->solverInfo,
      &vehicle_behavior_model_M->Sizes.numPeriodicContStates);
    rtsiSetPeriodicContStateIndicesPtr(&vehicle_behavior_model_M->solverInfo,
      &vehicle_behavior_model_M->periodicContStateIndices);
    rtsiSetPeriodicContStateRangesPtr(&vehicle_behavior_model_M->solverInfo,
      &vehicle_behavior_model_M->periodicContStateRanges);
    rtsiSetContStateDisabledPtr(&vehicle_behavior_model_M->solverInfo,
      (boolean_T**) &vehicle_behavior_model_M->contStateDisabled);
    rtsiSetErrorStatusPtr(&vehicle_behavior_model_M->solverInfo,
                          (&rtmGetErrorStatus(vehicle_behavior_model_M)));
    rtsiSetRTModelPtr(&vehicle_behavior_model_M->solverInfo,
                      vehicle_behavior_model_M);
  }

  rtsiSetSimTimeStep(&vehicle_behavior_model_M->solverInfo, MAJOR_TIME_STEP);
  rtsiSetIsMinorTimeStepWithModeChange(&vehicle_behavior_model_M->solverInfo,
    false);
  rtsiSetIsContModeFrozen(&vehicle_behavior_model_M->solverInfo, false);
  vehicle_behavior_model_M->intgData.y = vehicle_behavior_model_M->odeY;
  vehicle_behavior_model_M->intgData.f[0] = vehicle_behavior_model_M->odeF[0];
  vehicle_behavior_model_M->intgData.f[1] = vehicle_behavior_model_M->odeF[1];
  vehicle_behavior_model_M->intgData.f[2] = vehicle_behavior_model_M->odeF[2];
  vehicle_behavior_model_M->contStates = ((X_vehicle_behavior_model_T *)
    &vehicle_behavior_model_X);
  vehicle_behavior_model_M->contStateDisabled = ((XDis_vehicle_behavior_model_T *)
    &vehicle_behavior_model_XDis);
  vehicle_behavior_model_M->Timing.tStart = (0.0);
  rtsiSetSolverData(&vehicle_behavior_model_M->solverInfo, (void *)
                    &vehicle_behavior_model_M->intgData);
  rtsiSetSolverName(&vehicle_behavior_model_M->solverInfo,"ode3");
  rtmSetTPtr(vehicle_behavior_model_M, &vehicle_behavior_model_M->Timing.tArray
             [0]);
  rtmSetTFinal(vehicle_behavior_model_M, 10.0);
  vehicle_behavior_model_M->Timing.stepSize0 = 0.2;

  /* Setup for data logging */
  {
    static RTWLogInfo rt_DataLoggingInfo;
    rt_DataLoggingInfo.loggingInterval = (NULL);
    vehicle_behavior_model_M->rtwLogInfo = &rt_DataLoggingInfo;
  }

  /* Setup for data logging */
  {
    rtliSetLogXSignalInfo(vehicle_behavior_model_M->rtwLogInfo, (NULL));
    rtliSetLogXSignalPtrs(vehicle_behavior_model_M->rtwLogInfo, (NULL));
    rtliSetLogT(vehicle_behavior_model_M->rtwLogInfo, "tout");
    rtliSetLogX(vehicle_behavior_model_M->rtwLogInfo, "");
    rtliSetLogXFinal(vehicle_behavior_model_M->rtwLogInfo, "");
    rtliSetLogVarNameModifier(vehicle_behavior_model_M->rtwLogInfo, "rt_");
    rtliSetLogFormat(vehicle_behavior_model_M->rtwLogInfo, 4);
    rtliSetLogMaxRows(vehicle_behavior_model_M->rtwLogInfo, 0);
    rtliSetLogDecimation(vehicle_behavior_model_M->rtwLogInfo, 1);
    rtliSetLogY(vehicle_behavior_model_M->rtwLogInfo, "");
    rtliSetLogYSignalInfo(vehicle_behavior_model_M->rtwLogInfo, (NULL));
    rtliSetLogYSignalPtrs(vehicle_behavior_model_M->rtwLogInfo, (NULL));
  }

  /* block I/O */
  (void) memset(((void *) &vehicle_behavior_model_B), 0,
                sizeof(B_vehicle_behavior_model_T));

  /* states (continuous) */
  {
    (void) memset((void *)&vehicle_behavior_model_X, 0,
                  sizeof(X_vehicle_behavior_model_T));
  }

  /* disabled states */
  {
    (void) memset((void *)&vehicle_behavior_model_XDis, 0,
                  sizeof(XDis_vehicle_behavior_model_T));
  }

  /* Matfile logging */
  rt_StartDataLoggingWithStartTime(vehicle_behavior_model_M->rtwLogInfo, 0.0,
    rtmGetTFinal(vehicle_behavior_model_M),
    vehicle_behavior_model_M->Timing.stepSize0, (&rtmGetErrorStatus
    (vehicle_behavior_model_M)));

  /* InitializeConditions for Integrator: '<Root>/Integrator' */
  vehicle_behavior_model_X.Integrator_CSTATE =
    vehicle_behavior_model_P.Integrator_IC;
}

/* Model terminate function */
void vehicle_behavior_model_terminate(void)
{
  /* (no terminate code required) */
}