⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ps_flc3c_control_acc.c

📁 其中提到遺傳學的程式碼與應用提供給次淚相向的研究者參考下載
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * This file is not available for use in any application other than as a
 * MATLAB(R) MEX file for use with the Simulink(R) Accelerator product.
 */

/*
 * PS_flc3C_control_acc.c
 * 
 * Real-Time Workshop code generation for Simulink model "PS_flc3C_control_acc.mdl".
 *
 * Model Version              : 1.88
 * Real-Time Workshop version : 6.1  (R14SP1)  05-Sep-2004
 * C source code generated on : Wed May 11 22:35:49 2005
 */

#include <math.h>
#include <string.h>
#include "PS_flc3C_control_acc.h"
#include "PS_flc3C_control_acc_private.h"
#include <stdio.h>
#include "simstruc.h"
#include "fixedpoint.h"

#define CodeFormat                      S-Function
#define AccDefine1                      Accelerator_S-Function

/* Outputs for root system: '<Root>' */
static void mdlOutputs(SimStruct *S, int_T tid)
{
  /* simstruct variables */
  PS_flc3C_control_BlockIO *PS_flc3C_control_B = (PS_flc3C_control_BlockIO *)
    _ssGetBlockIO(S);
  PS_flc3C_control_ContinuousStates *PS_flc3C_control_X =
    (PS_flc3C_control_ContinuousStates*) ssGetContStates(S);
  PS_flc3C_control_D_Work *PS_flc3C_control_DWork = (PS_flc3C_control_D_Work *)
    ssGetRootDWork(S);
  PS_flc3C_control_Parameters *PS_flc3C_control_P = (PS_flc3C_control_Parameters
    *) ssGetDefaultParam(S);

  /* local block i/o variables */

  real_T rtb_Derivative1;
  real_T rtb_Derivative1_b;

  real_T rtb_Sum2;
  real_T rtb_Product_e[5];
  real_T rtb_Sum_l;
  real_T rtb_Product_i[5];
  real_T rtb_Sum_fp;

  real_T rtb_Product[2];
  real_T rtb_Sum_b;
  real_T rtb_Product_n[2];
  real_T rtb_Sum_c;
  real_T rtb_Product_g[2];
  real_T rtb_Sum_g;
  real_T rtb_Product_h[2];
  real_T rtb_Sum_j;
  real_T rtb_Product_j[2];
  real_T rtb_Sum_d;
  real_T rtb_netsum[5];
  real_T rtb_Product_j4[2];
  real_T rtb_Sum_i;
  real_T rtb_Product_hb[2];
  real_T rtb_Sum_h;
  real_T rtb_Product_l[2];
  real_T rtb_Sum_n;
  real_T rtb_Product_em[2];
  real_T rtb_Sum_f;
  real_T rtb_Product_k[2];
  real_T rtb_Sum_o;
  real_T rtb_netsum_h[5];

  /* Clock: '<Root>/Clock' */
  PS_flc3C_control_B->Clock = ssGetT(S);

  /* ToWorkspace: '<Root>/To Workspace4' */
  /* Call into Simulink for To Workspace */
  ssCallAccelRunBlock(S, 0, 1, SS_CALL_MDL_OUTPUTS);

  if (ssIsSampleHit(S, 3, tid)) {       /* Sample time: [-2.0s, 0.0s] */

    /* DiscretePulseGenerator: '<Root>/Pulse Generator' */
    real_T time = ssGetTaskTime(S,tid);
    real_T delay = 0.0;
    if ( (int_T)PS_flc3C_control_DWork->justEnabled ) {
      PS_flc3C_control_DWork->justEnabled = 0;
      if (time >= delay) {
        real_T ratio = (time - delay)/ PS_flc3C_control_P->PulseGenerator_Period;

        PS_flc3C_control_DWork->numCompleteCycles = (int)floor(ratio);

        if ( fabs((PS_flc3C_control_DWork->numCompleteCycles+1)- ratio ) <
         DBL_EPSILON * ratio )
        {
          PS_flc3C_control_DWork->numCompleteCycles =
            PS_flc3C_control_DWork->numCompleteCycles+1;
        }
        PS_flc3C_control_DWork->numCompleteCycles =
          PS_flc3C_control_DWork->numCompleteCycles;
        if (time < delay + PS_flc3C_control_DWork->numCompleteCycles *
         PS_flc3C_control_P->PulseGenerator_Period
         + PS_flc3C_control_P->PulseGenerator_Duty *
         PS_flc3C_control_P->PulseGenerator_Period/100) {
          PS_flc3C_control_DWork->currentValue = 1;
          PS_flc3C_control_DWork->nextTime = delay +
            PS_flc3C_control_DWork->numCompleteCycles *
            PS_flc3C_control_P->PulseGenerator_Period
            + PS_flc3C_control_P->PulseGenerator_Duty *
            PS_flc3C_control_P->PulseGenerator_Period/100;
        } else {
          PS_flc3C_control_DWork->currentValue = 0;
          PS_flc3C_control_DWork->nextTime = delay +
            (PS_flc3C_control_DWork->numCompleteCycles + 1) *
            PS_flc3C_control_P->PulseGenerator_Period;
        }
      } else {
        PS_flc3C_control_DWork->numCompleteCycles = 0;
        PS_flc3C_control_DWork->currentValue = 0;
        PS_flc3C_control_DWork->nextTime = delay;
      }
    } else {
      /* Determine if any values need to change */
      if (PS_flc3C_control_DWork->nextTime <= time) {
        if (PS_flc3C_control_DWork->currentValue == 1) {
          PS_flc3C_control_DWork->currentValue = 0;
          PS_flc3C_control_DWork->nextTime = delay +
            (PS_flc3C_control_DWork->numCompleteCycles + 1) *
            PS_flc3C_control_P->PulseGenerator_Period;
        } else {
          if ( PS_flc3C_control_DWork->nextTime != delay) {
            PS_flc3C_control_DWork->numCompleteCycles += 1;
          }
          PS_flc3C_control_DWork->currentValue = 1;
          PS_flc3C_control_DWork->nextTime = delay +
            PS_flc3C_control_DWork->numCompleteCycles *
            PS_flc3C_control_P->PulseGenerator_Period
            + 0.01 * PS_flc3C_control_P->PulseGenerator_Duty *
            PS_flc3C_control_P->PulseGenerator_Period;
        }
      }
    }

    /* Set the next hit time */
    {
      real_T tNext = PS_flc3C_control_DWork->nextTime;
      _ssSetVarNextHitTime(S, (int_T)0.0, tNext);
    }

    /* Output the values */
    if (PS_flc3C_control_DWork->currentValue == 1){
      PS_flc3C_control_B->PulseGenerator =
        PS_flc3C_control_P->PulseGenerator_Amp;
    } else {
      PS_flc3C_control_B->PulseGenerator = 0.0;
    }
  }
  if (ssIsSampleHit(S, 1, tid)) {       /* Sample time: [0.0s, 1.0s] */

    PS_flc3C_control_B->Constant = PS_flc3C_control_P->Constant_Value;

    rtb_Sum2 = PS_flc3C_control_B->PulseGenerator - PS_flc3C_control_B->Constant;

    PS_flc3C_control_B->Gain = rtb_Sum2 * PS_flc3C_control_P->Gain_Gain;
  }

  /* TransferFcn Block: <Root>/Transfer Fcn2 */
  PS_flc3C_control_B->TransferFcn2 =
    PS_flc3C_control_P->TransferFcn2_C*PS_flc3C_control_X->TransferFcn2_CSTATE[2];

  /* Scope: '<Root>/Scope' */
  /* Call into Simulink for Scope */
  ssCallAccelRunBlock(S, 0, 7, SS_CALL_MDL_OUTPUTS);

  if (ssIsSampleHit(S, 1, tid)) {       /* Sample time: [0.0s, 1.0s] */

    PS_flc3C_control_B->Gain1 = rtb_Sum2 * PS_flc3C_control_P->Gain1_Gain;
  }

  /* TransferFcn Block: <Root>/Transfer Fcn1 */
  PS_flc3C_control_B->TransferFcn1 =
    PS_flc3C_control_P->TransferFcn1_C*PS_flc3C_control_X->TransferFcn1_CSTATE[2];

  /* Scope: '<Root>/Scope1' */
  /* Call into Simulink for Scope */
  ssCallAccelRunBlock(S, 0, 10, SS_CALL_MDL_OUTPUTS);

  if (ssIsSampleHit(S, 1, tid)) {       /* Sample time: [0.0s, 1.0s] */

    /* ToWorkspace: '<Root>/To Workspace1' */
    /* Call into Simulink for To Workspace */
    ssCallAccelRunBlock(S, 0, 11, SS_CALL_MDL_OUTPUTS);

    /* ToWorkspace: '<Root>/To Workspace3' */
    /* Call into Simulink for To Workspace */
    ssCallAccelRunBlock(S, 0, 12, SS_CALL_MDL_OUTPUTS);
  }

  PS_flc3C_control_B->Sum = PS_flc3C_control_B->Gain -
    PS_flc3C_control_B->TransferFcn2;

  /* Derivative Block: <S1>/Derivative1 */
  {
    real_T t = ssGetTaskTime(S,tid);
    real_T timeStampA = PS_flc3C_control_DWork->Derivative1_RWORK.TimeStampA;
    real_T timeStampB = PS_flc3C_control_DWork->Derivative1_RWORK.TimeStampB;

    if (timeStampA >= t && timeStampB >= t) {
      rtb_Derivative1 = 0.0;
    } else {
      real_T deltaT;
      real_T *lastBank = &PS_flc3C_control_DWork->Derivative1_RWORK.TimeStampA;
      if (timeStampA < timeStampB) {
        if (timeStampB < t) {
          lastBank += 2;
        }
      } else if (timeStampA >= t) {
        lastBank += 2;
      }
      deltaT = t - *lastBank++;
      rtb_Derivative1 = (PS_flc3C_control_B->Sum - *lastBank++) / deltaT;
    }
  }

  if (ssIsSampleHit(S, 2, tid)) {       /* Sample time: [0.001s, 0.0s] */

    PS_flc3C_control_B->IW111[0] = PS_flc3C_control_P->IW111_Value[0];
    PS_flc3C_control_B->IW111[1] = PS_flc3C_control_P->IW111_Value[1];

    PS_flc3C_control_B->IW112[0] = PS_flc3C_control_P->IW112_Value[0];
    PS_flc3C_control_B->IW112[1] = PS_flc3C_control_P->IW112_Value[1];

    PS_flc3C_control_B->IW113[0] = PS_flc3C_control_P->IW113_Value[0];
    PS_flc3C_control_B->IW113[1] = PS_flc3C_control_P->IW113_Value[1];

    PS_flc3C_control_B->IW114[0] = PS_flc3C_control_P->IW114_Value[0];
    PS_flc3C_control_B->IW114[1] = PS_flc3C_control_P->IW114_Value[1];

    PS_flc3C_control_B->IW115[0] = PS_flc3C_control_P->IW115_Value[0];
    PS_flc3C_control_B->IW115[1] = PS_flc3C_control_P->IW115_Value[1];
  }

  PS_flc3C_control_B->SE1 = PS_flc3C_control_B->Sum *
    PS_flc3C_control_P->SE1_Gain;

  PS_flc3C_control_B->SDE001 = rtb_Derivative1 * PS_flc3C_control_P->SDE001_Gain;

  if (ssIsSampleHit(S, 2, tid)) {       /* Sample time: [0.001s, 0.0s] */

    rtb_Product[0] = PS_flc3C_control_B->IW111[0] * PS_flc3C_control_B->SE1;
    rtb_Product[1] = PS_flc3C_control_B->IW111[1] * PS_flc3C_control_B->SDE001;

    /* Sum: '<S14>/Sum' */
    rtb_Sum_b = rtb_Product[0];
    rtb_Sum_b += rtb_Product[1];

    rtb_Product_n[0] = PS_flc3C_control_B->IW112[0] * PS_flc3C_control_B->SE1;
    rtb_Product_n[1] = PS_flc3C_control_B->IW112[1] * PS_flc3C_control_B->SDE001;

    /* Sum: '<S15>/Sum' */
    rtb_Sum_c = rtb_Product_n[0];
    rtb_Sum_c += rtb_Product_n[1];

    rtb_Product_g[0] = PS_flc3C_control_B->IW113[0] * PS_flc3C_control_B->SE1;
    rtb_Product_g[1] = PS_flc3C_control_B->IW113[1] * PS_flc3C_control_B->SDE001;

    /* Sum: '<S16>/Sum' */
    rtb_Sum_g = rtb_Product_g[0];
    rtb_Sum_g += rtb_Product_g[1];

    rtb_Product_h[0] = PS_flc3C_control_B->IW114[0] * PS_flc3C_control_B->SE1;
    rtb_Product_h[1] = PS_flc3C_control_B->IW114[1] * PS_flc3C_control_B->SDE001;

    /* Sum: '<S17>/Sum' */
    rtb_Sum_j = rtb_Product_h[0];
    rtb_Sum_j += rtb_Product_h[1];

    rtb_Product_j[0] = PS_flc3C_control_B->IW115[0] * PS_flc3C_control_B->SE1;
    rtb_Product_j[1] = PS_flc3C_control_B->IW115[1] * PS_flc3C_control_B->SDE001;

    /* Sum: '<S18>/Sum' */
    rtb_Sum_d = rtb_Product_j[0];
    rtb_Sum_d += rtb_Product_j[1];

    {
      real_T cg_in_0_33_0[5];
      int32_T i1;

      for(i1=0; i1<5; i1++) {
        PS_flc3C_control_B->b1[i1] = PS_flc3C_control_P->b1_Value[i1];
      }

      cg_in_0_33_0[0] = rtb_Sum_b;
      cg_in_0_33_0[1] = rtb_Sum_c;
      cg_in_0_33_0[2] = rtb_Sum_g;
      cg_in_0_33_0[3] = rtb_Sum_j;
      cg_in_0_33_0[4] = rtb_Sum_d;
      for(i1=0; i1<5; i1++) {
        rtb_netsum[i1] = cg_in_0_33_0[i1] + PS_flc3C_control_B->b1[i1];

        PS_flc3C_control_B->Saturation[i1] = rt_SATURATE(rtb_netsum[i1],
         PS_flc3C_control_P->Saturation_LowerSat,
         PS_flc3C_control_P->Saturation_UpperSat);
      }
    }
  }
  if (ssIsSampleHit(S, 1, tid)) {       /* Sample time: [0.0s, 1.0s] */

    {
      int32_T i1;

      for(i1=0; i1<5; i1++) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -