创建测试安全带以生成功能调用
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。
Create a Simulink model. Save this model with the name
test_model
。Set configuration parameters for solverType至
固定步骤
,求解器auto
,,,,and固定步骤的大小至1
。添加aModel堵塞。打开“块参数”对话框。在里面Model nametext box, enter the name of your export-function model. In this example, enter
Model02
。通过将功能通用发电机块连接到该引用的模型组件
跑
港口。连接Constant块到达信号入门
port and a范围块到达发出信号
港口。运行仿真以验证您的模型从父模型正确模拟。当模型在没有功能通话事件端口的情况下进行模拟时,初始化Function块在模拟的开头执行终止功能块在模拟末尾执行。
Expose function-call input ports on the model block. Right-click theModel块并选择Block Parameters。在“块参数”对话框中,选择显示模型初始化端口,,,,显示模型重置端口,,,,and显示模型终止端口复选框。
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 the
Reset
端口触发重置功能块内容的执行。The reception of a function call on the
终止
端口触发执行终止功能阻止内容,然后执行默认模型终止例程。然后该模型停止运行。要再次执行模型,您必须通过将功能通话事件发送到初始化
港口。
Model an Event Scheduler
使用状态流图为事件时间表建模并生成初始化和终止功能呼叫信号。
添加状态流图。单击模型图并开始键入
图表
。从搜索列表中选择。
Open the chart and add two state blocks, one above the other.
添加默认过渡并将其连接到顶部状态块。编辑标签:
{step = 0}
添加从顶部块到底部块的过渡。编辑标签:
[step == 2]/{initialize}
添加从底部块然后返回到底部块的过渡。编辑标签:
[step == 5]/{reset}
添加a transition from the bottom block to top block. Edit the label:
[step == 9]/{Terminate}
编辑顶部块的内容:
非活动条目:步骤=步骤 + 1;在:步骤=步骤 + 1;
编辑底部块的内容:
运行条目:步骤=步骤 + 1;跑;在:步骤=步骤 + 1;跑;
将图表连接到测试模型
在图表上创建功能通话输出端口,以控制和运行模型组件。
Open Model Explorer. On the造型标签和从设计部分,选择Model Workspace
。。
Create index variable. From the menu, select添加>Data。在数据对话框中,输入
步
for the姓名。创建功能通话输出端口。对于您创建的每个函数呼叫事件,选择添加>事件在事件对话框中,输入并选择以下值。
输入事件文本框 Set Scope Set Trigger 初始化
输出以模拟金宝app
功能调用
Reset
输出以模拟金宝app
功能调用
终止
输出以模拟金宝app
功能调用
跑
输出以模拟金宝app
功能调用
导航到模型的最高级别。连接
初始化
,,,,Reset
,,,,终止
,,,,and跑
图表上的端口初始化
,,,,reset
,,,,terminate
,,,,and跑
输入端口Model堵塞。运行模拟。
模型不能执行,直到第二次step, when the block state is initialized to 4. At the fifth time step, a reset function call to the reset port triggers the重置功能块要执行。在第九次步骤中,子系统停止执行,并且块状态保持恒定。
如果模型在初始化函数调用之前接收一个函数调用以运行,则会发生仿真错误。