Main Content

Mask Atomic Subcharts and Boxes in Stateflow

An atomic subchart is a graphical object that you can use to create independent subcomponents in a Stateflow® chart. Charts in a library can be masked. Copying a masked chart from a library into a Stateflow chart creates a linked atomic subchart that retains the mask and the mask features. For more information about creating or using linked atomic subcharts, see Create Reusable Subcomponents by Using Atomic Subcharts.

An atomic box is a graphical object that helps you encapsulate graphical, truth table, MATLAB®, and Simulink® functions in a separate namespace. For more information about atomic boxes, see Reuse Functions by Using Atomic Boxes.

Using masks with linked atomic subcharts or boxes allows you to control the parameters for various inputs and outputs to your system at the chart level. Masking is helpful for systems that incorporate reusable components, because you can customize parameters to fit distinct use cases. You can create an interface for each instance of a linked atomic subchart, and configure each component to meet the needs of applications in the system. This adaptability allows you to reuse components and fine-tune the behavior of each instance of the subchart.

Masking an Atomic Subchart

In this example, you create a masked atomic subchart that represents a control system that warns you if the engine overheats. The subchart contains three states. By default, the chart starts in state NORM. If the engine temperature rises above 190 degrees, WARN becomes the active state. If the temperature rises above 225 degrees, ALARM becomes the active state. If the temperature lowers to a point equal or below these cutoff temperatures, the previous state becomes the active state again.

atomic_subchart.png

In this chart, temp is the parameter, and y is the output data.

Create a Masked Atomic Subchart

To open the library, at the command prompt type:

openExample('stateflow/EngineTemperatureMaskingExample')

First unlock the library, and select the chart. In the State Chart tab, click the Create Mask button. The mask editor appears. For more information about the mask editor capabilites, see Mask Editor Overview (Simulink).

In the Controls pane, use the Edit button and add one parameter for the temperature. After you add the parameter, you can edit the prompt and the name.

Temperature parameter added to the mask dialog.

The Prompt column shows the text that appears in the block dialog for the block mask. The Name column is the name of the parameter data.

Click the Save Mask button and close the mask editor. In the library, the block icon includes a gray arrow in the lower-left side. This arrow indicates that there is a mask on the chart.

Masked atomic subchart.

Create a Model with a Masked Atomic Subchart

To add this masked chart as an atomic subchart to your Simulink model:

  1. Open a new Stateflow chart.

  2. Set the chart decomposition to parallel.

  3. Copy the library chart to the Stateflow canvas three times.

Three masked atomic subcharts.

In the Symbols pane, create three outputs for the Stateflow chart and name them y1, y2, and y3. In the Property Inspector, specify the size as 1 and the type as double for each output.

To update the temperature parameter for each instance of the chart, double-click the atomic subchart. The Block Parameter window appears. In the Parameters tab, you can update the engine temperature.

Temperature parameter input.

Set the temperature for CarTemp to be 150, set CarTemp1 to 191, and set CarTemp2 to 275.

In the Mappings tab for each atomic subchart, map the CarTemp output y to y1 in the main chart, map the CarTemp1 output y to y2 in the main chart, and map the CarTemp2 output y to y3 in the main chart. Mapping your output data ensures that each atomic subchart has its own signal to the Scope block.

Output mapping dialog.

In the Simulink canvas, connect each output to a Scope block. In the block, select View > Layout and select three columns.

View the Results

After running the model, open the Scope block.

Results of running the model.

The Scope block shows that for the first atomic subchart, NORM is the only active state because the temperature is low. For the second atomic subchart, the active state moved to WARN. In the third subchart, the high temperature caused the chart to enter the ALARM state.

Add an Icon to the Mask

To customize the appearance of the atomic subchart mask icon, you can draw an icon using the Graphical Mode tab or load a DVG image. For more information, see Graphical Icon Editor Overview (Simulink). To load an icon image to your mask, right-click the masked library chart and select Mask > Add Icon Image.

Note

For a masked atomic subchart, you can only upload a DVG image or draw an icon in Graphical mode.

Limitations

Masked atomic subcharts do not support:

  • Self-modifiable masks.

  • Drawing Commands tab.

  • Undo or redo in the Mask Dialog.

Related Topics