Basic Concepts

The Finite State Machine consists of 5 parts: 1) Events, 2) Inputs, 3) Outputs, 4) States and 5) Transitions.

Event

A State Machine is activated by sending an event. It is done by calling

    A( FSM_Name::EventName )
When event is received, it is enqueued and processed. Transitions for the current state are checked to match boolean expression given in Condition field (see screen above). The first transition with matched expression is fired. It is guaranteed that no other event will be processed in the same time (transitions are atomic). The events are queued, so it is possible for automata to pass events to itself. In this case, A() will return after last event sent to itself is executed.

Input

Input is just a boolean function. It is placed inside Condition field of a transition, and normally should be const, because it can be called multiple times (C++ code generator creates const inputs). The full Condition expression expands to

e == Event && ( input1() || (input2() && input3()) )

Output

Output is a non-const void function which is called while entering the state, exiting from the state or moving by transition.

State

A Finite State Machine is always in one of it's states. Though a transition takes some time on execution, it is atomic, so another event will be processed only when automata reaches the transition destination. States and transitions can be represented with a directed graph, and shown in the top-right corner of the application.

In the Moore machine actions are performed when automata is entering one of it's states. It can be done with our editor by putting needed outputs to the In list of state editor (see picture below)

State editor with entry actions

Transition

The transition is the most interesting part of Finite State Machine. It connects states with each other. The order of transitions is significant when choosing the way. Transitions with the certain cases must come first, with more general ones — last. The lookup order is from up to dowd (in the tree). Move transition up-down with buttons (1) in the editor, the order of actions can be changed with (2), available actions are shown in (3), and target can be picked from combobox right of (4):

Disassembled transition editor

Transition firing

When transition condition is true, the first matched transition is fired. Firing includes three steps:

  1. Leaving current state. If destination is empty, the current state is unchanged, and only transition actions (outputs) are executed. Otherwise, out actions of current state are executed.
  2. Moving by transition. Transition actions are executed.
  3. Entering destination state. In actions are executed.
Destination Name

If you explicitly choose current state as destination, all three steps will be passed.