|
OpenRTM-aist 2.1.0
|
State machine class. More...
#include <StateMachine.h>

Public Member Functions | |
| StateMachine (int num_of_state) | |
| Constructor. | |
| virtual | ~StateMachine () |
| StateMachine (const StateMachine &other) | |
| StateMachine & | operator= (const StateMachine &other) |
| void | swap (StateMachine &other) |
| void | setNOP (Callback call_back) |
| Set NOP function. | |
| void | setListener (Listener *listener) |
| Set Listener Object. | |
| bool | setEntryAction (State state, Callback call_back) |
| Set Entry action function. | |
| bool | setPreDoAction (State state, Callback call_back) |
| Set PreDo action function. | |
| bool | setDoAction (State state, Callback call_back) |
| Set Do action function. | |
| bool | setPostDoAction (State state, Callback call_back) |
| Set PostDo action function. | |
| bool | setExitAction (State state, Callback call_back) |
| Set Exit action function. | |
| bool | setTransitionAction (Callback call_back) |
| Set state transition action function. | |
| void | setStartState (States states) |
| Set the initial state. | |
| States | getStates () |
| Get states. | |
| State | getState () |
| Get current state. | |
| bool | isIn (State state) |
| Check current state. | |
| void | goTo (State state) |
| Transit State. | |
| void | worker () |
| Worker function. | |
| void | worker_pre () |
| void | worker_do () |
| void | worker_post () |
Protected Member Functions | |
| void | setNullFunc (std::vector< Callback > &s, Callback nullfunc) |
| Set NOP function. | |
Protected Attributes | |
| int | m_num |
| Number of state . | |
| Listener * | m_listener |
| Callback function for listener . | |
| std::vector< Callback > | m_entry |
| Callback function for Entry action . | |
| std::vector< Callback > | m_predo |
| Callback function for PreDo action . | |
| std::vector< Callback > | m_do |
| Callback function for Do action . | |
| std::vector< Callback > | m_postdo |
| Callback function for PostDo action . | |
| std::vector< Callback > | m_exit |
| Callback function for Exit action . | |
| Callback | m_transit |
| Callback function for State transition action . | |
| States | m_states |
| Current state information . | |
| bool | m_selftrans |
| std::mutex | m_mutex |
State machine class.
StateMachine class is a class to realize a state machine.
Example: ActiveObject assumes to be an active object that has the state machine. There are three states such as INACTIVE, ACTIVE and ERROR state, and if you want to define Entry or Exit action, this class will realize as follows:
class ActiveObject
{
public:
enum MyState { INACTIVE, ACTIVE, ERROR };
using MyStates = States<MyState>;
ActiveObject()
: m_sm(3)
{
m_sm.setNOP(&ActiveObject::nullAction);
m_sm.setListener(this);
m_sm.setExitAction(INACTIVE, &ActiveObject::inactiveExit);
:
m_sm.setPostDoAction(ERROR, &ActiveObject::errorPostDo);
m_sm.setTransitionAction(&ActiveObject:transition);
};
bool nullAction(MyStates st) {};
bool inactiveExit(MyStates st) {};
:
bool errorPostDo(MyStates st) {};
bool transition(MyStates st) {};
private:
StateMachine<MyState, bool, ActiveObject> m_sm;
};
If you want to give a class to some states, you must implement the class to satisfy the following conditions:
In this class, you can define the following five actions for one state:
Transition action is an action invoked at the transition between any states, and you must define its behavior.
This class executes each action according to the following timing.
If the state is changed and transits(A->B) state,
(A:Exit)->|(state update:A->B)->(B:Entry)->(B:PreDo)->(B:Do)->(B:PostDo)
If the state is not changed and remains B state, (| shows a step's break) (B(n-1):PostDo)->|(B(n):PreDo)->(B(n):Do)->(B(n):PostDo)->|(B(n+1):PreDo) PreDo, Do and PostDo are executed over and over again.
| State | Type of the state |
| Listener | Listener object for action |
| States | State holder |
| Callback | Callback function for action |
|
inlineexplicit |
Constructor.
Constructor
| num_of_state | Number of states in the state machine |
References m_do, m_entry, m_exit, m_listener, m_num, m_postdo, m_predo, m_selftrans, and m_transit.
Referenced by operator=(), StateMachine(), and swap().
|
virtualdefault |
|
inline |
References m_do, m_entry, m_exit, m_listener, m_num, m_postdo, m_predo, m_selftrans, m_states, m_transit, and StateMachine().
|
inline |
|
inline |
|
inline |
Transit State.
Transit to the specified state. This function sets the next state forcibly. Therefore, to determine the next state, users must get current state and implement that logic. If transit destination is the same as the current state, flag of self-transition will be set.
| state | State of the transition destination |
References m_mutex, m_selftrans, and m_states.
|
inline |
|
inline |
References StateMachine(), and swap().
|
inline |
Set Do action function.
Set callback function for Do action that is executed in each state.
| state | Target state for the set |
| call_back | Callback function for Do action |
References m_do.
|
inline |
Set Entry action function.
Set callback function for Entry action that is executed when entering in each state.
| state | Target state for the set |
| call_back | Callback function for Entry action |
References m_entry.
|
inline |
Set Exit action function.
Set callback function for Exit action that is executed in each state.
| state | Target state for the set |
| call_back | Callback function for Exit action |
References m_exit.
|
inline |
Set Listener Object.
Set Listener Object invoked when various actions are executed.
| listener | Listener object |
References m_listener.
|
inline |
|
inlineprotected |
|
inline |
Set PostDo action function.
Set callback function for PostDo action that is executed in each state.
| state | Target state for the set |
| call_back | Callback function for PostDo action |
References m_postdo.
|
inline |
Set PreDo action function.
Set callback function for PreDo action that is executed in each state.
| state | Target state for the set |
| call_back | Callback function for PreDo action |
References m_predo.
|
inline |
Set the initial state.
Set the initial state of the state machine.
| states | Initial state |
References m_states.
|
inline |
Set state transition action function.
Set callback function for State transition action that is executed when transiting to the state.
| call_back | Callback function for State transition |
References m_transit.
|
inline |
References m_do, m_entry, m_exit, m_listener, m_num, m_postdo, m_predo, m_selftrans, m_states, m_transit, and StateMachine().
Referenced by operator=().
|
inline |
|
inline |
References m_do, and m_listener.
|
inline |
References m_listener, and m_postdo.
|
inline |
References m_entry, m_exit, m_listener, and m_predo.
|
protected |
Callback function for Do action .
Referenced by setDoAction(), setNOP(), StateMachine(), StateMachine(), swap(), worker(), and worker_do().
|
protected |
Callback function for Entry action .
Referenced by setEntryAction(), setNOP(), StateMachine(), StateMachine(), swap(), worker(), and worker_pre().
|
protected |
Callback function for Exit action .
Referenced by setExitAction(), setNOP(), StateMachine(), StateMachine(), swap(), worker(), and worker_pre().
|
protected |
Callback function for listener .
Referenced by setListener(), StateMachine(), StateMachine(), swap(), worker(), worker_do(), worker_post(), and worker_pre().
|
protected |
Referenced by getState(), getStates(), goTo(), and isIn().
|
protected |
Number of state .
Referenced by setNullFunc(), StateMachine(), StateMachine(), and swap().
|
protected |
Callback function for PostDo action .
Referenced by setNOP(), setPostDoAction(), StateMachine(), StateMachine(), swap(), worker(), and worker_post().
|
protected |
Callback function for PreDo action .
Referenced by setNOP(), setPreDoAction(), StateMachine(), StateMachine(), swap(), worker(), and worker_pre().
|
protected |
Referenced by goTo(), StateMachine(), StateMachine(), and swap().
|
protected |
Current state information .
Referenced by getState(), getStates(), goTo(), isIn(), setStartState(), StateMachine(), and swap().
|
protected |
Callback function for State transition action .
Referenced by setNOP(), setTransitionAction(), StateMachine(), StateMachine(), and swap().