I will be maintaining my libraries here:
http://wiring.uniandes.edu.co/source/trunk/wiring/
I am the lead developer for libraries that ship with the Wiring distribution. As per version 1.0 - Wiring will support Arduino boards. You are welcome to check it out!
http://wiring.org.co/download/
Finite State Machine Library for Arduino Author: Alexander Brevig Contact: alexanderbrevig@gmail.com
1.7 2010-03-08: Fixed a bug, constructor ran update, thanks to René Pressé
2.0 2013-02-08: LINK: Versions fixed for Arduino 1.0x Terry King http://arduino-info.wikispaces.com/HAL-LibrariesUpdates
1.8 2010-02-04: Fixed a bug, missing return type, thanks to Rick Howard
1.7 2010-03-08: Fixed a bug, constructor ran update, thanks to René Pressé
1.6 2010-03-08: Added timeInCurrentState() , requested by sendhb
1.5 2009-11-29: Fixed a bug that was introduced by the last fix, thanks to Jon Hylands again
1.4 2009-11-29: The first state now calls it's enter(), thank you Jon Hylands for bringing this bug to my attention.
1.3 2009-11-01: Added getCurrentState and isInState, requested by Henry Herman
1.2 2009-05-18: Enter and exit bug fix
1.1 2009-05-18: Added support for cascaded calls
1.0 2009-04-11: Beta
A FSM serves as a manager that organizes a set of states, or behaviors. It manages the transition between states, and the state itself.
The transitions might be caused by the user, a wall or something other that is external, and they might be caused by some internal logic. Transitions either happen immediately, or they are deferred to the next update. The latter is the most common. It's used because that way you'll know that all code related to the current state, will have executed on the same state.
FSM is a library for the Arduino.
It is created to help organizing and standardizing the way a FSM could be implemented.
This library expects all functionality to be coded in the sketch, and the State class will simply use callbacks to simulate functionality.
All States expects an enter function, an update function and an exit function. These functions are being called according to this scheme:
current.exit(); //exit current state next.enter(); //enter next state current = next; while no transition current.update();
//TODO - extend this section, contact if urgent
Download here: FSM
NOTE: Updated version for Arduino1.0x can be found here: http://arduino-info.wikispaces.com/HAL-LibrariesUpdates 2/13 terry@yourduino.com
Put the FSM folder in "hardware\libraries\".
In the Arduino IDE, create a new sketch (or open one) and
select from the menubar "Sketch->Import Library->FSM".
Once the library is imported, an "#include <FiniteStateMachine.h>" line will appear
at the top of your Sketch.
State( enterFunction , updateFunction , exitFunction )
State ethernetDebugState = State( connectToHost , debug , closeConnectionToHost );
FiniteStateMachine(State& current)
FSM(State& current)
FSM ethernetStateMachine = FSM(ethernetDebugState);
Initializes an FSM object with the current state equal to ethernetDebugState
This function gets called whenever this state is entered
This function gets called whenever the state machine updates while in this state
This function gets called whenever this state is exited
This function will trigger update on the current State
This function will schedule a state change, the change itself will occur at the beginning of the next update
This function will instantly change the current state to next state
Returns the current state
Check if state is equal to the current state of the FSM
We will implement a state machine for an LED.
From a design point of view we want to make the led go on and off, as well as fade in and out. This translates directly to the states for our example:
The states describe themselves.
We will use external transitions, caused by a user and their button presses.
Each button will cause the FSM to advance to the next State in the diagram above.
How can I use multiple FSMs?
//Under Construction
Part of AlphaBeta Libraries. | |
Last Modified: | August 13, 2015, at 02:32 PM |
By: | pert |