主要内容

Schedule Execution of Multiple Controllers

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.

Goal of the Tutorial

本教程的目的是在状态流图中使用simulink函数来改善名为的模型的设计金宝appsf_temporal_logic_scheduler.

理由改善模式l Design

Thesf_temporal_logic_schedulermodel 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.

Edit a Model to Use金宝appFunctions

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_schedulermodel. If you simulate the model, you see this result in the scope.

For more information, seeSchedule Subsystems to Execute at Specific Times.

Add金宝appFunctions to the Chart

请按照以下步骤将Simulink函数添加到时间逻辑调金宝app度程序图表中。

  1. In the Simulink model, right-click the A1 block in the lower right corner and selectCutfrom the context menu.

  2. Open the Temporal Logic Scheduler chart.

  3. In the chart, right-click outside any states and selectPastefrom the context menu.

  4. 扩展新的simulink函数,金宝app使签名适合在功能框内。

    Tip

    To change the font size of a function, right-click the function box and select a new size from theFont Sizemenu.

  5. Rename the Simulink function fromA1tof1by enteringy = f1(u)in the function box.

  6. 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 statesfastschedulerSlowSchedulerrequire access to the function outputs.

Change the Scope of Chart Data

In the Model Explorer, change the scope of chart-level dataytoLocal因为该数据的计算现在发生在图表内。

Update State Actions in the Chart

In the Stateflow Editor, you can replace event broadcasts in state actions with function calls.

  1. Edit the state actions infastschedulerSlowScheduler调用simulink函数金宝appf1,f2, 和f3.

  2. In both states, update eachduringaction as follows.

    du: y = u1-y2;

Add Data to the Chart

For theon everystate actions offastschedulerSlowScheduler, define three data. (For details, see添加状态流数据

  1. Add local datay1y2到图表。

  2. Add output datay3到图表。

  3. In the model, connect the output fory3to the scope.

    Tip

    翻转Scope块,选择块。然后,在工具条中,在格式tab, clickFlip left-right翻转左右按钮.

Remove Unused Items in the Model

  1. 在模型资源管理器中,删除输出事件A1,A2, 和A3和input datau2because the function-call subsystems no longer exist.

  2. 删除模型中的任何虚线信号线。

Run the New Model

Your new model looks something like this:

如果模拟新型号,则结果与原始设计的结果匹配。

相关话题