list of dots Digital Research Alliance of Canada logo  NSERC logo  University of Ottawa logo / UniversitĂ© d'Ottawa

User Manual    [Previous]   [Next]   

State Machine Regions

It is possible for a system to be in two states at once. This can be accomplished by dividing any state (we will call it the parent state) into regions separated by || symbols. Each region is like a small state machine, and the system is in one state of each of the regions until it exits the parent state.

In the example below the TrackShuttler starts off initializing then transferringLoad. But after that it starts shuttling (going to the other end of some kind of track). During shuttling, it independently controls its moving in one region, and the lights in the other region. Here shuttling is the parent state. While shuttling the system can be in lightsOn+accelerating, lightsOn+coasting, lightsOff+coasting, lightsOff+braking or in any of the 2*3=6 total configurations of substates of the two regions. When an exit from shuttling occurs due to the reachEnd event, the state machine exits both controllingLights and moving.

In general there can be any number of regions, and regions can be nested in arbitrary ways.

Example

class TrackShuttler {
  sm {
    initializing {
      readyToGo -> transferringLoad;
    }
    transferringLoad {
      loaded -> shuttling;
    }
    shuttling {
      reachEnd -> transferringLoad;
      moving {
        nearEnd -> braking;
         accelerating {
           reachedMaxSpeed -> coasting;
         }
         coasting {
           tooSlow -> accelerating;
         }
         braking {
           tooSlow -> coasting;
         }           
      }
      ||
       controllingLights {
         lightsOn {
           daylightDetected -> lightsOff;
         }
         lightsOff {
           darknessDetected -> lightsOn;
         }
      }
    }
  } 
}
// @@@skipcppcompile

      

Load the above code into UmpleOnline