Error in S-function MDL_Derivatives
Show older comments
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;
end
ssSetInputPortWidth(S, 0, 3);
ssSetInputPortDirectFeedThrough(S, 0, 1);
#define 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)
{
real_T *dx = ssGetdX(S);
real_T *x = ssGetContStates(S);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
/* xdot= f(x,u) */
dx[0]= 1E-3 + U(0);
dx[1]= 1E-3;
dx[2]= 1E-3;
dx[3]= 1E-3;
dx[4]= 1E-3;
}
#endif /* MDL_DERIVATIVES *
Any help on this is greatly appreciated!
1 Comment
Brian Tremaine
on 20 Nov 2020
Answers (0)
Categories
Find more on User-Defined Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!