Motorcortex Core
version: 2.7.6
|
States machine manager and event interpreter. More...
#include <sm_statemachine.h>
Public Member Functions | |
void | deinitialize () |
Deinitialization of the queues and states. More... | |
void | setName (const std::string &new_name) |
Sets name of the state machine. More... | |
const std::string & | getName () const |
Gets name of the state machine. More... | |
template<class STATE > | |
void | createState () |
Creates new state. More... | |
template<class STATE > | |
void | createState (const STATE &new_state) |
Creates new state from the copy constructor. More... | |
template<class STATE > | |
STATE * | setActiveState (bool output=true) |
Sets active state by class name. More... | |
SUPER_STATE * | setActiveState (int state_id, bool output=true) |
Sets active state by class id. More... | |
template<typename STATE > | |
int | getStateId () |
Given a state class name returns its id. More... | |
template<typename... STATES> | |
bool | isStateActive () |
Checks if given state is active by state class name. More... | |
bool | isStateActive (int id) |
Checks if given state is active by state id. More... | |
bool | isStateActive (std::initializer_list< int > id_list) |
Checks if given states are active by the list of state id. More... | |
EventStatus | executeEvent (const Event0< SUPER_STATE > &event, bool silently=false) |
Executes event in the active state. More... | |
EventStatus | executeEvent (const Event1< SUPER_STATE > &event, bool silently=false) |
Executes event in the active state. More... | |
EventStatus | executeEvent (const Event2< SUPER_STATE > &event, bool silently=false) |
Executes event in the active state. More... | |
EventStatus | executeEvent (const Event3< SUPER_STATE > &event, bool silently=false) |
Executes event in the active state. More... | |
void | addEvent (const Event0< SUPER_STATE > &event, double timeoutSec=EVENT_DEFAULT_TIMEOUT_SEC, EventPriority priority=LOW_PRIORITY_EVENT, EventStatus(SUPER_STATE::*terminateEvent)=DEFAULT_TERMINATE_EVENT) |
Adds event without parameters to the event execution queue. More... | |
void | addEvent (const Event1< SUPER_STATE > &event, double timeoutSec=EVENT_DEFAULT_TIMEOUT_SEC, EventPriority priority=LOW_PRIORITY_EVENT, EventStatus(SUPER_STATE::*terminateEvent)=DEFAULT_TERMINATE_EVENT) |
Adds event with one parameter to the event execution queue. More... | |
void | addEvent (const Event2< SUPER_STATE > &event, double timeoutSec=EVENT_DEFAULT_TIMEOUT_SEC, EventPriority priority=LOW_PRIORITY_EVENT, EventStatus(SUPER_STATE::*terminateEvent)=DEFAULT_TERMINATE_EVENT) |
Adds event with two parameters to the event execution queue. More... | |
void | addEvent (const Event3< SUPER_STATE > &event, double timeoutSec=EVENT_DEFAULT_TIMEOUT_SEC, EventPriority priority=LOW_PRIORITY_EVENT, EventStatus(SUPER_STATE::*terminateEvent)=DEFAULT_TERMINATE_EVENT) |
Adds event with three parameters to the event queue. More... | |
double | getDtSec () const |
EventStatus | iterate (double cycleTimeSec) |
Iterates an execution cycle of the state machine. More... | |
void | clear (bool highPriority=true, bool lowPriority=true) |
Clears event queue. More... | |
size_t | length (EventPriority priority=LOW_PRIORITY_EVENT) |
Returns length of the event queue. More... | |
ErrorHandle< SUPER_STATE > & | getErrorHandle () |
Returns reference to the error handler. More... | |
const ErrorHandle< SUPER_STATE > & | getErrorHandle () const |
Returns const reference to the error handler. More... | |
bool | warning (const Error &error) |
Executes warning routine, add error code to the error list. More... | |
bool | forcedDisengaged (const Error &error) |
Executes forced disengaged routine, add error code to the error list. More... | |
bool | shutdown (const Error &error) |
Executes shutdown routine, add error code to the error list. More... | |
bool | emergencyStop (const Error &error) |
Executes e-stop routine, add error code to the error list. More... | |
Friends | |
class | ErrorHandle< SUPER_STATE > |
States machine manager and event interpreter.
Creates and initializes the states, adds events to the queue, executes events from the queue.
|
inline |
Adds event without parameters to the event execution queue.
event | - event without parameters to add to the queue. |
timeoutSec | - time in sec after which terminate callback is called. |
priority | - priority of the event. |
terminateEvent | - terminate callback, which is called if the event is not complete before timeout. |
|
inline |
Adds event with one parameter to the event execution queue.
event | - event with one parameter to add to the queue. |
timeoutSec | - time in sec after which terminate callback is called. |
priority | - priority of the event. |
terminateEvent | - terminate callback, which is called if the event is not complete before timeout. |
|
inline |
Adds event with two parameters to the event execution queue.
event | - event with two parameters to add to the queue. |
timeoutSec | - time in sec after which terminate callback is called. |
priority | - priority of the event. |
terminateEvent | - terminate callback, which is called if the event is not complete before timeout. |
|
inline |
Adds event with three parameters to the event queue.
event | - event with three parameters to add to the queue. |
timeoutSec | - time in sec after which terminate callback is called. |
priority | - priority of the event. |
terminateEvent | - terminate callback, which is called if the event is not complete before timeout. |
|
inline |
Clears event queue.
highPriority | - true - to clear high priority queue. |
lowPriority | - true to clear low priority queue. |
|
inline |
Creates new state.
Before the state can be used, it needs to be created and registered in the state machine. The state is created by a default constructor.
STATE | - class name which represents the state. |
|
inline |
Creates new state from the copy constructor.
This method is useful when there is a data which needs to be shared between states.
new_state | - constructor of the new state. |
|
inline |
Deinitialization of the queues and states.
If not called, will be called automatically in the destructor.
|
inline |
Executes e-stop routine, add error code to the error list.
If active state has e-stop routine implemented, adds new error code to the error list, executes e-stop routine.
error | - error code which should be triggered |
|
inline |
Executes event in the active state.
event | - event without parameters to execute. |
silently | - don't produce log output. |
|
inline |
Executes event in the active state.
event | - event with one parameter to execute. |
silently | - don't produce log output. |
|
inline |
Executes event in the active state.
event | - event with two parameters to execute. |
silently | - don't produce log output. |
|
inline |
Executes event in the active state.
event | - event with three parameters to execute. |
silently | - don't produce log output. |
|
inline |
Executes forced disengaged routine, add error code to the error list.
If active state has forced disengaged routine implemented, adds new error code to the error list, executes forced disengaged routine.
error | - error code which should be triggered |
|
inline |
Returns reference to the error handler.
|
inline |
Returns const reference to the error handler.
|
inline |
Gets name of the state machine.
|
inline |
Given a state class name returns its id.
STATE | - state class name. |
|
inline |
Checks if given state is active by state class name.
STATES | - single or multiple state names. |
|
inline |
Checks if given state is active by state id.
id | - state id. |
|
inline |
Checks if given states are active by the list of state id.
id_list | - list of state ids. |
|
inline |
Iterates an execution cycle of the state machine.
cycleTimeSec | - cycle time of the iteration in seconds. |
|
inline |
Returns length of the event queue.
priority | - select type of the queue. |
lowPriority | - true to clear low priority queue. |
|
inline |
Sets active state by class name.
STATE | - state to switch to. |
output | - flag to produce output to console. |
|
inline |
Sets active state by class id.
Every state has a unique id, which can be used to set active state at runtime.
state_id | - id of the state to switch to. |
output | - flag to produce output to console. |
|
inline |
Sets name of the state machine.
new_name | - name of the state machine. |
|
inline |
Executes shutdown routine, add error code to the error list.
If active state has shutdown routine implemented, adds new error code to the error list, executes shutdown routine.
error | - error code which should be triggered |
|
inline |
Executes warning routine, add error code to the error list.
If active state has warning routine implemented, adds new error code to the error list, executes warning routine.
error | - error code which should be triggered |