Error in S-function MDL_Derivatives
3 views (last 30 days)
I'm creating a model using example mex file csfunc.c as a starting example. When I compile & execute I get a fatal error in MDL_Derivatives at time= 0. For this code as a test I'm using the input U(0) in one of the derivatives. This throws an error. If I delete the reference to U(0) and just leave the additions of 1E-3 the model works.
At the beginning of the S-Functiion I do have the define: #define U(element) (*uPtrs[element])
What could cause this fatal fault?
I also have the input port delclared as a feedthrough, with
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 3);
ssSetInputPortDirectFeedThrough(S, 0, 1);
#define MDL_DERIVATIVES /* Change to #undef to remove function */
/* Function: mdlDerivatives =================================================
* 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)
real_T *dx = ssGetdX(S);
real_T *x = ssGetContStates(S);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
/* xdot= f(x,u) */
dx= 1E-3 + U(0);
#endif /* MDL_DERIVATIVES *
Any help on this is greatly appreciated!