As Wikipedia says:
a finite-state machine (FSM) or finite-state automaton (FSA, plural: automata), finite automaton, or simply a state machine, is a mathematical model of computation. It is an abstract machine that can be in exactly one of a finite number of states at any given time. The FSM can change from one state to another in response to some inputs; the change from one state to another is called a transition.An FSM is defined by a list of its states, its initial state, and the inputs that trigger each transition.
In other words, a FSM can be the right choice on many occasions with our development board for a number of very good reasons:
- Finite state machines are flexible
- Easy to move from a significant abstract to a code execution
- Low processor overhead
- Easy determination of reachability of a state
The theory behind it is fantastic, but how does this translate into a working Arduino sketch?
In this little tutorial we'll be using a the YA_FSM Arduino library that does all the dirty work behind the scenes.
This way we can focus on what's really important with FSM: the model!
Among the many types of graphic modeling, something that closely resembles GRAFCET / SFC will be used which lends itself very well to describing sequential operations that can be easily translated into code (it was created precisely for this purpose). Despite to GRAFCET /SFC rules, this library will allow only one active state at time (at least for now) and only some action qualifiers are supported: N, S, R, D, L (i would say the most usefuls).
As automation, we will make a small variation on the very classic green / orange / red traffic light algorithm. We will implement the code for a pedestrian traffic light: normally the green light is on; when the pedestrian presses the call button he waits, after a short waiting time the yellow light turns on and finally the red light
This is the graphic representation of this simple automation model:
In order to get familiarity with SFC and library, try to add an additional and helpfully functionality!
Would be nice for pedestrians having a feedback led that will light up on the call button pressed in order to identify that input was acquired from the controller.
Comments
Please log in or sign up to comment.