Overview of Finite State Machines (FSMs)

In essence, a finite state machine (FSM) consists of states and transitions. A state defines the specific actions to be performed while the machine is in that state. For example, a state could represent the running mode of a motor or an active loop maintaining a specific level in a tank. The first step in designing an FSM is to divide the machine’s functionality into discrete states, known as “finite states.”

To move from one state to another, transitions must be defined. A transition is triggered by one or more conditions and specifies the new state (or states) to enter when those conditions are met. For instance, if the level in a filling tank rises above a predefined threshold, the “filling” state must end, and the “emptying” state should begin. Depending on the number of defined transitions, a single active state can lead to one or more subsequent states.

The theoretical FSM model provides an ideal framework for describing the behavior of such systems. A major advantage of this approach is its focus on processing only the information relevant to the current state. Irrelevant data does not affect the state and is simply ignored, ensuring streamlined and efficient control.


Finite State Sketch Features

In detail, an FSM sketch includes a range of functions to evaluate conditions and trigger transitions to the next state. Examples of these conditions include:

  • Detecting the pressing of a button (e.g., monitoring the rising or falling edge of an input signal).
  • Monitoring an analog value crossing a specific threshold (e.g., exceeding or dropping below a defined level).
  • Checking the expiration of a timer.

Additionally, the FSM sketch provides functions to execute actions associated with a state, such as controlling outputs. These outputs enable actions like:

  • Starting a motor.
  • Opening or closing a valve.
  • Adjusting a servo position.
  • Setting analog values (via PWM outputs only).

Each of these functions is detailed in the following chapters, offering a comprehensive guide to building and implementing FSM-based controls.

Translate