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.
|
virtualdefault |
|
inline |
|
inline |
Get current state.
|
inline |
Get states.
|
inline |
Transit State.
|
inline |
Check current state.
|
inline |
|
inline |
Set Do action function.
|
inline |
Set Entry action function.
|
inline |
Set Exit action function.
|
inline |
Set Listener Object.
|
inline |
Set NOP function.
|
inlineprotected |
Set NOP function.
|
inline |
Set PostDo action function.
|
inline |
Set PreDo action function.
|
inline |
Set the initial state.
|
inline |
Set state transition action function.
|
inline |
References RTC_Utils::StateMachine< State, Listener, States, Callback >::m_do, RTC_Utils::StateMachine< State, Listener, States, Callback >::m_entry, RTC_Utils::StateMachine< State, Listener, States, Callback >::m_exit, RTC_Utils::StateMachine< State, Listener, States, Callback >::m_listener, RTC_Utils::StateMachine< State, Listener, States, Callback >::m_num, RTC_Utils::StateMachine< State, Listener, States, Callback >::m_postdo, RTC_Utils::StateMachine< State, Listener, States, Callback >::m_predo, RTC_Utils::StateMachine< State, Listener, States, Callback >::m_selftrans, RTC_Utils::StateMachine< State, Listener, States, Callback >::m_states, and RTC_Utils::StateMachine< State, Listener, States, Callback >::m_transit.
|
inline |
Worker function.
|
inline |
|
inline |
|
inline |
|
protected |
Callback function for Do action .
Referenced by RTC_Utils::StateMachine< State, Listener, States, Callback >::swap().
|
protected |
Callback function for Entry action .
Referenced by RTC_Utils::StateMachine< State, Listener, States, Callback >::swap().
|
protected |
Callback function for Exit action .
Referenced by RTC_Utils::StateMachine< State, Listener, States, Callback >::swap().
|
protected |
Callback function for listener .
Referenced by RTC_Utils::StateMachine< State, Listener, States, Callback >::swap().
|
protected |
|
protected |
Number of state .
Referenced by RTC_Utils::StateMachine< State, Listener, States, Callback >::swap().
|
protected |
Callback function for PostDo action .
Referenced by RTC_Utils::StateMachine< State, Listener, States, Callback >::swap().
|
protected |
Callback function for PreDo action .
Referenced by RTC_Utils::StateMachine< State, Listener, States, Callback >::swap().
|
protected |
|
protected |
Current state information .
Referenced by RTC_Utils::StateMachine< State, Listener, States, Callback >::swap().
|
protected |
Callback function for State transition action .
Referenced by RTC_Utils::StateMachine< State, Listener, States, Callback >::swap().