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

📄 exm09322_1_4_acc.c

📁 精通matlab
💻 C
字号:
#if 0

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.

If you do not have the Real-Time Workshop licensed, this file contains
encrypted block names, etc. If you purchase the Real-Time Workshop,
this file will contain full block descriptions and improved variable
names.

#endif

/*
 * exm09322_1_4_acc.c
 *
 * Real-Time Workshop code generation for Simulink model "exm09322_1_4_acc.mdl".
 *
 * Model Version                        : 1.2
 * Real-Time Workshop file version      : 4.0 $Date: 2000/09/19 19:45:27 $
 * Real-Time Workshop file generated on : Sat Aug 11 16:25:43 2001
 * TLC version                          : 4.0 (Aug 21 2000)
 * C source code generated on           : Sat Aug 11 16:25:43 2001
 *
 * Relevant TLC Options:
 *   InlineParameters      = 0
 *   RollThreshold         = 5
 *   CodeFormat            = S-Function
 *
 * Simulink model settings:
 *   Solver     : VariableStep
 *   StartTime  : 0.0 s
 *   StopTime   : 100.0 s
 *   Variable step solver used
 */

#include <math.h>
#include <string.h>
#include "exm09322_1_4_acc.h"
#include "exm09322_1_4_acc_prm.h"

/* Start of Functions in model "exm09322_1_4_acc" */

/* Compute block outputs */
static void mdlOutputs(SimStruct *S, int_T tid)
{
  /* simstruct variables */
  exm09322_1_4_BlockIO *exm09322_1_4_B = (exm09322_1_4_BlockIO *) _ssGetBlockIO(S);
  exm09322_1_4_ContinuousStates *exm09322_1_4_X = (exm09322_1_4_ContinuousStates*) ssGetContStates(S);
  exm09322_1_4_D_Work *exm09322_1_4_DWork = (exm09322_1_4_D_Work *) ssGetRootDWork(S);
  exm09322_1_4_Parameters *exm09322_1_4_P = (exm09322_1_4_Parameters *) ssGetDefaultParam(S);

  /* local block i/o variables */
  real_T rtb_root_Constant;
  real_T rtb_root_Fw;
  real_T rtb_temp9;
  real_T rtb_temp10;

  if (ssIsContinuousTask(S, tid)) {     /* Sample time: [0.0, 0.0] */
    /* Integrator Block: <Root>/Int1 */
    exm09322_1_4_B->root_x_c = exm09322_1_4_X->root_Int1;

    /* Display Block: <Root>/Display */
    /* Call into Simulink for Display */
    ssCallAccelRunBlock(S, 0, 1, SS_CALL_MDL_OUTPUTS);

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

    /* Clock Block: <Root>/Clock */
    rtb_temp10 = ssGetT(S);
  }

  if (ssIsSampleHit(S, 1, tid)) {       /* Sample time: [0.0, 1.0] */
    /* Constant Block: <Root>/Constant */
    rtb_root_Constant = (exm09322_1_4_P->root_Constant_Value);
  }

  if (ssIsContinuousTask(S, tid)) {     /* Sample time: [0.0, 0.0] */
    /* Integrator Block: <Root>/Int2 */
    rtb_temp9 = exm09322_1_4_X->root_Int2;

    /* Fcn Block: <Root>/FH */
    /* Expression: 30*sin(0.0001*u) */
    rtb_temp9 = 30.0 * sin( 0.0001 * rtb_temp9 );

    /* Fcn Block: <Root>/FW */
    /* Expression: 0.001*(u[1]+20*sin(0.01*u[2]))^2 */
    rtb_root_Fw = 0.001 * pow( exm09322_1_4_B->root_x_c + 20.0 * sin(
        0.01 * rtb_temp10 ) , 2.0);
  }

  if (ssIsSampleHit(S, 1, tid)) {       /* Sample time: [0.0, 1.0] */
    /* Constant Block: <Root>/Max Brake */
    exm09322_1_4_B->root_Max_Brake = (exm09322_1_4_P->root_Max_Brake_Value);

    /* Constant Block: <Root>/Max Thrust */
    exm09322_1_4_B->root_Max_Thrust = (exm09322_1_4_P->root_Max_Thrust_Value);

    /* Gain Block: <S1>/Slider Gain */
    exm09322_1_4_B->s1_Slider_Gain = rtb_root_Constant * (exm09322_1_4_P->s1_Slider_Gain_Gain);
  }

  if (ssIsContinuousTask(S, tid)) {     /* Sample time: [0.0, 0.0] */
    /* Sum Block: <Root>/Sum */
    rtb_temp10 = - exm09322_1_4_B->root_x_c + exm09322_1_4_B->s1_Slider_Gain;

    /* Gain Block: <Root>/Ke */
    exm09322_1_4_B->root_Fc = rtb_temp10 * (exm09322_1_4_P->root_Ke_Gain);

    /* MinMax Block: <Root>/UpLim */
    if (ssIsMajorTimeStep(S)) {
      exm09322_1_4_DWork->root_UpLim_MODE = (exm09322_1_4_B->root_Max_Thrust < exm09322_1_4_B->root_Fc) ? 0: 1;
    }
    if (exm09322_1_4_DWork->root_UpLim_MODE == 0) {
      exm09322_1_4_B->root_UpLim = exm09322_1_4_B->root_Max_Thrust;
    } else {
      exm09322_1_4_B->root_UpLim = exm09322_1_4_B->root_Fc;
    }

    /* MinMax Block: <Root>/LowLim */
    if (ssIsMajorTimeStep(S)) {
      exm09322_1_4_DWork->root_LowLim_MODE = (exm09322_1_4_B->root_Max_Brake > exm09322_1_4_B->root_UpLim) ? 0: 1;
    }
    if (exm09322_1_4_DWork->root_LowLim_MODE == 0) {
      rtb_temp10 = exm09322_1_4_B->root_Max_Brake;
    } else {
      rtb_temp10 = exm09322_1_4_B->root_UpLim;
    }

    /* Sum Block: <Root>/Sum1 */
    rtb_temp10 = rtb_temp10 - rtb_temp9 - rtb_root_Fw;

    /* Gain Block: <Root>/InvMass */
    exm09322_1_4_B->root_x_a = rtb_temp10 * (exm09322_1_4_P->root_InvMass_Gain);
  }
}

