Main Content

创建测试安全带以生成功能调用

After you create a model component to initialize, reset, and terminate the state of blocks (see使用初始化,重置和终止功能), you can place the model in a simulation test harness. A test harness is a Simulink®您用于开发,测试和调试模型组件的模型。

要创建测试线束,请参考新模型中包含模型组件的导出功能模型,然后添加状态流®图表以建模功能通话事件调度程序。

Reference the Export-Function Model

导出功能模型包含用于测试的模型组件。要创建导出函数模型,请参阅Create an Export-Function Model

  1. Create a Simulink model. Save this model with the nametest_model

  2. Set configuration parameters for solverType固定步骤,求解器auto,,,,and固定步骤的大小1

  3. 添加aModel堵塞。打开“块参数”对话框。在里面Model nametext box, enter the name of your export-function model. In this example, enterModel02

  4. 通过将功能通用发电机块连接到该引用的模型组件港口。连接Constant块到达信号入门port and a范围块到达发出信号港口。

  5. 运行仿真以验证您的模型从父模型正确模拟。当模型在没有功能通话事件端口的情况下进行模拟时,初始化Function块在模拟的开头执行终止功能块在模拟末尾执行。

  6. Expose function-call input ports on the model block. Right-click theModel块并选择Block Parameters。在“块参数”对话框中,选择显示模型初始化端口,,,,显示模型重置端口,,,,and显示模型终止端口复选框。

  7. Delete the函数通话发生器通过按下来阻止和更新模型CTR-D

    当您激活初始化函数通话输入端口时Model块,该模型必须在初始化port before it can execute. The reception of a function call triggers the execution of the default model initialize routine, and then the execution of the初始化Function块内容。

    The reception of a function call on theReset端口触发重置功能块内容的执行。

    The reception of a function call on the终止端口触发执行终止功能阻止内容,然后执行默认模型终止例程。然后该模型停止运行。要再次执行模型,您必须通过将功能通话事件发送到初始化港口。

Model an Event Scheduler

使用状态流图为事件时间表建模并生成初始化和终止功能呼叫信号。

  1. 添加状态流图。单击模型图并开始键入图表。从搜索列表中选择

  2. Open the chart and add two state blocks, one above the other.

  3. 添加默认过渡并将其连接到顶部状态块。编辑标签:

    {step = 0}
  4. 添加从顶部块到底部块的过渡。编辑标签:

    [step == 2]/{initialize}

  5. 添加从底部块然后返回到底部块的过渡。编辑标签:

    [step == 5]/{reset}

  6. 添加a transition from the bottom block to top block. Edit the label:

    [step == 9]/{Terminate}

  7. 编辑顶部块的内容:

    非活动条目:步骤=步骤 + 1;在:步骤=步骤 + 1;

  8. 编辑底部块的内容:

    运行条目:步骤=步骤 + 1;跑;在:步骤=步骤 + 1;跑;

将图表连接到测试模型

在图表上创建功能通话输出端口,以控制和运行模型组件。

  1. Open Model Explorer. On the造型标签和从设计部分,选择Model Workspace。。

  2. Create index variable. From the menu, select添加>Data。在数据对话框中,输入for the姓名

  3. 创建功能通话输出端口。对于您创建的每个函数呼叫事件,选择添加>事件在事件对话框中,输入并选择以下值。

    输入事件文本框 Set Scope Set Trigger
    初始化 输出以模拟金宝app 功能调用
    Reset 输出以模拟金宝app 功能调用
    终止 输出以模拟金宝app 功能调用
    输出以模拟金宝app 功能调用

  4. 导航到模型的最高级别。连接初始化,,,,Reset,,,,终止,,,,and图表上的端口初始化,,,,reset,,,,terminate,,,,and输入端口Model堵塞。

  5. 运行模拟。

    模型不能执行,直到第二次step, when the block state is initialized to 4. At the fifth time step, a reset function call to the reset port triggers the重置功能块要执行。在第九次步骤中,子系统停止执行,并且块状态保持恒定。

    如果模型在初始化函数调用之前接收一个函数调用以运行,则会发生仿真错误。

也可以看看

Blocks

Related Topics