A Simulink®function is a graphical object that you fill with Simulink blocks and call in the actions of states and transitions. Simulink functions are not supported in standalone Stateflow®charts in MATLAB®. For more information, seeReuse Simulink Functions in Stateflow Charts.
本教程的目的是在状态流图中使用simulink函数来改善名为的模型的设计金宝appsf_temporal_logic_scheduler
.
Thesf_temporal_logic_scheduler
model contains a Stateflow chart and three function-call subsystems. These blocks interact as follows:
图表广播输出事件A1
,A2
, 和A3
触发功能通话子系统。
子系统A1,A2, 和A3execute at different rates defined by the chart.
子系统输出直接输入图表。
No other blocks in the model access the subsystem outputs.
You can replace function-call subsystems with Simulink functions inside a chart when:
子系统执行图表所需的计算。
Other blocks in the model do not need access to the subsystem outputs.
The sections that follow describe how to replace function-call subsystem blocks in a Simulink model with Simulink functions in a Stateflow chart. This procedure reduces the number of objects in the model while retaining the same simulation results.
Step | 任务 | Reference |
---|---|---|
1 | Open the model. | 打开模型 |
2 | Move the contents of the function-call subsystems into Simulink functions in the chart. | Add Simulink Functions to the Chart |
3 | Change the scope of specific chart-level data toLocal . |
Change the Scope of Chart Data |
4 | Replace event broadcasts with function calls. | Update State Actions in the Chart |
5 | 验证该函数输入和输出已定义。 | Add Data to the Chart |
6 | Remove unused items in the model. | Remove Unused Items in the Model |
Note
To skip the conversion steps, you can access the新模式directly.
Open thesf_temporal_logic_scheduler
model. If you simulate the model, you see this result in the scope.
For more information, seeSchedule Subsystems to Execute at Specific Times.
请按照以下步骤将Simulink函数添加到时间逻辑调金宝app度程序图表中。
In the Simulink model, right-click the A1 block in the lower right corner and selectCutfrom the context menu.
Open the Temporal Logic Scheduler chart.
In the chart, right-click outside any states and selectPastefrom the context menu.
扩展新的simulink函数,金宝app使签名适合在功能框内。
Tip
To change the font size of a function, right-click the function box and select a new size from theFont Sizemenu.
Rename the Simulink function fromA1
tof1
by enteringy = f1(u)
in the function box.
Repeat steps 1 through 5 for these cases:
Copying the contents ofA2into a Simulink function namedf2
.
Copying the contents ofA3into a Simulink function namedf3
.
Note
The new functions reside at the chart level because both statesfastscheduler
和SlowScheduler
require access to the function outputs.
In the Model Explorer, change the scope of chart-level datay
toLocal
因为该数据的计算现在发生在图表内。
In the Stateflow Editor, you can replace event broadcasts in state actions with function calls.
Edit the state actions infastscheduler
和SlowScheduler
调用simulink函数金宝appf1
,f2
, 和f3
.
In both states, update eachduring
action as follows.
du: y = u1-y2;
For theon every
state actions offastscheduler
和SlowScheduler
, define three data. (For details, see添加状态流数据)
Add local datay1
和y2
到图表。
Add output datay3
到图表。
In the model, connect the output fory3
to the scope.
Tip
翻转Scope块,选择块。然后,在工具条中,在格式tab, clickFlip left-right.
在模型资源管理器中,删除输出事件A1
,A2
, 和A3
和input datau2
because the function-call subsystems no longer exist.
删除模型中的任何虚线信号线。
Your new model looks something like this:
如果模拟新型号,则结果与原始设计的结果匹配。