Main Content

mdlInitializeSampleTimes

指定此C MEX函数运行的样本率

Required

是的

语言

C,C ++

句法

void mdlInitializeSampleTimes(SimStruct *S)

参数

s

代表S功能块的SIMSTRUCT。

描述

This method should specify the sample time and offset time for each sample rate at which this S-function operates via the following paired macros

sssetsampletime(s,sampletime index,sample_time)sssetOffsetTime(s,offsetTimeIndex,offset_time)

在哪里SampleTimeIndex0比在指定的样本时间数量的数量少于mdlInitializeSizes通过sssetnumsampletimes

如果S功能以一个或多个样本率运行,则此方法可以指定给定样本时间的以下任何样本时间和偏移值:

  • [连续_sample_time,0.0]

  • [连续_sample_time,fixed_in_minor_step_offset]

  • [discrete_sample_period, offset]

  • [VARIABLE_SAMPLE_TIME, 0.0]

大写值是定义的宏sl_sample_time_defs.h

If the S-function operates at one rate, this method can alternatively set the sample time to one of the following sample/offset time pairs.

  • [sentarited_sample_time,0.0]

  • [sarenited_sample_time,fixed_in_minor_step_offset]

如果样本时间为0,则Simulink万博1manbetx®引擎假设S功能从其连接到的块中继承其样品时间,即样品时间为

[sentarited_sample_time,0.0]

This method can therefore return without doing anything.

指定样本时间时,请使用以下准则。

  • 在次要集成步骤中发生变化的连续函数应将样本时间设置为

    [连续_sample_time,0.0]
  • 在次要集成步骤中不变的连续函数应将样本时间设置为

    [连续_sample_time,fixed_in_minor_step_offset]
  • 以指定速率更改的离散函数应将样本时间设置为

    [discrete_sample_period, offset]

    在哪里

    iNCETE_SAMPLE_PERIOD> 0.0

    and

    0.0 <= offset 
                    
  • A discrete function that changes at a variable rate should set the sample time to

    [VARIABLE_SAMPLE_TIME, 0.0]

    Simu万博1manbetxlink引擎调用mdlGetTimeOfNextVarHit函数以获取可变步骤离散任务的下一个示例点击的时间。

    注意variable_sample_timerequires a variable-step solver.

  • 要在触发的子系统或周期系统中正确操作,离散的s功能应

    • 指定单个示例时间设置为

      [sentarited_sample_time,0.0]
    • 利用ssSetOptions设置ss_option_disallow_constant_sample_time仿真选项INmdlInitializeSizes

    • 确认它被分配一个离散或triggered sample time inmdlsetworkwidths

      如果(ssgetSampletime(s,0)==连续_sample_time){sssetErrorStatus(s,“该块不能分配一个连续的示例时间”);}

    在整个框图中传播样品时间之后,引擎分配了样品时间

    [INHERITED_SAMPLE_TIME, INHERITED_SAMPLE_TIME]

    驻留在触发子系统中的离散块。

If this function has no intrinsic sample time, it should set its sample time to inherited according to the following guidelines:

  • 随着输入的变化的变化函数,即使在次要集成步骤中,也应将其样本时间设置为

    [sentarited_sample_time,0.0]

    随着输入的变化而变化但在次要集成步骤(即在次要步骤中保存)时不会改变的功能,应将其样本时间设置为

    [sarenited_sample_time,fixed_in_minor_step_offset]

S功能应使用ssissampleshitorssiscontinousTaskmacros to check for a sample hit during execution (inmdlOutputsormdlupdate)。例如,如果块的第一个示例时间是连续的,则该函数可以使用以下代码片段检查示例点击。

if (ssIsContinuousTask(S,tid)) { }

笔记

如果使用使用,该功能会收到不正确的结果ssissampleshit(S,0,tid)

如果该函数要确定第三(离散)任务是否有命中,则可以使用以下代码片段。

if (ssIsSampleHit(S,2,tid) { }

笔记

If you have万博1manbetxSimulink编码器™,当生成包含此方法的非线s函数的代码时,请确保该方法未包装在一个#如果定义(matlab_mex_file)statement. For example:

#如果定义(matlab_mex_file)static void mdlInitializeSampleTimes(SimStruct *S) { /* Add mdlInitializeSampleTimes code here * } #endif

define声明使得mdlInitializeSampleTimesmethod available only to a MATLAB®MEX文件。如果未嵌入s功能,万博1manbetxSimulink编码器product cannot use this method, resulting in link or run-time errors.

版本历史记录

Introduced before R2006a