State Machine Approach

What is a State Machine?

A State Machine is a workflow layout consisting of a finite number of pre-defined states and transitions between these states.

At any point throughout the execution, based on the external inputs and verified conditions, the workflow can be in only one of the states.

Don't think about State Machine like a workflow layout used only in automation. Some examples from your daily life were designed also with State Machine principles in mind: air-condition, elevator, traffic light, or vending machines.

What are the advantages?

  • Transitions between states are well defined and offer flexibility to the workflow;

  • While simple use cases having academic or demo purpose can be resolved with if statements, switch, or loops (for, for each, while, do-while), the state machine can accommodate real-life processes that are more complex and / or continuous.

  • State Machine eases the coverage of all the possible cases/transitions.

Rules for a successful State Machine

  • Must contain a start state and an end state

  • Every state must be linked at least to another state

  • If a state is linked to 2 or more states, they must have a condition based on which the robot can know what is the nest state.

Types of Transitions

1. Normal Transition- the standard transition between 2 states

2. Exception State - can be used to implement a business or application exception; you can think about it like a Try Catch from programming.

Last updated