📄 ex38s2_acc.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
/*
* ex38s2_acc.c
*
* Real-Time Workshop code generation for Simulink model "ex38s2_acc.mdl".
*
* Model Version : 1.58
* Real-Time Workshop file version : 4.0 $Date: 2000/09/19 19:45:27 $
* Real-Time Workshop file generated on : Thu Feb 07 20:20:20 2002
* TLC version : 4.0 (Aug 21 2000)
* C source code generated on : Thu Feb 07 20:20:20 2002
*
* Relevant TLC Options:
* InlineParameters = 0
* RollThreshold = 5
* CodeFormat = S-Function
*
* Simulink model settings:
* Solver : VariableStep
* StartTime : 0.0 s
* StopTime : 140.0 s
* Variable step solver used
*/
#include <math.h>
#include <string.h>
#include "ex38s2_acc.h"
#include "ex38s2_acc_prm.h"
real_T rtInf;
/* Start of Functions in model "ex38s2_acc" */
/* Compute block outputs */
static void mdlOutputs(SimStruct *S, int_T tid)
{
/* simstruct variables */
ex38s2_BlockIO *ex38s2_B = (ex38s2_BlockIO *) _ssGetBlockIO(S);
ex38s2_ContinuousStates *ex38s2_X = (ex38s2_ContinuousStates*) ssGetContStates(S);
ex38s2_D_Work *ex38s2_DWork = (ex38s2_D_Work *) ssGetRootDWork(S);
ex38s2_Parameters *ex38s2_P = (ex38s2_Parameters *) ssGetDefaultParam(S);
/* local block i/o variables */
real_T rtb_s1_White_Noise;
real_T rtb_temp19;
if (ssIsSampleHit(S, 3, tid)) { /* Sample time: [30.0, 0.0] */
/* RandomNumber Block: <S1>/White Noise */
rtb_s1_White_Noise = ex38s2_DWork->s1_White_Noise_RWORK.NextOutput;
/* Gain Block: <S1>/Gain */
ex38s2_B->s1_Gain = rtb_s1_White_Noise * (ex38s2_P->s1_Gain_Gain);
/* Outport Block: <Root>/Out1 */
/* Call into Simulink for root Outports */
ssCallAccelRunBlock(S, 0, 2, SS_CALL_MDL_OUTPUTS);
}
if (ssIsContinuousTask(S, tid)) { /* Sample time: [0.0, 0.0] */
/* StateSpace Block: <S3>/Internal */
{
ex38s2_B->s3_Internal = (ex38s2_P->s3_Internal_C)*ex38s2_X->s3_Internal[1];
}
/* Outport Block: <Root>/Out2 */
/* Call into Simulink for root Outports */
ssCallAccelRunBlock(S, 0, 4, SS_CALL_MDL_OUTPUTS);
/* Sum Block: <Root>/Sum */
ex38s2_B->root_Sum = ex38s2_B->s1_Gain - ex38s2_B->s3_Internal;
/* Gain Block: <Root>/Gain */
ex38s2_B->root_Gain = ex38s2_B->root_Sum * (ex38s2_P->root_Gain_Gain);
/* Abs Block: <Root>/Abs */
if (ssIsMajorTimeStep(S)) {
ex38s2_DWork->root_Abs_MODE = ex38s2_B->root_Gain >= 0.0;
}
rtb_temp19 = (ex38s2_DWork->root_Abs_MODE)? ex38s2_B->root_Gain:-(ex38s2_B->root_Gain);
}
if (ssIsSampleHit(S, 2, tid)) { /* Sample time: [0.01, 0.0] */
/* UnitDelay Block: <Root>/Unit Delay Ts=0.1 */
ex38s2_B->root_Unit_Delay_Ts_0_1 = ex38s2_DWork->root_Unit_Delay_Ts_0_1_DSTATE;
}
if (ssIsContinuousTask(S, tid)) { /* Sample time: [0.0, 0.0] */
/* Sum Block: <Root>/Sum2 */
ex38s2_B->root_Sum2 = rtb_temp19 + ex38s2_B->root_Unit_Delay_Ts_0_1;
/* Outport Block: <Root>/Out4 */
/* Call into Simulink for root Outports */
ssCallAccelRunBlock(S, 0, 10, SS_CALL_MDL_OUTPUTS);
}
if (ssIsSampleHit(S, 1, tid)) { /* Sample time: [0.0, 1.0] */
/* Constant Block: <Root>/Constant */
ex38s2_B->root_Constant = (ex38s2_P->root_Constant_Value);
}
if (ssIsContinuousTask(S, tid)) { /* Sample time: [0.0, 0.0] */
/* RelationalOperator Block: <Root>/Relational Operator */
if (ssIsMajorTimeStep(S)) {
ex38s2_DWork->root_Relational_Operator_MODE = (int_T)(ex38s2_B->root_Sum2 > ex38s2_B->root_Constant);
}
ex38s2_B->root_Relational_Operator = (real_T)(ex38s2_DWork->root_Relational_Operator_MODE);
/* Outport Block: <Root>/Out3 */
/* Call into Simulink for root Outports */
ssCallAccelRunBlock(S, 0, 13, SS_CALL_MDL_OUTPUTS);
/* Display Block: <Root>/Display */
/* Call into Simulink for Display */
ssCallAccelRunBlock(S, 0, 14, SS_CALL_MDL_OUTPUTS);
}
if (ssIsSampleHit(S, 1, tid)) { /* Sample time: [0.0, 1.0] */
/* Display Block: <Root>/Display1 */
/* Call into Simulink for Display */
ssCallAccelRunBlock(S, 0, 15, SS_CALL_MDL_OUTPUTS);
}
if (ssIsContinuousTask(S, tid)) { /* Sample time: [0.0, 0.0] */
/* Scope Block: <Root>/Scope */
/* Call into Simulink for Scope */
ssCallAccelRunBlock(S, 0, 16, SS_CALL_MDL_OUTPUTS);
}
if (ssIsSampleHit(S, 2, tid)) { /* Sample time: [0.01, 0.0] */
/* ZeroOrderHold Block: <Root>/Zero-Order Hold1 */
ex38s2_B->root_Zero_Order_Hold1[0] = ex38s2_B->s1_Gain;
ex38s2_B->root_Zero_Order_Hold1[1] = ex38s2_B->s3_Internal;
/* ToWorkspace Block: <Root>/To Workspace1 */
/* Call into Simulink for To Workspace */
ssCallAccelRunBlock(S, 0, 19, SS_CALL_MDL_OUTPUTS);
}
if (ssIsContinuousTask(S, tid)) { /* Sample time: [0.0, 0.0] */
/* Derivative Block: <Root>/Derivative */
{
real_T t = ssGetTaskTime(S,tid);
real_T timeStampA = ex38s2_DWork->root_Derivative_RWORK.TimeStampA;
real_T timeStampB = ex38s2_DWork->root_Derivative_RWORK.TimeStampB;
if (timeStampA >= t && timeStampB >= t) {
rtb_temp19 = 0.0;
} else {
real_T deltaT;
real_T *lastBank = &ex38s2_DWork->root_Derivative_RWORK.TimeStampA;
if (timeStampA < timeStampB) {
if (timeStampB < t) {
lastBank += 2;
}
} else if (timeStampA >= t) {
lastBank += 2;
}
deltaT = t - *lastBank++;
rtb_temp19 = (ex38s2_B->root_Sum - *lastBank++) / deltaT;
}
}
/* Gain Block: <S2>/Gain */
ex38s2_B->s2_Gain = ex38s2_B->root_Sum * (ex38s2_P->s2_Gain_Gain);
/* Saturate Block: <S2>/Saturation */
if (ssIsMajorTimeStep(S)) {
if (ex38s2_B->s2_Gain >= (ex38s2_P->s2_Saturation_UpperSat)) {
ex38s2_DWork->s2_Saturation_MODE = 1;
} else if (ex38s2_B->s2_Gain > (ex38s2_P->s2_Saturation_LowerSat)) {
ex38s2_DWork->s2_Saturation_MODE = 0;
} else {
ex38s2_DWork->s2_Saturation_MODE = -1;
}
}
/* Output value */
if (ex38s2_DWork->s2_Saturation_MODE == 1) {
ex38s2_B->s2_Saturation = (ex38s2_P->s2_Saturation_UpperSat);
} else if (ex38s2_DWork->s2_Saturation_MODE == -1) {
ex38s2_B->s2_Saturation = (ex38s2_P->s2_Saturation_LowerSat);
} else {
ex38s2_B->s2_Saturation = ex38s2_B->s2_Gain;
}
/* Gain Block: <S2>/Gain1 */
ex38s2_B->s2_Gain1 = rtb_temp19 * (ex38s2_P->s2_Gain1_Gain);
/* Saturate Block: <S2>/Saturation1 */
if (ssIsMajorTimeStep(S)) {
if (ex38s2_B->s2_Gain1 >= (ex38s2_P->s2_Saturation1_UpperSat)) {
ex38s2_DWork->s2_Saturation1_MODE = 1;
} else if (ex38s2_B->s2_Gain1 > (ex38s2_P->s2_Saturation1_LowerSat)) {
ex38s2_DWork->s2_Saturation1_MODE = 0;
} else {
ex38s2_DWork->s2_Saturation1_MODE = -1;
}
}
/* Output value */
if (ex38s2_DWork->s2_Saturation1_MODE == 1) {
ex38s2_B->s2_Saturation1 = (ex38s2_P->s2_Saturation1_UpperSat);
} else if (ex38s2_DWork->s2_Saturation1_MODE == -1) {
ex38s2_B->s2_Saturation1 = (ex38s2_P->s2_Saturation1_LowerSat);
} else {
ex38s2_B->s2_Saturation1 = ex38s2_B->s2_Gain1;
}
/* Level2 S-Function Block: <S4>/FIS S-function (sffis) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 0, 25, SS_CALL_MDL_OUTPUTS);
/* Gain Block: <S2>/Gain2 */
rtb_temp19 = ex38s2_B->s4_FIS_S_function * (ex38s2_P->s2_Gain2_Gain);
}
if (ssIsSampleHit(S, 2, tid)) { /* Sample time: [0.01, 0.0] */
/* UnitDelay Block: <Root>/Unit Delay Ts=0.01 */
ex38s2_B->root_Unit_Delay_Ts_0_01 = ex38s2_DWork->root_Unit_Delay_Ts_0_01_DSTATE;
}
if (ssIsContinuousTask(S, tid)) { /* Sample time: [0.0, 0.0] */
/* Sum Block: <Root>/Sum1 */
ex38s2_B->root_Sum1 = rtb_temp19 + ex38s2_B->root_Unit_Delay_Ts_0_01;
/* Clock Block: <Root>/Clock */
ex38s2_B->root_Clock = ssGetT(S);
}
if (ssIsSampleHit(S, 2, tid)) { /* Sample time: [0.01, 0.0] */
/* ZeroOrderHold Block: <Root>/Zero-Order Hold7 */
ex38s2_B->root_Zero_Order_Hold7 = ex38s2_B->root_Clock;
/* ToWorkspace Block: <Root>/To Workspace */
/* Call into Simulink for To Workspace */
ssCallAccelRunBlock(S, 0, 31, SS_CALL_MDL_OUTPUTS);
}
}
/* Perform model update */
#define MDL_UPDATE
static void mdlUpdate(SimStruct *S, int_T tid)
{
/* simstruct variables */
ex38s2_BlockIO *ex38s2_B = (ex38s2_BlockIO *) _ssGetBlockIO(S);
ex38s2_D_Work *ex38s2_DWork = (ex38s2_D_Work *) ssGetRootDWork(S);
ex38s2_Parameters *ex38s2_P = (ex38s2_Parameters *) ssGetDefaultParam(S);
if (ssIsSampleHit(S, 3, tid)) { /* Sample time: [30.0, 0.0] */
/* RandomNumber Block: <S1>/White Noise */
ex38s2_DWork->s1_White_Noise_RWORK.NextOutput = rt_NormalRand((uint_T *)&ex38s2_DWork->s1_White_Noise_IWORK.RandSeed)*(ex38s2_P->s1_White_Noise_StdDev)+(ex38s2_P->s1_White_Noise_Mean);
}
if (ssIsSampleHit(S, 2, tid)) { /* Sample time: [0.01, 0.0] */
/* UnitDelay Block: <Root>/Unit Delay Ts=0.1 */
ex38s2_DWork->root_Unit_Delay_Ts_0_1_DSTATE = ex38s2_B->root_Sum2;
}
if (ssIsContinuousTask(S, tid)) { /* Sample time: [0.0, 0.0] */
/* Stop Block: <Root>/Stop Simulation */
if (ex38s2_B->root_Relational_Operator != 0.0) {
ssSetStopRequested(S, 1);
}
/* Derivative Block: <Root>/Derivative */
{
real_T timeStampA = ex38s2_DWork->root_Derivative_RWORK.TimeStampA;
real_T timeStampB = ex38s2_DWork->root_Derivative_RWORK.TimeStampB;
real_T *lastBank = &ex38s2_DWork->root_Derivative_RWORK.TimeStampA;
if (timeStampA != rtInf) {
if (timeStampB == rtInf) {
lastBank += 2;
} else if (timeStampA >= timeStampB) {
lastBank += 2;
}
}
*lastBank++ = ssGetTaskTime(S,tid);
*lastBank++ = ex38s2_B->root_Sum;
}
}
if (ssIsSampleHit(S, 2, tid)) { /* Sample time: [0.01, 0.0] */
/* UnitDelay Block: <Root>/Unit Delay Ts=0.01 */
ex38s2_DWork->root_Unit_Delay_Ts_0_01_DSTATE = ex38s2_B->root_Sum1;
}
}
/* Compute model derivatives */
#define MDL_DERIVATIVES
static void mdlDerivatives(SimStruct *S)
{
/* simstruct variables */
ex38s2_BlockIO *ex38s2_B = (ex38s2_BlockIO *) _ssGetBlockIO(S);
ex38s2_ContinuousStates *ex38s2_X = (ex38s2_ContinuousStates*) ssGetContStates(S);
ex38s2_Parameters *ex38s2_P = (ex38s2_Parameters *) ssGetDefaultParam(S);
/* StateSpace Block: <S3>/Internal */
{
real_T *dx = ssGetdX(S)+0;
dx[0] = (ex38s2_P->s3_Internal_B)*ex38s2_B->root_Sum1;
dx[0] += (ex38s2_P->s3_Internal_A[0])*ex38s2_X->s3_Internal[0]+(ex38s2_P->s3_Internal_A[1])*ex38s2_X->s3_Internal[1];
dx[1] = (ex38s2_P->s3_Internal_A[2])*ex38s2_X->s3_Internal[0];
}
}
/* Compute model zero crossings */
#define MDL_ZERO_CROSSINGS
static void mdlZeroCrossings(SimStruct *S)
{
/* simstruct variables */
ex38s2_BlockIO *ex38s2_B = (ex38s2_BlockIO *) _ssGetBlockIO(S);
ex38s2_Parameters *ex38s2_P = (ex38s2_Parameters *) ssGetDefaultParam(S);
ex38s2_NonsampledZCs *ex38s2_NonsampledZC = (ex38s2_NonsampledZCs *) ssGetNonsampledZCs(S);
/* Abs Block: <Root>/Abs */
ex38s2_NonsampledZC->root_Abs = ex38s2_B->root_Gain;
/* RelationalOperator Block: <Root>/Relational Operator */
ex38s2_NonsampledZC->root_Relational_Operator = ex38s2_B->root_Sum2 - ex38s2_B->root_Constant;
/* Saturate Block: <S2>/Saturation */
/* Do zero crossings for the upper limit */
ex38s2_NonsampledZC->s2_Saturation[0] = ex38s2_B->s2_Gain -
(ex38s2_P->s2_Saturation_UpperSat);
/* Do zero crossings for the lower limit */
ex38s2_NonsampledZC->s2_Saturation[1] = ex38s2_B->s2_Gain -
(ex38s2_P->s2_Saturation_LowerSat);
/* Saturate Block: <S2>/Saturation1 */
/* Do zero crossings for the upper limit */
ex38s2_NonsampledZC->s2_Saturation1[0] = ex38s2_B->s2_Gain1 -
(ex38s2_P->s2_Saturation1_UpperSat);
/* Do zero crossings for the lower limit */
ex38s2_NonsampledZC->s2_Saturation1[1] = ex38s2_B->s2_Gain1 -
(ex38s2_P->s2_Saturation1_LowerSat);
}
/* End of Functions in model "ex38s2_acc" */
#include "ex38s2_acc_reg.h"
/* [EOF] ex38s2_acc.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -