Breaking up a Stateflow Chart for Collaborative Development 2

Posted by Guy Rouleau,

This week I have been experimenting with a feature released in R2010b that I have not used before: Stateflow Atomic Subcharts

The Problem

I am currently working on a model architecture where different functionalities will be developed by different people simultaneously.

Typically, when I need to componentize a Simulink model, I use Model Referencing and Block Libraries. However, for my application, the algorithms to be developed are very procedural and better suited for Stateflow.

While going through the Stateflow documentation, I ran into a page titled When to Use Atomic Subcharts and saw the following scenario:

You want to break a chart into standalone parts because multiple people are working on different parts of the chart.

That sounds exactly like what I am looking for... so let's give that a try!

Initial Design

Let's start with a simple example chart:

Simple chart

In this chart, I have 3 sub-states for 3 different tasks. At a high level, I know that TaskA will be followed by TaskB, who is followed by TaskC. Each of these tasks are pretty complex and will developed by different engineers.

So let's see how we can store states TaskA, TaskB and TaskC in different files.

Atomic Subcharts

If I right-click on the states, I can select Make Content -> Atomic Subcharted.

Simple chart

and the content of the state becomes atomic

Simple Atomic Subchart


One File Per Atomic Subchart

The next step is to store the state in a library. To do this, I copy the Atomic Subchart to a Simulink Library and recopy it back to the chart. Notice that the annotation on the state changes from Atomic to Link:

Storing an Atomic chart in a library


and that's it... I now have a Stateflow chart with different states stored in different files.

Data Mapping

Now we have one more step to go. To use an Atomic Subchart, you need to map the data internal to the subchart to the main chart data. To accomplish this task, right-click on the chart and select Edit Subchart mappings...

Opening Subchart Mapping


This will launch a dialog containing tables to map inputs, outputs, data store memory, parameters and input events.

subchart mapping


Now it's your turn

Do you componentize Stateflow using Atomic Subcharts? Leave us a comment here.

2 CommentsOldest to Newest

Paul replied on : 1 of 2

In the past, I’ve had issues with charts growing so large that it makes readability poor. This also looks like a good solution for even solo project when people want to break up a large chart (divide and conquer).

john replied on : 2 of 2

We make extensive use of this feature to enable unit testing of the atomic charts. They can be easily built into test harnesses and tested on every check-in. There are some things you have to learn about mapping and you will wind up with many more variables due to the mapping of them, especially if you leave the warning about mirrored variables on.

Add A Comment

What is 3 + 8?

Preview: hide