필터 지우기
필터 지우기

Error in S-function MDL_Derivatives

조회 수: 1 (최근 30일)
Brian Tremaine
Brian Tremaine 2020년 11월 19일
댓글: Brian Tremaine 2020년 11월 20일
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
Brian Tremaine
Brian Tremaine 2020년 11월 20일
I seemed to have fixed it by adding the line ssSetInputPortRequiredContiguous(S, 0, 0) to mdlInitializeSizes. The line was added after the setting up the inputs,
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 5); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/* Return if number of expected != number of actual parameters */
return;
}
ssSetNumContStates(S, NUMSTATES); // ia,ib,ic,wrad,theta
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 3);
ssSetInputPortDirectFeedThrough(S, 0, 1);
/*
* Set direct feedthrough flag (1=yes, 0=no).
* A port has direct feedthrough if the input is used in either
* the mdlOutputs or mdlGetTimeOfNextVarHit functions.
*/
ssSetInputPortRequiredContiguous(S, 0, 0);

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by