NewStateMachine

NewStateMatrix()

Description

Creates a new, empty state machine.

  • The state machine description returned is a struct with 12 subfields:

    • 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.

    • GlobalTimerMatrix: 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).

    • 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 = NewStateMatrix();

Parameters

-None

Returns

  • An empty state machine struct

Example

% This code initializes a state matrix and then adds one state:

sma = NewStateMatrix();

sma = AddState(sma, 'Name', 'MyState', ...

'Timer', 1,...

'StateChangeConditions', {'Tup', 'exit'},...

'OutputActions', {});