主要内容

通过使用原子子图创建可重复使用的子组件

一个atomic subchartis a graphical object that helps you to create independent subcomponents in a Stateflow®chart. Atomic subcharts are not supported in standalone Stateflow charts in MATLAB®

原子子图允许:

  • 在多个图表和模型中重复使用同一状态或子图

  • Faster simulation after making small changes to a chart with many states or levels of hierarchy

  • Ease of team development when multiple people are working on different parts of the same chart

  • 手动检查图表中特定状态或子图的生成代码

一个atomic subchart looks opaque and includes the label原子在左上角。If you use a linked atomic subchart from a library, the label关联appears in the upper-left corner.

Example of an Atomic Subchart

此示例说明了正常子图和原子子图之间的差异。

In the Air Controller chart,PowerOff是一个普通的子图。打开是一个原子次子图。这两个子图看起来都不透明,但是打开包括标签原子on the upper-left corner.

使用原子子图的好处

原子subcharts combine the functionality ofstates,,,,正常子图, 和原子子系统(金宝appSimulink)。原子科:

  • 作为独立图表的行为。

  • Support usage as library links.

  • Support the generation of reusable code.

  • 允许映射输入,输出,参数,数据存储内存和输入事件。

Atomic子图不支持访问:金宝app

  • 数据在图表层次结构的每个级别。

  • Event broadcasts outside the scope of the atomic subchart.

原子subcharts do not support explicit specification of sample time.

创建一个原子子图

您可以通过转换现有状态或子图或链接图书馆模型的图表来创建原子子图。创建原子子图之后,通过右键单击原子子图并选择变量的映射子图Mappings。有关更多信息,请参阅Map Variables for Atomic Subcharts and Boxes

Convert a State or Normal Subchart to an Atomic Subchart

To create an independent component that allows for faster debugging and code generation workflows, convert an existing state or subchart into an atomic subchart. In your chart, right-click a state or a normal subchart and select组织p & Subchart>原子子图。The label原子出现在子图的左上角。

新的原子子图具有图表中子图中访问的每个数据对象的副本。本地数据被复制为数据存储存储器。其他数据的范围,包括输入和输出数据,不会改变。

将状态或子图转换为Atomic子图,可以自动将任何超级转移替换为状态或子图,并通过连接到条目或出口端口的过渡。进入和退出端口使您的图表能够在状态流层次结构中的边界过渡,同时隔离输入和退出原子子图的逻辑。有关更多信息,请参阅Create Entry and Exit Connections Across State BoundariesIsolate the Transition Logic for Entering and Exiting an Atomic Subchart

For a list of issues that can prevent you from converting a state or subchart to an atomic subchart, seeRestrictions for Converting to Atomic Subcharts

链接从图书馆

要创建一个子组件以跨多个图表和模型重复使用,请从库模型创建链接。在库模型中复制图表,并将其粘贴到另一个模型中的图表。如果库图包含任何状态,则将其作为标签的链接原子子图关联在左上角。

This modeling method minimizes maintenance of similar states. When you modify the atomic subchart in the library, your changes propagate to the links in all charts and models.

如果库图仅包含函数,没有状态,则在图表中出现一个链接的原子框。有关更多信息,请参阅重用功能通过使用原子盒子

Convert an Atomic Subchart to a Normal Subchart

Converting an atomic subchart back to a state or a normal subchart removes all of its variable mappings. The conversion merges subchart-parented data objects with the chart-parented data to which they map.

  1. 如果原子子图是一个库链接,请右键单击原子子图,然后选择库链接>Disable Link

  2. 要将原子子图转换回正常的子图,请右键单击原子次数并清除该子图组织p & Subchart>原子子图复选框。

  3. 要将子图转换回一个状态,请右键单击子图并清除组织p & Subchart>子图复选框。

  4. 如有必要,将图表中的图形对象重新排列。

如果:

  • 原子子图将参数映射到单个变量名称以外的表达式。例如,映射参数数据1to one of these expressions prevents the conversion of an atomic subchart to a normal subchart:

    • 3

    • data2(3)

    • Data2 + 3

  • both of these conditions are true:

    • The atomic subchart contains MATLAB functions or truth table functions that use MATLAB as the action language.

    • The atomic subchart does not map each variable to a variable of the same name in the main chart.

When to Use Atomic Subcharts

Reuse State Logic

假设您想多次重复使用相同的状态或子图以促进大规模建模。

If you do not use atomic subcharts, you have to maintain each copy of a subcomponent manually. For example, this chart contains two states with a similar structure. The only difference between the two states is the names of variables. If you change the logic in state一个,,,,then you must make the same change in stateb

To enable reuse of subcomponents by using linked atomic subcharts, create a single copy of state一个并将其作为图表存储在库模型中。从该库中,在图表中两次复制并粘贴原子子图。然后根据需要更新子图变量的映射。

当您更改库中的原子子图时,更改将传播到所有库链接。有关更多信息,请参阅Reuse a State Multiple Times in a Chart

Debug Charts Incrementally

Suppose that you want to test a sequence of changes in a chart that contains many states or several levels of hierarchy.

如果您不使用原子子图,则在对图表的一个部分进行小更改并开始模拟时,整个图表都会发生重新编译。因为重新编译整个图表可能需要很长时间,所以您决定在测试之前进行几次更改。但是,如果发现错误,则必须逐步介绍所有更改以识别错误的原因。

相比之下,当您修改原子子图时,仅对子图而不是整个图表进行重新编译。仿真的增量构建需要更少的时间重新编译。汇编时间的减少使您能够测试每个单独的更改,而不是一次等待一次测试多个更改。通过单独测试每个更改,您可以快速识别导致错误的更改。有关更多信息,请参阅Reduce the Compilation Time of a Chart

开发多个人使用的图表

假设您想将图表分解为子组件,因为多个人正在研究图表的不同部分。

没有原子次数,一次只有一个人可以编辑模型。如果有人在图表的一部分进行编辑时,而其他人编辑了同一图表的另一部分,则必须在提交时间合并这些更改。

相比之下,您可以将图表的不同部分存储为链接的原子子图。由于原子子图作为独立对象的行为,因此不同的人可以在图表的不同部分工作,而不会影响图表的其他部分。在提交时间,由于更改存在于单独的模型中,因此无需合并。有关更多信息,请参阅Divide a Chart into Separate Units

检查生成的代码

假设您要检查由金宝app®Coder™或嵌入式编码器®手动用于图表的特定部分。

If you do not use atomic subcharts, you generate code for an entire model in one file. To find code for a specific part of the chart, you have to look through the entire file.

In contrast, you can specify that the code for an atomic subchart appears in a separate file. This method of code generation enables unit testing for a specific part of a chart. You avoid searching through unrelated code and focus only on the code that interests you. For more information, see为原子子图生成单独的代码

也可以看看

(金宝appSimulink)

相关话题