Checking State Activity

When to Check State Activity

Check state activity when you have substates in parallel states that can be active at the same time. For example, checking state activity allows you to synchronize substates in two parallel states.

How to Check State Activity

Use the in operator to check if a state is active. You can use this operator in state actions and transitions that originate from states.

The in Operator

Purpose

Checks if a state is active in a given time step during chart execution.

Syntax

in(S)

where S is a fully qualified state.

Description

The in operator is true and returns a value of 1 whenever state S is active; otherwise, it returns a value of 0.

Example

This example illustrates the use of the in operator in transition conditions.

In this chart, using the in operator to check state activity synchronizes substates in the parallel states Place and Tracker. For example, when the input position u becomes positive, the state transition from Place.L to Place.R occurs. This transition makes the condition [in(Place.R)] true, and the transition from Tracker.Moved_Left to Tracker.Moved_Right occurs.

How Checking State Activity Works

Checking state activity is a two-stage process. First, the in operator must find the desired state. Then, the operator determines if the desired state is active.

This diagram shows the detailed process of checking state activity.

When you use the in operator to check state activity, these actions take place:

  1. The search begins in the state where you use the in operator.

  2. The in operator searches at that level of the hierarchy for a path to a state that matches the desired state. If the operator finds a match, it adds that state to the list of possible matches.

  3. The operator moves up to the next highest level of the hierarchy. At that level, the operator searches for a path to a state that matches the desired state. If the operator finds a match, it adds that state to the list of possible matches.

  4. The in operator repeats the previous step until it reaches the chart level.

  5. At the chart level, the operator searches for a path to a state that matches the desired state. If the operator finds a match, it adds that state to the list of possible matches. Then, the search ends.

  6. After the search ends, one of the following occurs:

State Resolution for Identically Named Substates

For identically named substates in parallel superstates, the scope of the in operator remains local with respect to its chart-level superstate. When the in operator checks activity of a substate, it does not automatically detect an identically named substate that resides in a parallel superstate.

This example shows how the in operator works in a chart with identically named substates.

For the transition condition of A.A2, the in operator performs these search actions:

Step Action of the in OperatorFinds a Match?
1Picks A.A2 as the starting point and searches for the state A.A2.A1.YNo
2Moves up to the next level of the hierarchy and searches for the state A.A1.YYes
3Moves up to the chart level and searches for the state A1.YNo

The search ends, with the single state A.A1.Y found. The in operator checks if that state is active and returns a value of 0 or 1.

Localizing the scope of the in operator produces a unique search result. For example, the in operator of A.A2 does not detect the state B.A1.Y, because the search algorithm localizes the scope of the operator. Similarly, the in operator of B.A2 detects only the state B.A1.Y and does not detect the state A.A1.Y.

Best Practices for Checking State Activity

Use a Specific Search Path

Be specific when defining the path of the state whose activity you want to check. See the examples that follow for details.

Example of No States Matching the Argument of the in Operator.  

In the state A.B, the during action invokes the in operator. Assume that you want to check the activity of the state A.B.Other.C.D. The in operator performs these search actions:

StepAction of the in OperatorFinds a Match?
1Picks A.B as the starting point and searches for the state A.B.C.DNo
2Moves up to the next level of the hierarchy and searches for the state A.C.DNo
3Moves up to the chart level and searches for the state C.DNo

The search ends, and a warning message appears because no match exists.

To eliminate the warning message, use a more specific path to check state activity: in(Other.C.D).

Example of the Wrong State Matching the Argument of the in Operator.  

In the state A.B, the during action invokes the in operator. Assume that you want to check the activity of the state A.B.Other.Q.R. The in operator performs these search actions:

StepAction of the in OperatorFinds a Match?
1Picks A.B as the starting point and searches for the state A.B.Q.RNo
2Moves up to the next level of the hierarchy and searches for the state A.Q.RNo
3Moves up to the chart level and searches for the state Q.RYes

The search ends, with the single state Q.R found. The in operator checks if that state is active and returns a value of 0 or 1.

In this example, the in operator checks the status of the wrong state. To prevent this error, use a more specific path to check state activity: in(Other.Q.R).

Use Unique State Names

Use unique names when you name the states in a chart.

Example of Multiple States Matching the Argument of the in Operator.  

In the state A.B, the during action invokes the in operator. Assume that you want to check the activity of the state A.B.P.Q.R. The in operator performs these search actions:

StepAction of the in OperatorFinds a Match?
1Picks A.B as the starting point and searches for the state A.B.P.Q.RYes
2Moves up to the next level of the hierarchy and searches for the state A.P.Q.RNo
3Moves up to the chart level and searches for the state P.Q.RYes

The search ends, and a warning message appears because multiple matches exist.

To eliminate the warning message, do one of these corrective actions:

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS