NewStateMachine()
Description
Creates a new, empty state machine.
The state machine description returned is a struct with 21 subfields:
Meta: a struct with information about the state machine (sizes of variables, precomputed for speed)
nStates: the number of states that have been added to the state machine
Manifest: a cell array listing the names of states that have been referenced by other states (though not explicitly added yet)
nStatesInManifest: the number of states in the manifest
StateNames: a cell array of strings containing the name of each state added to the state machine with AddState(); initialized as a 1x1 cell with the string "Placeholder"
InputMatrix: each row is a state, each column is an input event. The matrix specifies the new state to go to if each event occurrs in each state.
OutputMatrix: each row is a state, each column is an output action. The matrix specifies the value of each output action in each state.
StateTimerMatrix: for each state, specifies the new state to go to if the state's internal timer elapses.
GlobalTimerStartMatrix: each row is a state, each column is a global timer. The matrix specifies the new state to go to when the global timer starts.
GlobalTimerEndMatrix: each row is a state, each column is a global timer. The matrix specifies the new state to go to when the global timer elapses.
GlobalTimers: each column is a timer. This vector specifies the current setting of each timer in seconds.
GlobalCounterMatrix: each row is a state, each column is a global counter. The matrix specifies the new state to go to if the counter's threshold is exceeded.
GlobalCounterEvents: each column is a counter. This vector specifies the input event being counted. It defaults to 255 (no input event).
GlobalCounterThresholds: each column is a counter. This vector specifies the number of events recorded before each counter is exceeded.
GlobalCounterSet: each column is a counter. This vector specifies whether each counter was used in the current matrix (1) or not (0).
ConditionMatrix: each row is a state, each column is a configurable input channel condition. The matrix specifies the new state to go to if the condition is satisfied.
ConditionChannels: The input channel index linked to each condition.
ConditionValues: The value of the input channel (specified in ConditionChannels) for each condition to be satisfied.
StateTimers: each column is a state. This vector specifies the setting of each state's internal timer in seconds.
StatesDefined: each column is a state. States appear in the matrix as blank states when first referred to as the target of a state transition. StatesDefined is then set from 0 to 1 when the state is finally added.
States can be added to the empty state machine description with the AddState() function.
Syntax
StateMachine = NewStateMachine();
Parameters
-None
Returns
An empty state machine struct
Example
% This code initializes a state matrix and then adds one state:
sma = NewStateMachine();
sma = AddState(sma, 'Name', 'MyState', ...
'Timer', 1,...
'StateChangeConditions', {'Tup', 'exit'},...
'OutputActions', {});