示例#1
0
/* Model step function */
void Hammerstein_step(void)
{
  /* DiscreteStateSpace: '<S1>/LinearModel' */
  {
    Hammerstein_B.LinearModel = Hammerstein_P.LinearModel_C*
      Hammerstein_DWork.LinearModel_DSTATE;
  }

  /* Level2 S-Function Block: '<S1>/Pwlinear1' (sfunpwlinear) */
  {
    SimStruct *rts = Hammerstein_M->childSfunctions[0];
    ssSetOutputPortSignal(rts, 0, &Hammerstein_Y.Out1);
    sfcnOutputs(rts, 0);
  }

  /* Level2 S-Function Block: '<S1>/Pwlinear' (sfunpwlinear) */
  {
    SimStruct *rts = Hammerstein_M->childSfunctions[1];
    sfcnOutputs(rts, 0);
  }

  /* Update for DiscreteStateSpace: '<S1>/LinearModel' */
  {
    Hammerstein_DWork.LinearModel_DSTATE = Hammerstein_B.Pwlinear +
      Hammerstein_P.LinearModel_A*Hammerstein_DWork.LinearModel_DSTATE;
  }

  /* Matfile logging */
  rt_UpdateTXYLogVars(Hammerstein_M->rtwLogInfo, (Hammerstein_M->Timing.t));

  /* signal main to stop simulation */
  {                                    /* Sample time: [0.06s, 0.0s] */
    if ((rtmGetTFinal(Hammerstein_M)!=-1) &&
        !((rtmGetTFinal(Hammerstein_M)-Hammerstein_M->Timing.t[0]) >
          Hammerstein_M->Timing.t[0] * (DBL_EPSILON))) {
      rtmSetErrorStatus(Hammerstein_M, "Simulation finished");
    }

    if (rtmGetStopRequested(Hammerstein_M)) {
      rtmSetErrorStatus(Hammerstein_M, "Simulation finished");
    }
  }

  /* 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 (!(++Hammerstein_M->Timing.clockTick0)) {
    ++Hammerstein_M->Timing.clockTickH0;
  }

  Hammerstein_M->Timing.t[0] = Hammerstein_M->Timing.clockTick0 *
    Hammerstein_M->Timing.stepSize0 + Hammerstein_M->Timing.clockTickH0 *
    Hammerstein_M->Timing.stepSize0 * 4294967296.0;
}
/* Model step function */
void HSimpleConstDead_export_step(void)
{
  /* Outport: '<Root>/Out1' incorporates:
   *  Constant: '<Root>/Constant2'
   *  Inport: '<Root>/In1'
   *  Product: '<Root>/Product'
   */
  HSimpleConstDead_export_Y.Out1 = 433.22 * HSimpleConstDead_export_U.In1;

  /* Matfile logging */
  rt_UpdateTXYLogVars(HSimpleConstDead_export_M->rtwLogInfo,
                      (HSimpleConstDead_export_M->Timing.t));

  /* 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 (!(++HSimpleConstDead_export_M->Timing.clockTick0)) {
    ++HSimpleConstDead_export_M->Timing.clockTickH0;
  }

  HSimpleConstDead_export_M->Timing.t[0] =
    HSimpleConstDead_export_M->Timing.clockTick0 *
    HSimpleConstDead_export_M->Timing.stepSize0 +
    HSimpleConstDead_export_M->Timing.clockTickH0 *
    HSimpleConstDead_export_M->Timing.stepSize0 * 4294967296.0;
}
示例#3
0
/* Model step function */
void Const1_step(void)
{
  /* Outport: '<Root>/Out1' incorporates:
   *  Inport: '<Root>/In1'
   *  Sum: '<Root>/Sum'
   */
  Const1_Y.Out1 = Const1_U.In1 + 439.30400000000003;

  /* Matfile logging */
  rt_UpdateTXYLogVars(Const1_M->rtwLogInfo, (Const1_M->Timing.t));

  /* 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 (!(++Const1_M->Timing.clockTick0)) {
    ++Const1_M->Timing.clockTickH0;
  }

  Const1_M->Timing.t[0] = Const1_M->Timing.clockTick0 *
    Const1_M->Timing.stepSize0 + Const1_M->Timing.clockTickH0 *
    Const1_M->Timing.stepSize0 * 4294967296.0;
}
示例#4
0
/* Model step function */
void HConstfolding_export_step(void)
{
    /* Product: '<Root>/Product' */
    HConstfolding_export_DWork.UnitDelay_DSTATE *=
        HConstfolding_export_DWork.UnitDelay1_DSTATE;

    /* Gain: '<Root>/Gain2' */
    HConstfolding_export_DWork.UnitDelay_DSTATE *=
        HConstfolding_export_P.Gain2_Gain;

    /* Gain: '<Root>/Gain3' */
    HConstfolding_export_DWork.UnitDelay_DSTATE *=
        HConstfolding_export_P.Gain3_Gain;

    /* Outport: '<Root>/Out1' */
    HConstfolding_export_Y.Out1 = HConstfolding_export_DWork.UnitDelay_DSTATE;

    /* Update for UnitDelay: '<Root>/Unit Delay' incorporates:
     *  Constant: '<Root>/Constant51'
     */
    HConstfolding_export_DWork.UnitDelay_DSTATE =
        HConstfolding_export_P.Constant51_Value;

    /* Update for UnitDelay: '<Root>/Unit Delay1' incorporates:
     *  Constant: '<Root>/Constant50'
     */
    HConstfolding_export_DWork.UnitDelay1_DSTATE =
        HConstfolding_export_P.Constant50_Value;

    /* Matfile logging */
    rt_UpdateTXYLogVars(HConstfolding_export_M->rtwLogInfo,
                        (HConstfolding_export_M->Timing.t));

    /* 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 (!(++HConstfolding_export_M->Timing.clockTick0)) {
        ++HConstfolding_export_M->Timing.clockTickH0;
    }

    HConstfolding_export_M->Timing.t[0] =
        HConstfolding_export_M->Timing.clockTick0 *
        HConstfolding_export_M->Timing.stepSize0 +
        HConstfolding_export_M->Timing.clockTickH0 *
        HConstfolding_export_M->Timing.stepSize0 * 4294967296.0;
}
/* Model step function */
void Flatten2_export_export_step(void)
{
  /* local block i/o variables */
  real_T rtb_Gain2;

  /* Product: '<Root>/Product2' incorporates:
   *  Constant: '<Root>/Constant'
   *  Inport: '<Root>/In1'
   */
  rtb_Gain2 = Flatten2_export_export_U.In1 *
    Flatten2_export_export_P.Constant_Value;

  /* Product: '<Root>/Product3' incorporates:
   *  Constant: '<Root>/Constant2'
   */
  rtb_Gain2 *= Flatten2_export_export_P.Constant2_Value;

  /* Sum: '<Root>/Sum' incorporates:
   *  Constant: '<Root>/Constant'
   */
  rtb_Gain2 += Flatten2_export_export_P.Constant_Value;

  /* Gain: '<Root>/Gain2' */
  rtb_Gain2 *= Flatten2_export_export_P.Gain2_Gain;

  /* Outport: '<Root>/Out1' */
  Flatten2_export_export_Y.Out1 = rtb_Gain2;

  /* Matfile logging */
  rt_UpdateTXYLogVars(Flatten2_export_export_M->rtwLogInfo,
                      (Flatten2_export_export_M->Timing.t));

  /* 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 (!(++Flatten2_export_export_M->Timing.clockTick0)) {
    ++Flatten2_export_export_M->Timing.clockTickH0;
  }

  Flatten2_export_export_M->Timing.t[0] =
    Flatten2_export_export_M->Timing.clockTick0 *
    Flatten2_export_export_M->Timing.stepSize0 +
    Flatten2_export_export_M->Timing.clockTickH0 *
    Flatten2_export_export_M->Timing.stepSize0 * 4294967296.0;
}
示例#6
0
/* Model step function */
void Koordinatentransfer3_step(void)
{
  real_T rtb_Gain;
  real_T rtb_Gain1;

  /* Outport: '<Root>/a' incorporates:
   *  Inport: '<Root>/alpha'
   */
  Koordinatentransfer3_Y.a = Koordinatentransfer3_U.alpha;

  /* Gain: '<S1>/Gain' incorporates:
   *  Inport: '<Root>/alpha'
   */
  rtb_Gain = Koordinatentransfer3_P.Gain_Gain * Koordinatentransfer3_U.alpha;

  /* Gain: '<S1>/Gain1' incorporates:
   *  Inport: '<Root>/beta'
   */
  rtb_Gain1 = Koordinatentransfer3_P.Gain1_Gain * Koordinatentransfer3_U.beta;

  /* Outport: '<Root>/b' incorporates:
   *  Sum: '<S1>/Sum1'
   */
  Koordinatentransfer3_Y.b = rtb_Gain1 - rtb_Gain;

  /* Outport: '<Root>/c' incorporates:
   *  Sum: '<S1>/Sum'
   */
  Koordinatentransfer3_Y.c = (0.0 - rtb_Gain) - rtb_Gain1;

  /* Matfile logging */
  rt_UpdateTXYLogVars(Koordinatentransfer3_M->rtwLogInfo,
                      (&Koordinatentransfer3_M->Timing.taskTime0));

  /* signal main to stop simulation */
  {                                    /* Sample time: [0.02s, 0.0s] */
    if ((rtmGetTFinal(Koordinatentransfer3_M)!=-1) &&
        !((rtmGetTFinal(Koordinatentransfer3_M)-
           Koordinatentransfer3_M->Timing.taskTime0) >
          Koordinatentransfer3_M->Timing.taskTime0 * (DBL_EPSILON))) {
      rtmSetErrorStatus(Koordinatentransfer3_M, "Simulation finished");
    }
  }

  /* 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 (!(++Koordinatentransfer3_M->Timing.clockTick0)) {
    ++Koordinatentransfer3_M->Timing.clockTickH0;
  }

  Koordinatentransfer3_M->Timing.taskTime0 =
    Koordinatentransfer3_M->Timing.clockTick0 *
    Koordinatentransfer3_M->Timing.stepSize0 +
    Koordinatentransfer3_M->Timing.clockTickH0 *
    Koordinatentransfer3_M->Timing.stepSize0 * 4294967296.0;
}
/* Model step function */
void trajectoryModel_step(void)
{
  /* local block i/o variables */
  real_T rtb_Sqrt;
  real_T rtb_Divide1;
  int8_T rtAction;
  real_T rtb_Divide;
  real_T rtb_Add1;
  if (rtmIsMajorTimeStep(trajectoryModel_M)) {
    /* set solver stop time */
    if (!(trajectoryModel_M->Timing.clockTick0+1)) {
      rtsiSetSolverStopTime(&trajectoryModel_M->solverInfo,
                            ((trajectoryModel_M->Timing.clockTickH0 + 1) *
        trajectoryModel_M->Timing.stepSize0 * 4294967296.0));
    } else {
      rtsiSetSolverStopTime(&trajectoryModel_M->solverInfo,
                            ((trajectoryModel_M->Timing.clockTick0 + 1) *
        trajectoryModel_M->Timing.stepSize0 +
        trajectoryModel_M->Timing.clockTickH0 *
        trajectoryModel_M->Timing.stepSize0 * 4294967296.0));
    }
  }                                    /* end MajorTimeStep */

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

  /* Integrator: '<Root>/x' */
  trajectoryModel_B.x = trajectoryModel_X.x_CSTATE;

  /* Sum: '<S3>/x-Planet_x' incorporates:
   *  Constant: '<Root>/0 '
   */
  rtb_Divide1 = trajectoryModel_B.x - trajectoryModel_P._Value;

  /* Integrator: '<Root>/y ' */
  trajectoryModel_B.y = trajectoryModel_X.y_CSTATE;

  /* Sqrt: '<S3>/Sqrt' incorporates:
   *  Product: '<S3>/(x-Planet_x)^2'
   *  Product: '<S3>/y^2'
   *  Sum: '<S3>/(x-Planet_x)^2+y^2'
   */
  rtb_Sqrt = sqrt(rtb_Divide1 * rtb_Divide1 + trajectoryModel_B.y *
                  trajectoryModel_B.y);

  /* If: '<Root>/If' incorporates:
   *  Constant: '<Root>/stopRadius'
   *  Constant: '<Root>/terminate'
   */
  if (rtmIsMajorTimeStep(trajectoryModel_M)) {
    if (rtb_Sqrt < trajectoryModel_P.stopRadius) {
      rtAction = 0;
    } else {
      rtAction = 1;
    }

    trajectoryModel_DW.If_ActiveSubsystem = rtAction;
  } else {
    rtAction = trajectoryModel_DW.If_ActiveSubsystem;
  }

  switch (rtAction) {
   case 0:
    /* Outputs for IfAction SubSystem: '<Root>/If Action Subsystem' incorporates:
     *  ActionPort: '<S1>/Action Port'
     */
    trajectoryMod_IfActionSubsystem(rtb_Sqrt,
      &trajectoryModel_B.IfActionSubsystem);

    /* End of Outputs for SubSystem: '<Root>/If Action Subsystem' */
    break;

   case 1:
    /* Outputs for IfAction SubSystem: '<Root>/If Action Subsystem1' incorporates:
     *  ActionPort: '<S2>/Action Port'
     */
    trajectoryMod_IfActionSubsystem(trajectoryModel_P.terminate_Value,
      &trajectoryModel_B.IfActionSubsystem1);

    /* End of Outputs for SubSystem: '<Root>/If Action Subsystem1' */
    break;
  }

  /* End of If: '<Root>/If' */
  if (rtmIsMajorTimeStep(trajectoryModel_M)) {
    /* Stop: '<Root>/Stop Simulation' */
    if (trajectoryModel_B.IfActionSubsystem1.In1 != 0.0) {
      rtmSetStopRequested(trajectoryModel_M, 1);
    }

    /* End of Stop: '<Root>/Stop Simulation' */
  }

  /* Integrator: '<Root>/dx' */
  trajectoryModel_B.x_dot = trajectoryModel_X.dx_CSTATE;

  /* Integrator: '<Root>/dy' */
  trajectoryModel_B.y_dot = trajectoryModel_X.dy_CSTATE;
  if (rtmIsMajorTimeStep(trajectoryModel_M)) {
  }

  /* Sum: '<S4>/x-Planet_x' incorporates:
   *  Constant: '<Root>/Earth_x'
   */
  rtb_Divide1 = trajectoryModel_B.x - (-trajectoryModel_P.mu);

  /* Sqrt: '<S4>/Sqrt' incorporates:
   *  Product: '<S4>/(x-Planet_x)^2'
   *  Product: '<S4>/y^2'
   *  Sum: '<S4>/(x-Planet_x)^2+y^2'
   */
  rtb_Divide1 = sqrt(rtb_Divide1 * rtb_Divide1 + trajectoryModel_B.y *
                     trajectoryModel_B.y);

  /* Product: '<Root>/Divide1' incorporates:
   *  Constant: '<Root>/Moon_x Earth mass'
   *  Product: '<Root>/Divide2'
   */
  rtb_Divide1 = (1.0 - trajectoryModel_P.mu) / (rtb_Divide1 * rtb_Divide1 *
    rtb_Divide1);

  /* Sum: '<S5>/x-Planet_x' incorporates:
   *  Constant: '<Root>/Moon_x Earth mass'
   */
  rtb_Divide = trajectoryModel_B.x - (1.0 - trajectoryModel_P.mu);

  /* Sqrt: '<S5>/Sqrt' incorporates:
   *  Product: '<S5>/(x-Planet_x)^2'
   *  Product: '<S5>/y^2'
   *  Sum: '<S5>/(x-Planet_x)^2+y^2'
   */
  rtb_Divide = sqrt(rtb_Divide * rtb_Divide + trajectoryModel_B.y *
                    trajectoryModel_B.y);

  /* Product: '<Root>/Divide' incorporates:
   *  Constant: '<Root>/Moon mass'
   *  Product: '<Root>/Divide3'
   */
  rtb_Divide = trajectoryModel_P.mu / (rtb_Divide * rtb_Divide * rtb_Divide);

  /* Sum: '<Root>/Add1' incorporates:
   *  Constant: '<Root>/2'
   */
  rtb_Add1 = (trajectoryModel_P._Value_f - rtb_Divide1) - rtb_Divide;

  /* Sum: '<Root>/Add' incorporates:
   *  Gain: '<Root>/Gain'
   *  Product: '<Root>/Product'
   */
  trajectoryModel_B.Add = trajectoryModel_B.y * rtb_Add1 -
    trajectoryModel_P.Gain_Gain * trajectoryModel_B.x_dot;

  /* Sum: '<Root>/Add6' incorporates:
   *  Constant: '<Root>/Earth_x'
   *  Constant: '<Root>/Moon_x Earth mass'
   *  Gain: '<Root>/Gain1'
   *  Product: '<Root>/Product5'
   *  Product: '<Root>/Product6'
   *  Product: '<Root>/Product7'
   *  Sum: '<Root>/Add7'
   */
  trajectoryModel_B.Add6 = (((1.0 - trajectoryModel_P.mu) * rtb_Divide +
    -trajectoryModel_P.mu * rtb_Divide1) + trajectoryModel_B.x * rtb_Add1) +
    trajectoryModel_P.Gain1_Gain * trajectoryModel_B.y_dot;
  if (rtmIsMajorTimeStep(trajectoryModel_M)) {
    /* Matfile logging */
    rt_UpdateTXYLogVars(trajectoryModel_M->rtwLogInfo,
                        (trajectoryModel_M->Timing.t));
  }                                    /* end MajorTimeStep */

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

    rt_ertODEUpdateContinuousStates(&trajectoryModel_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 (!(++trajectoryModel_M->Timing.clockTick0)) {
      ++trajectoryModel_M->Timing.clockTickH0;
    }

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

    {
      /* Update absolute timer for sample time: [0.01s, 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.01, 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.
       */
      trajectoryModel_M->Timing.clockTick1++;
      if (!trajectoryModel_M->Timing.clockTick1) {
        trajectoryModel_M->Timing.clockTickH1++;
      }
    }
  }                                    /* end MajorTimeStep */
}
示例#8
0
/* Function: rsimOneStepMT =====================================================
 *
 *      Perform one step of the model.
 *      Errors are set in the SimStruct's ErrorStatus, NULL means no errors.
 */
static void rsimOneStepMT(SimStruct *S)
{
    int_T  i;
    const int_T FIRST_TID = gbl_raccel_tid01eq ? 1 : 0;
    int_T* sampleHit = ssGetSampleHitPtr(S);

    ssSetSimTimeStep(S, MAJOR_TIME_STEP);
    
    /* Clear the flag that blocks set in their major time step methods (output,
       update, etc.) to flag that they have changed their state. If this flag is
       true then we need to run model outputs again at the first minor step
       (i.e., at the same time as the last major step).*/
    
    ssClearBlkStateChange(S);

#ifdef DEBUG_TIMING
    rsimDisplayTimingData(S,
                          sizeof(struct SimStruct_tag),
                          sizeof(struct _ssMdlInfo));
#endif
    if (gblExtModeEnabled) {
        rtExtModeOneStep(ssGetRTWExtModeInfo(S),
                         ssGetNumSampleTimes(S),
                         (boolean_T*)&ssGetStopRequested(S));
        if (ssGetStopRequested(S)) return;
    }
    /* Setup the task times and sample hit flags for the discrete rates */
    rsimUpdateDiscreteTaskTimesAndSampleHits(S);
    if (ssGetErrorStatus(S) != NULL) return;

    ssSetLogOutput(S,TRUE);

    /* Do output, log, update for the base rate */
    MdlOutputs(FIRST_TID);

    if (gblExtModeEnabled) {
        rtExtModeUploadCheckTrigger(ssGetNumSampleTimes(S));
        rtExtModeUpload(FIRST_TID, ssGetTaskTime(S, FIRST_TID));
    }

    if (ssGetLogOutput(S)) {
        (void)rt_UpdateTXYLogVars(ssGetRTWLogInfo(S), ssGetTPtr(S));
        if (ssGetErrorStatus(S) != NULL) return;
    }

    MdlUpdate(FIRST_TID);
    if (ssGetErrorStatus(S) != NULL) return;

    /* Do not log outputs during minor time steps */
    ssSetLogOutput(S, FALSE);
    ssSetTimeOfLastOutput(S,ssGetT(S));

    /* Call the solver push time forward based on the continuous dynamics */
    if (ssGetSampleTime(S,0) == CONTINUOUS_SAMPLE_TIME &&
        !ssGetStopRequested(S) ) {
        rsimUpdateSolverStopTimeForFixedStepMultiTaskingSim(S);
        if (!ssGetStopRequested(S)) rsimAdvanceSolver(S);
    }

    /* Do output and update for the remaining rates */
    ssSetLogOutput(S, TRUE);
    for (i = FIRST_TID+1; i < gbl_raccel_NumST; i++) {
        if ( !sampleHit[i] ) continue;
        MdlOutputs(i);
        rtExtModeUpload(i, ssGetTaskTime(S,i));
        MdlUpdate(i);
    }
    if (ssGetErrorStatus(S) != NULL) return;
    ssSetLogOutput(S, FALSE);

    if (gblExtModeEnabled) {
        rtExtModeCheckEndTrigger();
    }

    /* Update the timing engine and determine the solver stop time */
    rsimUpdateTimingEngineAndSolverStopTime(S);
    if (ssGetErrorStatus(S) != NULL) return;

} /* rsimOneStepMT */
示例#9
0
/* Function: rsimOutputLogUpdate ===============================================
 *
 */
static void rsimOutputLogUpdate(SimStruct* S)
{
    double currTime  = ssGetT(S);
    bool   logOutput = !ssGetOutputTimesOnly(S);

#ifdef DEBUG_TIMING
    rsimDisplayTimingData(S,
                          sizeof(struct SimStruct_tag),
                          sizeof(struct _ssMdlInfo));
#endif

    if (gblExtModeEnabled) {
        rtExtModeOneStep(ssGetRTWExtModeInfo(S),
                         ssGetNumSampleTimes(S),
                         (boolean_T*)&ssGetStopRequested(S));
        if (ssGetStopRequested(S)) return;
    }

    /* Setup the task times and sample hit flags for the discrete rates */
    rsimUpdateDiscreteTaskTimesAndSampleHits(S);
    if (ssGetErrorStatus(S) != NULL) return;

    /*
     * See if we are at an outputTime, and if so set logOutput to true and
     * increment the next output time index to point to the next entry in
     * the outputTimes array.
     */
    if ( ssGetNumOutputTimes(S) > 0 &&
         ssGetOutputTimesIndex(S) < ssGetNumOutputTimes(S) ) {
        time_T nextOutputTime = ssGetNextOutputTime(S);
        /* utAssert(currTime <= nextOutputTime); */
        if (currTime == nextOutputTime) {
            uint_T idx = ssGetOutputTimesIndex(S);
            ssSetOutputTimesIndex(S, idx+1);
            logOutput = 1; /* this is one of the specified output times */
        }
    }
    ssSetLogOutput(S, logOutput);

    MdlOutputs(0);

    if (gblExtModeEnabled) {
        rtExtModeSingleTaskUpload(S);
    }

    if (ssGetLogOutput(S)) {
        (void)rt_UpdateTXYLogVars(ssGetRTWLogInfo(S), ssGetTPtr(S));
        if (ssGetErrorStatus(S) != NULL) return;
    }

    MdlUpdate(0);
    if (ssGetErrorStatus(S) != NULL) return;

    ssSetLogOutput(S, FALSE);
    ssSetTimeOfLastOutput(S, currTime);

    /* Update the timing engine and determine the solver stop time */
    rsimUpdateTimingEngineAndSolverStopTime(S);
    if (ssGetErrorStatus(S) != NULL) return;

    if (gblExtModeEnabled) {
        rtExtModeCheckEndTrigger();
    }
    return;

} /* rsimOutputLogUpdate */
示例#10
0
/* Model step function */
void model1_step(void)
{
  /* local block i/o variables */
  real_T rtb_Kv;
  real_T rtb_Kv1;
  real_T rtb_Kv_p;
  real_T rtb_Kv1_d;
  real_T rtb_SineWaveA;
  real_T rtb_SineWaveB;
  real_T rtb_SineWaveC;
  real_T HoldSine;

  /* Gain: '<S1>/Kv' */
  rtb_Kv = model1_P.Kv_Gain * 0.0;

  /* Gain: '<S1>/Kv1' */
  rtb_Kv1 = model1_P.Kv1_Gain * 0.0;

  /* Gain: '<S2>/Kv' */
  rtb_Kv_p = model1_P.Kv_Gain_f * 0.0;

  /* Gain: '<S2>/Kv1' */
  rtb_Kv1_d = model1_P.Kv1_Gain_d * 0.0;

  /* Sin: '<S11>/Sine Wave A' */
  if (model1_DW.systemEnable != 0) {
    model1_DW.lastSin = sin(6.2831853071795862 * model1_P.Source1_Frequency *
      model1_M->Timing.taskTime0);
    model1_DW.lastCos = cos(6.2831853071795862 * model1_P.Source1_Frequency *
      model1_M->Timing.taskTime0);
    model1_DW.systemEnable = 0;
  }

  rtb_SineWaveA = ((model1_DW.lastSin * model1_P.SineWaveA_PCos +
                    model1_DW.lastCos * model1_P.SineWaveA_PSin) *
                   model1_P.SineWaveA_HCos + (model1_DW.lastCos *
    model1_P.SineWaveA_PCos - model1_DW.lastSin * model1_P.SineWaveA_PSin) *
                   model1_P.SineWaveA_Hsin) * model1_P.SineWaveA_Amp +
    model1_P.SineWaveA_Bias;

  /* End of Sin: '<S11>/Sine Wave A' */

  /* Sin: '<S11>/Sine Wave B' */
  if (model1_DW.systemEnable_i != 0) {
    model1_DW.lastSin_o = sin(6.2831853071795862 * model1_P.Source1_Frequency *
      model1_M->Timing.taskTime0);
    model1_DW.lastCos_l = cos(6.2831853071795862 * model1_P.Source1_Frequency *
      model1_M->Timing.taskTime0);
    model1_DW.systemEnable_i = 0;
  }

  rtb_SineWaveB = ((model1_DW.lastSin_o * model1_P.SineWaveB_PCos +
                    model1_DW.lastCos_l * model1_P.SineWaveB_PSin) *
                   model1_P.SineWaveB_HCos + (model1_DW.lastCos_l *
    model1_P.SineWaveB_PCos - model1_DW.lastSin_o * model1_P.SineWaveB_PSin) *
                   model1_P.SineWaveB_Hsin) * model1_P.SineWaveB_Amp +
    model1_P.SineWaveB_Bias;

  /* End of Sin: '<S11>/Sine Wave B' */

  /* Sin: '<S11>/Sine Wave C' */
  if (model1_DW.systemEnable_g != 0) {
    model1_DW.lastSin_b = sin(6.2831853071795862 * model1_P.Source1_Frequency *
      model1_M->Timing.taskTime0);
    model1_DW.lastCos_g = cos(6.2831853071795862 * model1_P.Source1_Frequency *
      model1_M->Timing.taskTime0);
    model1_DW.systemEnable_g = 0;
  }

  rtb_SineWaveC = ((model1_DW.lastSin_b * model1_P.SineWaveC_PCos +
                    model1_DW.lastCos_g * model1_P.SineWaveC_PSin) *
                   model1_P.SineWaveC_HCos + (model1_DW.lastCos_g *
    model1_P.SineWaveC_PCos - model1_DW.lastSin_b * model1_P.SineWaveC_PSin) *
                   model1_P.SineWaveC_Hsin) * model1_P.SineWaveC_Amp +
    model1_P.SineWaveC_Bias;

  /* End of Sin: '<S11>/Sine Wave C' */

  /* Update for Sin: '<S11>/Sine Wave A' */
  HoldSine = model1_DW.lastSin;
  model1_DW.lastSin = model1_DW.lastSin * model1_P.SineWaveA_HCos +
    model1_DW.lastCos * model1_P.SineWaveA_Hsin;
  model1_DW.lastCos = model1_DW.lastCos * model1_P.SineWaveA_HCos - HoldSine *
    model1_P.SineWaveA_Hsin;

  /* Update for Sin: '<S11>/Sine Wave B' */
  HoldSine = model1_DW.lastSin_o;
  model1_DW.lastSin_o = model1_DW.lastSin_o * model1_P.SineWaveB_HCos +
    model1_DW.lastCos_l * model1_P.SineWaveB_Hsin;
  model1_DW.lastCos_l = model1_DW.lastCos_l * model1_P.SineWaveB_HCos - HoldSine
    * model1_P.SineWaveB_Hsin;

  /* Update for Sin: '<S11>/Sine Wave C' */
  HoldSine = model1_DW.lastSin_b;
  model1_DW.lastSin_b = model1_DW.lastSin_b * model1_P.SineWaveC_HCos +
    model1_DW.lastCos_g * model1_P.SineWaveC_Hsin;
  model1_DW.lastCos_g = model1_DW.lastCos_g * model1_P.SineWaveC_HCos - HoldSine
    * model1_P.SineWaveC_Hsin;

  /* Matfile logging */
  rt_UpdateTXYLogVars(model1_M->rtwLogInfo, (&model1_M->Timing.taskTime0));

  /* signal main to stop simulation */
  {                                    /* Sample time: [5.0E-5s, 0.0s] */
    if ((rtmGetTFinal(model1_M)!=-1) &&
        !((rtmGetTFinal(model1_M)-model1_M->Timing.taskTime0) >
          model1_M->Timing.taskTime0 * (DBL_EPSILON))) {
      rtmSetErrorStatus(model1_M, "Simulation finished");
    }
  }

  /* 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 (!(++model1_M->Timing.clockTick0)) {
    ++model1_M->Timing.clockTickH0;
  }

  model1_M->Timing.taskTime0 = model1_M->Timing.clockTick0 *
    model1_M->Timing.stepSize0 + model1_M->Timing.clockTickH0 *
    model1_M->Timing.stepSize0 * 4294967296.0;
}