# Guy and Seth on Simulink

## Breaking up a Stateflow Chart for Collaborative Development

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

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.

Atomic Subcharts

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

and the content of the state becomes atomic

.

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:

.

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

.

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

.

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

### 2 Responses to “Breaking up a Stateflow Chart for Collaborative Development”

1. Paul replied on :

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

2. john replied on :

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.

 Name (required) E-mail (required, will not be published) Website (optional) Spam protection (required): What is 3 + 6 ?

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>


If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).

Guy Rouleau and Seth Popinchalk are Application Engineers for MathWorks. They write here about Simulink and other MathWorks tools used in Model-Based Design.

These postings are the author's and don't necessarily represent the opinions of MathWorks.