Stateflow User's Guide Previous page   Next Page

Adding a Superstate

You add superstates to contain other objects to give them the simplicity of one start point and one exit point. In this topic, you add a superstate to contain the states Hi and Lo in the Stateflow diagram of the Simulink model SFcontrol4 that you created in, Controlling with Junctions.

Use the following steps to add the superstate On:

  1. If not already loaded, load the Simulink model SFcontrol4 you save in Adding a Graphical Function for Convenience and save it as SFcontrol5.
  2. Double-click on the Stateflow block Controller to open it, if not already open.

  3. Delete all the transitions except the default transition into the Off state and the transition from Hi to Lo.
  1. The Stateflow diagram now has the following appearance:

  1. Place a new state below the Lo state as shown.

  1. Notice that both the new state and the Lo state are highlighted. This kind of highlighting occurs for conflicts between states. Two states cannot permanently overlap each other like this. However, that is soon remedied in the following steps.

  1. Place the cursor over the upper-right corner of the new state until it turns into a set of diagonal arrows and click-drag the upper-right corner of the new state above the state Hi as shown.

  2. Click-drag the upper-left corner of the new state to the left of Hi and release the mouse as shown.

  1. Notice that even though the new state is highlighted, the states Hi an Lo are not. These states are no longer in conflict with the new state, which now contains them.

Finish the diagram with the following steps:

  1. Name the new state On.
  2. Draw a default transition to the state Lo.
  3. Click-drag a transition from Lo to Hi and label it with [hot()].
  4. Click-drag a transition from On to Off and label it with off_switch.
  5. Click-drag a transition from On to Off and label it with on_switch.
  1. This is what the final Stateflow diagram should look like:

  1. Save the model (SFcontrol5).

Previous page  Adding Superstates to Simplify Control Simulating the Superstate Next page

© 1994-2005 The MathWorks, Inc.