phaze
Phaze is a finite state machine for Node robotics. It is intended to help manage the transitions from one state to the next in a deterministic manner.
Concepts
Some basics to consider when using a state machine:
- State - a discrete, non-transitory situation that a system may be in at any given moment, e.g.:
- idling
- moving forward
- reversing
- Transition - the process of moving from one state to another
A stimulus is required to initiate a transition - this can be an event or an explicit call to change state.
Design
States
- Phaze is designed to allow an optional callback function to be triggered once a state has been entered.
- Once this function has completed, an output event is fired, which will initiate a transition change.
Transitions
- A transition moves the system from the current state to the next state. A transition is triggered by the output event of a previous state.
- A transition has a many-to-one relationship between states, i.e.: a transition can have multiple "from" states but ONLY one "to" state.
Persistence
- Persistent storage of state is achieved through passing save and get functions into the initialise function of the state machine.
- These functions are used to save or retrieve state using injected logic.
Nesting
- A state machine can be nested within the state of an outer state machine.
- Construction and initialisation of the inner state machine is done within the "do" function of a state.
Usage
/***************STATES***************/var startState = { } outputEvent: 'startEvent' ; var walkingState = { ; } outputEvent: 'walkEvent'; // no outputEvent will cause the state machine to exit the loopvar runningState = { ; }; /***************TRANSITIONS***************/var transition1 = eventId: 'startEvent' from: 'startState' to: 'walkingState'; var transition2 = eventId: 'walkEvent' from: 'walkingState' to: 'runningState'; /***************STATE PERSISTENCE FUNCTIONS (these can wrap database calls etc.)***************/var { ;}; var { ;}; /***STATE MACHINE***/var stateMachine = ; // initialise - first argument is the number of times the machine will loop (0 = infinite)stateMachine;