Stateflow User's Guide Previous page   Next Page

Stateflow Hierarchy of Objects

Stateflow diagrams arrange Stateflow objects in a hierarchy of objects. This hierarchy is based on containment. That is, one Stateflow object can contain other Stateflow objects.

The object hierarchy for all Stateflow objects in a Simulink model is referred to as the Stateflow Data Dictionary. This dictionary defines which objects a particular object can contain in a Stateflow diagram. The Stateflow Data Dictionary is depicted in the following diagram.

The highest object in Stateflow hierarchy is the Stateflow machine. It is defined as an object that contains all other Stateflow objects in a Simulink model. This means that the Stateflow machine contains all the Stateflow charts (diagrams) in a Simulink model. In addition, the Stateflow machine for a model can also contain its own data, event, and target objects. Only a simulation target (named sfun) is added to the Stateflow machine by default when the model is created. All other data, event, and target objects must be added to the machine.

Similaraly, charts can contain state, box, function, data, event, transition, junction, and note events. You use all of these objects to create a Stateflow diagram. Continuing with the Stateflow hierarchy, states can contain all of these objects as well, including other states. Stateflow represents state hierarchy with superstates and substates. For example, this Stateflow diagram has a superstate that contains two substates.

In the preceding Stateflow diagram, the engaged superstate contains the first and second substates. The engaged superstate is the parent in the hierarchy to the states first and second. When the event clutch_engaged occurs, the system transitions out of the neutral state to the engaged superstate. Transitions within the engaged superstate are intentionally omitted from this example for simplicity.

A transition out of a superstate implies transitions out of any of its active substates. Transitions can cross superstate boundaries to specify a substate destination. If a substate is made active its parent superstate is also made active.

The Stateflow hierarchy of objects lets you organize complex Stateflow diagrams by defining a containment structure. A hierarchical design usually reduces the number of transitions and produces neat, manageable diagrams. Stateflow supports a hierarchical organization of both charts and states.


Previous page  Connective Junctions Exploring a Real-World Stateflow Application Next page

© 1994-2005 The MathWorks, Inc.