Stateflow    

Condition Actions

Example: Actions Specified as Condition Actions

This example shows the semantics of a simple condition action in a multiple segment transition.

Initially the Stateflow diagram is asleep. State A is active. Event E_one occurs and awakens the Stateflow diagram. Conditions C_one and C_two are false. Event E_one is processed from the root of the Stateflow diagram down through the hierarchy of the Stateflow diagram:

  1. The Stateflow diagram root checks to see if there is a valid transition as a result of E_one. A valid transition segment from state A to a connective junction is detected. The condition action, A_one, is detected on the valid transition segment and is immediately executed and completed. State A is still active.
  2. Since the conditions on the transition segments to possible destinations are false, none of the complete transitions is valid.
  3. State A remains active. State A during action executes and completes (durA()).
  4. The Stateflow diagram goes back to sleep waiting to be awakened by another event.

This sequence completes the execution of the Stateflow diagram associated with event E_one when state A was active.

Example: Actions Specified as Condition and Transition Actions

This example shows the semantics of a simple condition and transition action specified on a transition from one exclusive (OR) state to another.

Initially the Stateflow diagram is asleep. State A is active. Event E_one occurs and awakens the Stateflow diagram. Condition C_one is true. Event E_one is processed from the root of the Stateflow diagram down through the hierarchy of the Stateflow diagram:

  1. The Stateflow diagram root checks to see if there is a valid transition as a result of E_one. A valid transition from state A to state B is detected. The condition, C_one is true. The condition action, A_one, is detected on the valid transition and is immediately executed and completed. State A is still active.
  2. State A exit actions execute and complete (ExitA()).
  3. State A is marked inactive.
  4. The transition action, A_two, is executed and completed.
  5. State B is marked active.
  6. State B entry actions execute and complete (entB()).
  7. The Stateflow diagram goes back to sleep waiting to be awakened by another event.

This sequence completes the execution of the Stateflow diagram associated with event E_one when state A was active.

Example: Using Condition Actions in For Loop Construct

Condition actions and connective junctions are used to design a for loop construct. This example shows the use of a condition action and connective junction to create a for loop construct.

See Example: For Loop Construct to see the semantics of this example.

Example: Using Condition Actions to Broadcast Events to Parallel (AND) States

Condition actions can be used to broadcast events immediately to parallel (AND) states. This example shows this use.

See Example: Event Broadcast Condition Action to see the semantics of this example.

Example: Cyclic Behavior to Avoid When Using Condition Actions

This example shows a notation to avoid when using event broadcasts as condition actions because the semantics result in cyclic behavior.

Initially the Stateflow diagram is asleep. State On is active. Event E_one occurs and awakens the Stateflow diagram. Event E_one is processed from the root of the Stateflow diagram down through the hierarchy of the Stateflow diagram:

  1. The Stateflow diagram root checks to see if there is a valid transition as a result of E_one. A valid transition from state On to state Off is detected. A condition action, broadcast of event E_one, is detected on the valid transition and is immediately executed. State On is still active.

    The broadcast of event E_one awakens the Stateflow diagram a second time. The Stateflow diagram root checks to see if there is a valid transition as a result of E_one. The transition from state On to state Off is still valid. The condition action, broadcast of event E_one, is immediately executed again.

  1. Step 1 continues to execute in a cyclical manner. The transition label indicating a trigger on the same event as the condition action broadcast event results in unrecoverable cyclic behavior.

This sequence never completes when event E_one is broadcast and state On is active.


 Transitions to and from Exclusive (OR) States Default Transitions