Home Examples Parallel State Execution (Independent State Machines)
Coding Tips

Parallel State Execution (Independent State Machines)

This example shows how to set up independent state machines that operate in parallel. In this example, control over the target (i.e. target colour) is controlled independently from the main flow of states in the task.

10.18.1   Simulink Code for Parallel State Execution (Independent State Machines) Example

The Simulink code for this example is based on the code in in 6.7 Centre-out Reaching Task. The one difference is the addition of a second target state in the Show_Targetblock. Please see 10.7 Multiple Targets and Multiple Target States for more details on creating a second target state.

Figure 10.27: Simulink Code for Parallel State Example

10.18.2   Stateflow Chart for Parallel State Execution (Independent State Machines) Example

The Stateflow Chart shown below is based upon 6.7 Centre-out Reaching Task, however, several modifications were made to the chart:

  • A new super-state, Main_State_Flow, was created encompassing most of the original states.
  • A new state, Target_Indicator, was created along with two new sub-states, Target_State_1 and Target_State_2.
  • A new super-state, Trial, was created that encompasses the Main_State_Flow and Target_Indicator states.
  • The decomposition of the super-state Trial was changed to Parallel (AND) by

right-clicking inside of the super-state and selecting Decomposition > Parallel (AND). This step resulted in the Main_State_Flow and Target_Indicator states becoming dashed lines rather than solid lines to indicate that they will operate in parallel. The number in the upper right corner indicates which will execute first.

Figure 10.28: Stateflow Chart for Parallel State Execution Example

The above modifications mean that when a transition occurs into the Trial super-state, both the Main_State_Flow and Target_Indicator sub-states become active and both will operate and function concurrently. Likewise, when a transition occurs out of the Trial super-state, both the Main_State_Flow and Target_Indicator super-states become inactive and both cease to operate. For more complete information on using Parallel versus Exclusive states in Stateflow, please refer to the MathWorks Help documentation.

Related Tasks

Coding Tips
Persistent Variables
Persistent variables are ones that hold their value between calls to the embedded MATLAB code they are defined in.
Coding Tips
Custom Control of the Trial Protocol Order
Normally, Dexterit-E manages and controls the order in which Trial Protocols (TPs) execute based on what is defined in the block table of the Task Protocol (see the Dexterit-E User Guide for more details).