📄 estimatepaths.c
字号:
/*
* estimatepaths.c: Basic 'C' template for a level 2 S-function.
* x(n+1)=u(n)
* y(n) =f(x(n),u(n))
* Copyright 2008.4.28 vincent.
* $Revision: 0.1
*/
#define S_FUNCTION_NAME estimatepaths
#define S_FUNCTION_LEVEL 2
#include "simstruc.h"
#include <stdlib.h>
/*--------------------------------------------------------------*/
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 0); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/* Return if number of expected != number of actual parameters */
return;
}
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 1);
if (!ssSetNumInputPorts(S, 2)) return;
ssSetInputPortWidth(S, 0, 1);
ssSetInputPortDirectFeedThrough(S, 0, 0);
ssSetInputPortWidth(S, 1, 1);
ssSetInputPortDirectFeedThrough(S, 1, 1);
if (!ssSetNumOutputPorts(S, 2)) return;
ssSetOutputPortWidth(S, 0, 1);
ssSetOutputPortWidth(S, 1, 1);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 2);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE);
}
/*----------------------------------------------------------*/
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
/*-----------------------------------------------------------*/
#define MDL_INITIALIZE_CONDITIONS
/* Function: mdlInitializeConditions ========================================
* Abstract:
* Initialize both discrete states to one.
*/
static void mdlInitializeConditions(SimStruct *S)
{
real_T *x = ssGetRealDiscStates(S);
*x =0.0;
}
/*----------------------------------------------------------------*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
real_T teamp_v;
real_T teamp_u;
real_T teamp;
real_T *y_0 = ssGetOutputPortRealSignal(S,0);
real_T *y_1 = ssGetOutputPortRealSignal(S,1);
real_T *x = ssGetRealDiscStates(S);
InputRealPtrsType vPtrs = ssGetInputPortRealSignalPtrs(S,0);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,1);
UNUSED_ARG(tid);
teamp = *x;
teamp_v = *vPtrs[0];
teamp_u = *uPtrs[0];
if((teamp_v>0.0)&&((teamp_v-teamp_u)>=-1)&&((teamp_v-teamp_u)<=1))
{
*y_0= teamp_v;
*y_1= teamp_u;
}
else
{
*y_0= 0.0;
*y_1= 0.0;
}
}
/*--------------------------------------------------------*/
#define MDL_UPDATE /* Change to #undef to remove function */
#if defined(MDL_UPDATE)
static void mdlUpdate(SimStruct *S, int_T tid)
{
real_T *x = ssGetRealDiscStates(S);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,1);
UNUSED_ARG(tid);
*x=*uPtrs[0];
}
#endif /* MDL_UPDATE */
/*----------------------------------------------------------------------------------*/
#undef MDL_DERIVATIVES /* Change to #undef to remove function */
#if defined(MDL_DERIVATIVES)
/* Function: mdlDerivatives =================================================
* Abstract:
* In this function, you compute the S-function block's derivatives.
* The derivatives are placed in the derivative vector, ssGetdX(S).
*/
static void mdlDerivatives(SimStruct *S)
{
}
#endif /* MDL_DERIVATIVES */
/* Function: mdlTerminate =====================================================
*/
static void mdlTerminate(SimStruct *S)
{
}
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration function */
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -