User-defined sample time in s-function

3 ビュー (過去 30 日間)
jpro89
jpro89 2017 年 3 月 2 日
回答済み: Jose Lara 2017 年 3 月 8 日
I am trying to set the sample time using the value of an input to the s-function. My code looks as follows:
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, 1e-5);
ssSetOffsetTime(S, 0, 0.0);
}
I would like instead to do the following:
static void mdlInitializeSampleTimes(SimStruct *S)
{
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
ssSetSampleTime(S, 0, *uPtrs[1]);
ssSetOffsetTime(S, 0, 0.0);
}
However, this does not work at all. I have looked at the simulink examples and the closest thing I found is getting the sample time from the defined parameters in the s-function (which is not exactly what I am looking for). Has anybody tried something similar?

採用された回答

Jose Lara
Jose Lara 2017 年 3 月 8 日
This is actually not possible. According to the C MEX S-Function documentation, "mdlInitializeSampleTimes" is only computed once, before the simulation loop. You can only access port signal values during the simulation loop, therefore the function "ssGetInputPortRealSignals" cannot be used in "mdlInitializeSampleTimes".
Check out the Simulink Engine Interaction with C S-Functions documentation for more information regarding the process.
Another option you have is to access the sample time of an Input port or inherit the sample time from as shown below:
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime( S, 0, INHERITED_SAMPLE_TIME );
ssSetOffsetTime( S, 0, 0 );
ssSetModelReferenceSampleTimeDefaultInheritance(S);
}

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by