/* Perform model update */
#define MDL_UPDATE
static void mdlUpdate(SimStruct *S, int_T tid)
{
  /* (no update code required) */
}

/* Compute model derivatives */
#define MDL_DERIVATIVES
static void mdlDerivatives(SimStruct *S)
{
  /* simstruct variables */
  exm09322_1_4_BlockIO *exm09322_1_4_B = (exm09322_1_4_BlockIO *) _ssGetBlockIO(S);

  /* Integrator Block: <Root>/Int1 */
  {
    real_T *dx = ssGetdX(S);

    dx[0] = exm09322_1_4_B->root_x_a;
  }

  /* Integrator Block: <Root>/Int2 */
  {
    real_T *dx = ssGetdX(S);

    dx[1] = exm09322_1_4_B->root_x_c;
  }
}

/* Compute model zero crossings */
#define MDL_ZERO_CROSSINGS
static void mdlZeroCrossings(SimStruct *S)
{
  /* simstruct variables */
  exm09322_1_4_BlockIO *exm09322_1_4_B = (exm09322_1_4_BlockIO *) _ssGetBlockIO(S);
  exm09322_1_4_D_Work *exm09322_1_4_DWork = (exm09322_1_4_D_Work *) ssGetRootDWork(S);
  exm09322_1_4_NonsampledZCs *exm09322_1_4_NonsampledZC = (exm09322_1_4_NonsampledZCs *) ssGetNonsampledZCs(S);

  /* MinMax Block: <Root>/UpLim */
  if (exm09322_1_4_B->root_Max_Thrust < exm09322_1_4_B->root_Fc) {
    if (exm09322_1_4_DWork->root_UpLim_MODE == 0) {
      exm09322_1_4_NonsampledZC->root_UpLim = exm09322_1_4_B->root_Max_Thrust - exm09322_1_4_B->root_Max_Thrust;
    } else {
      exm09322_1_4_NonsampledZC->root_UpLim = exm09322_1_4_B->root_Max_Thrust - exm09322_1_4_B->root_Fc;
    }
  } else {
    if (exm09322_1_4_DWork->root_UpLim_MODE == 0) {
      exm09322_1_4_NonsampledZC->root_UpLim = exm09322_1_4_B->root_Fc - exm09322_1_4_B->root_Max_Thrust;
    } else {
      exm09322_1_4_NonsampledZC->root_UpLim = exm09322_1_4_B->root_Fc - exm09322_1_4_B->root_Fc;
    }
  }

  /* MinMax Block: <Root>/LowLim */
  if (exm09322_1_4_B->root_Max_Brake > exm09322_1_4_B->root_UpLim) {
    if (exm09322_1_4_DWork->root_LowLim_MODE == 0) {
      exm09322_1_4_NonsampledZC->root_LowLim = exm09322_1_4_B->root_Max_Brake - exm09322_1_4_B->root_Max_Brake;
    } else {
      exm09322_1_4_NonsampledZC->root_LowLim = exm09322_1_4_B->root_Max_Brake - exm09322_1_4_B->root_UpLim;
    }
  } else {
    if (exm09322_1_4_DWork->root_LowLim_MODE == 0) {
      exm09322_1_4_NonsampledZC->root_LowLim = exm09322_1_4_B->root_UpLim - exm09322_1_4_B->root_Max_Brake;
    } else {
      exm09322_1_4_NonsampledZC->root_LowLim = exm09322_1_4_B->root_UpLim - exm09322_1_4_B->root_UpLim;
    }
  }
}

/* End of Functions in model "exm09322_1_4_acc" */

#include "exm09322_1_4_acc_reg.h"

/* [EOF] exm09322_1_4_acc.c */

⌨️ 快捷键说明

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