Stateflow User's Guide Previous page   Next Page

Creating Parallel States

In Creating Exclusive States, you learn about exclusive states, the default state of Stateflow, the type of state that you have been creating in all the previous material of this Getting Started guide. In this topic, you learn about parallel states, the only other type of state in Stateflow.

Parallel states have dashed borders and are sometimes referred to as AND states. You create them by assigning the parent of the states parallel decomposition. The distinguishing feature about parallel states is that all brother and sister parallel states are active at the same time. You could say that these states are actively concurrent with each other.

In this topic, you create parallel states to provide control over two individual control objects in the following steps:

  1. Load the Simulink model SFcontrol3 you save in Adding a Sensor to the Model and save it as SFcontrol8.

  2. Change the Constant block value for the input data temp to 130.
  3. Open the Stateflow diagram for the Stateflow block Controller.

  4. Use zoom to decrease the size of the diagram and draw a superstate around the diagram, as shown.

  5. Label the superstate FAN1 and double-click it to group it.
  6. Increase the Stateflow diagram window to twice its horizontal size.
  7. Place the cursor in state FAN1 and right-click and drag a copy of it to the right as shown.

  8. Rename the copied superstate on the right to FAN2.
  9. Right-click empty space in the diagram and, from the resulting context menu, select Decomposition followed by Parallel(AND).
  1. Notice that the states FAN1 and FAN2 now have dashed borders.

    Notice that both states have numbers in their upper-right corner. These numbers give the priority of one parallel state over another. Even though parallel states have concurrent behavior, they are not completely concurrent. They are executed according to their priority number.

    Priority numbers are assigned to parallel states automatically by Stateflow based on the position of the state. Parallel states that have a higher position in the Stateflow diagram editor receive a higher priority. Parallel states on the left have priority over states on the right with the same vertical position.

  1. Move the FAN2 state up or down and notice the change in priority number for both FAN1 and FAN2.
  1. Notice that the Stateflow diagram has two states named On and two states named Off. These states do not conflict because each set of On and Off states is in its own namespace. States must be named uniquely, but only within their namespace.

  1. In the parallel state FAN2, label the transition from Off to On as follows:
  1. The expression in(FAN1.On) checks if the On state in FAN1 is active before the transition is taken. This use of the built-in function in is referred to as an implicit event. In this case, if the state Off in FAN2 is active and the state On in FAN1 is active, in(FAN1.On) is true and the transition from Off to On in FAN2 is taken.

  1. Continue making the following changes to the diagram in parallel state FAN2:
  1. After these changes are made, this is what you should see.

  1. Save the model (SFcontrol8).

Previous page  Creating Exclusive States Simulating Parallel States Next page

© 1994-2005 The MathWorks, Inc.