SMACC2
|
#include <smacc_state_machine.hpp>
Public Member Functions | |
ISmaccStateMachine (std::string stateMachineName, SignalDetector *signalDetector) | |
virtual | ~ISmaccStateMachine () |
virtual void | reset () |
virtual void | stop () |
virtual void | eStop () |
template<typename TOrthogonal > | |
TOrthogonal * | getOrthogonal () |
const std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > & | getOrthogonals () const |
template<typename SmaccComponentType > | |
void | requiresComponent (SmaccComponentType *&storage, bool throwsException=false) |
template<typename EventType > | |
void | postEvent (EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE) |
template<typename EventType > | |
void | postEvent (EventLifeTime evlifetime=EventLifeTime::ABSOLUTE) |
template<typename T > | |
bool | getGlobalSMData (std::string name, T &ret) |
template<typename T > | |
void | setGlobalSMData (std::string name, T value) |
template<typename StateField , typename BehaviorType > | |
void | mapBehavior () |
std::string | getStateMachineName () |
void | state_machine_visualization () |
std::shared_ptr< SmaccStateInfo > | getCurrentStateInfo () |
void | publishTransition (const SmaccTransitionInfo &transitionInfo) |
virtual void | onInitialize () |
this function should be implemented by the user to create the orthogonals More... | |
void | getTransitionLogHistory (const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< smacc2_msgs::srv::SmaccGetTransitionHistory::Request > req, std::shared_ptr< smacc2_msgs::srv::SmaccGetTransitionHistory::Response > res) |
template<typename TSmaccSignal , typename TMemberFunctionPrototype , typename TSmaccObjectType > | |
boost::signals2::connection | createSignalConnection (TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object) |
void | disconnectSmaccSignalObject (void *object) |
template<typename StateType > | |
void | notifyOnStateEntryStart (StateType *state) |
template<typename StateType > | |
void | notifyOnStateEntryEnd (StateType *state) |
template<typename StateType > | |
void | notifyOnRuntimeConfigured (StateType *state) |
template<typename StateType > | |
void | notifyOnStateExitting (StateType *state) |
template<typename StateType > | |
void | notifyOnStateExited (StateType *state) |
template<typename StateType > | |
void | notifyOnRuntimeConfigurationFinished (StateType *state) |
uint64_t | getCurrentStateCounter () const |
ISmaccState * | getCurrentState () const |
const SmaccStateMachineInfo & | getStateMachineInfo () |
template<typename InitialStateType > | |
void | buildStateMachineInfo () |
rclcpp::Node::SharedPtr | getNode () |
rclcpp::Logger | getLogger () |
std::recursive_mutex & | getMutex () |
Protected Member Functions | |
void | checkStateMachineConsistence () |
void | initializeROS (std::string smshortname) |
void | onInitialized () |
template<typename TOrthogonal > | |
void | createOrthogonal () |
Protected Attributes | |
rclcpp::Node::SharedPtr | nh_ |
rclcpp::TimerBase::SharedPtr | timer_ |
rclcpp::Publisher< smacc2_msgs::msg::SmaccStateMachine >::SharedPtr | stateMachinePub_ |
rclcpp::Publisher< smacc2_msgs::msg::SmaccStatus >::SharedPtr | stateMachineStatusPub_ |
rclcpp::Publisher< smacc2_msgs::msg::SmaccTransitionLogEntry >::SharedPtr | transitionLogPub_ |
rclcpp::Service< smacc2_msgs::srv::SmaccGetTransitionHistory >::SharedPtr | transitionHistoryService_ |
std::vector< ISmaccState * > | currentState_ |
std::shared_ptr< SmaccStateInfo > | currentStateInfo_ |
smacc2_msgs::msg::SmaccStatus | status_msg_ |
std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > | orthogonals_ |
std::shared_ptr< SmaccStateMachineInfo > | stateMachineInfo_ |
Private Member Functions | |
void | lockStateMachine (std::string msg) |
void | unlockStateMachine (std::string msg) |
template<typename EventType > | |
void | propagateEventToStateReactors (ISmaccState *st, EventType *ev) |
void | updateStatusMessage () |
Private Attributes | |
std::recursive_mutex | m_mutex_ |
std::recursive_mutex | eventQueueMutex_ |
StateMachineInternalAction | stateMachineCurrentAction |
std::map< void *, std::shared_ptr< CallbackCounterSemaphore > > | stateCallbackConnections |
std::map< std::string, std::pair< std::function< std::string()>, boost::any > > | globalData_ |
std::vector< smacc2_msgs::msg::SmaccTransitionLogEntry > | transitionLogHistory_ |
smacc2::SMRunMode | runMode_ |
SignalDetector * | signalDetector_ |
uint64_t | stateSeqCounter_ |
Friends | |
class | ISmaccState |
class | SignalDetector |
Definition at line 64 of file smacc_state_machine.hpp.
smacc2::ISmaccStateMachine::ISmaccStateMachine | ( | std::string | stateMachineName, |
SignalDetector * | signalDetector | ||
) |
Definition at line 35 of file smacc_state_machine.cpp.
References smacc2::DEBUG, smacc2::SignalDetector::initialize(), nh_, smacc2::RELEASE, runMode_, and signalDetector_.
|
virtual |
Definition at line 75 of file smacc_state_machine.cpp.
References nh_.
void smacc2::ISmaccStateMachine::buildStateMachineInfo |
Definition at line 739 of file smacc_state_machine_impl.hpp.
References checkStateMachineConsistence(), getNode(), and stateMachineInfo_.
|
protected |
Definition at line 229 of file smacc_state_machine.cpp.
Referenced by buildStateMachineInfo().
|
protected |
Definition at line 93 of file smacc_state_machine_impl.hpp.
References getLogger(), m_mutex_, and orthogonals_.
boost::signals2::connection smacc2::ISmaccStateMachine::createSignalConnection | ( | TSmaccSignal & | signal, |
TMemberFunctionPrototype | callback, | ||
TSmaccObjectType * | object | ||
) |
Definition at line 411 of file smacc_state_machine_impl.hpp.
References smacc2::utils::Bind< arity >::bindaux(), getLogger(), m_mutex_, and stateCallbackConnections.
Referenced by smacc2::ISmaccClient::connectSignal(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onAborted(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onCancelled(), smacc2::SmaccAsyncClientBehavior::onFailure(), smacc2::SmaccAsyncClientBehavior::onFinished(), smacc2::components::CpTopicSubscriber< MessageType >::onFirstMessageReceived(), smacc2::client_bases::SmaccSubscriberClient< MessageType >::onFirstMessageReceived(), cl_keyboard::ClKeyboard::OnKeyPress(), smacc2::components::CpTopicSubscriber< MessageType >::onMessageReceived(), smacc2::client_bases::SmaccSubscriberClient< MessageType >::onMessageReceived(), cl_multirole_sensor::ClMultiroleSensor< MessageType >::onMessageTimeout(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onSucceeded(), smacc2::SmaccAsyncClientBehavior::onSuccess(), cl_ros_timer::ClRosTimer::onTimerTick(), cl_ros_timer::CbTimerCountdownLoop::onTimerTick(), and cl_ros_timer::CbTimerCountdownOnce::onTimerTick().
void smacc2::ISmaccStateMachine::disconnectSmaccSignalObject | ( | void * | object | ) |
Definition at line 80 of file smacc_state_machine.cpp.
References nh_, and stateCallbackConnections.
Referenced by notifyOnStateExited(), and smacc2::ISmaccOrthogonal::onDispose().
|
virtual |
Reimplemented in smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >.
Definition at line 102 of file smacc_state_machine.cpp.
Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::eStop().
|
inline |
Definition at line 749 of file smacc_state_machine_impl.hpp.
References currentState_.
|
inline |
|
inline |
Definition at line 106 of file smacc_state_machine.hpp.
References currentStateInfo_.
bool smacc2::ISmaccStateMachine::getGlobalSMData | ( | std::string | name, |
T & | ret | ||
) |
Definition at line 224 of file smacc_state_machine_impl.hpp.
References getLogger(), globalData_, and m_mutex_.
Referenced by smacc2::ISmaccOrthogonal::getGlobalSMData(), smacc2::ISmaccState::getGlobalSMData(), and mapBehavior().
|
inline |
Definition at line 153 of file smacc_state_machine.hpp.
References nh_.
Referenced by createOrthogonal(), createSignalConnection(), getGlobalSMData(), getOrthogonal(), smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl(), mapBehavior(), notifyOnStateEntryEnd(), notifyOnStateEntryStart(), notifyOnStateExited(), notifyOnStateExitting(), postEvent(), propagateEventToStateReactors(), and requiresComponent().
|
inline |
rclcpp::Node::SharedPtr smacc2::ISmaccStateMachine::getNode | ( | ) |
Definition at line 96 of file smacc_state_machine.cpp.
References nh_.
Referenced by buildStateMachineInfo(), smacc2::ISmaccClient::getNode(), smacc2::ISmaccClientBehavior::getNode(), smacc2::ISmaccOrthogonal::getNode(), smacc2::SignalDetector::getNode(), smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl(), smacc2::SignalDetector::pollOnce(), and smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::SmaccState().
TOrthogonal * smacc2::ISmaccStateMachine::getOrthogonal |
Definition at line 55 of file smacc_state_machine_impl.hpp.
References getLogger(), m_mutex_, and orthogonals_.
Referenced by smacc2::ISmaccState::getOrthogonal().
const std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > & smacc2::ISmaccStateMachine::getOrthogonals | ( | ) | const |
Definition at line 105 of file smacc_state_machine.cpp.
References orthogonals_.
Referenced by smacc2::introspection::SmaccStateMachineInfo::assembleSMStructureMessage(), smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal(), smacc2::SignalDetector::findUpdatableClientsAndComponents(), smacc2::SignalDetector::findUpdatableStateElements(), and smacc2::ISmaccState::requiresClient().
|
inline |
Definition at line 751 of file smacc_state_machine_impl.hpp.
References stateMachineInfo_.
Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getStateInfo().
std::string smacc2::ISmaccStateMachine::getStateMachineName | ( | ) |
Definition at line 224 of file smacc_state_machine.cpp.
References smacc2::introspection::demangleSymbol().
void smacc2::ISmaccStateMachine::getTransitionLogHistory | ( | const std::shared_ptr< rmw_request_id_t > | request_header, |
const std::shared_ptr< smacc2_msgs::srv::SmaccGetTransitionHistory::Request > | req, | ||
std::shared_ptr< smacc2_msgs::srv::SmaccGetTransitionHistory::Response > | res | ||
) |
Definition at line 185 of file smacc_state_machine.cpp.
References nh_, and transitionLogHistory_.
Referenced by initializeROS().
|
protected |
Definition at line 166 of file smacc_state_machine.cpp.
References getTransitionLogHistory(), nh_, stateMachinePub_, stateMachineStatusPub_, transitionHistoryService_, and transitionLogPub_.
Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl().
|
private |
Definition at line 212 of file smacc_state_machine.cpp.
Referenced by notifyOnStateExited().
void smacc2::ISmaccStateMachine::mapBehavior |
Definition at line 280 of file smacc_state_machine_impl.hpp.
References smacc2::introspection::demangleSymbol(), getGlobalSMData(), getLogger(), requiresComponent(), and setGlobalSMData().
void smacc2::ISmaccStateMachine::notifyOnRuntimeConfigurationFinished | ( | StateType * | state | ) |
Definition at line 561 of file smacc_state_machine_impl.hpp.
References currentState_, m_mutex_, smacc2::SignalDetector::notifyStateConfigured(), orthogonals_, signalDetector_, smacc2::STATE_ENTERING, stateMachineCurrentAction, and updateStatusMessage().
Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal().
void smacc2::ISmaccStateMachine::notifyOnRuntimeConfigured | ( | StateType * | state | ) |
Definition at line 580 of file smacc_state_machine_impl.hpp.
References smacc2::STATE_CONFIGURING, and stateMachineCurrentAction.
Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal().
void smacc2::ISmaccStateMachine::notifyOnStateEntryEnd | ( | StateType * | state | ) |
Definition at line 493 of file smacc_state_machine_impl.hpp.
References currentState_, smacc2::introspection::demangleSymbol(), getLogger(), m_mutex_, orthogonals_, smacc2::STATE_RUNNING, stateMachineCurrentAction, and updateStatusMessage().
Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal().
void smacc2::ISmaccStateMachine::notifyOnStateEntryStart | ( | StateType * | state | ) |
Definition at line 477 of file smacc_state_machine_impl.hpp.
References currentState_, currentStateInfo_, smacc2::introspection::demangleSymbol(), getLogger(), m_mutex_, orthogonals_, stateMachineInfo_, and stateSeqCounter_.
Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal().
void smacc2::ISmaccStateMachine::notifyOnStateExited | ( | StateType * | state | ) |
Definition at line 648 of file smacc_state_machine_impl.hpp.
References currentState_, smacc2::introspection::demangleSymbol(), disconnectSmaccSignalObject(), getLogger(), lockStateMachine(), smacc2::SignalDetector::notifyStateExited(), orthogonals_, signalDetector_, stateCallbackConnections, stateMachineCurrentAction, smacc2::TRANSITIONING, and unlockStateMachine().
Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::exit().
void smacc2::ISmaccStateMachine::notifyOnStateExitting | ( | StateType * | state | ) |
Definition at line 586 of file smacc_state_machine_impl.hpp.
References smacc2::introspection::demangleSymbol(), getLogger(), orthogonals_, smacc2::STATE_EXITING, and stateMachineCurrentAction.
Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::exit().
|
virtual |
this function should be implemented by the user to create the orthogonals
Definition at line 157 of file smacc_state_machine.cpp.
Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl().
|
protected |
Definition at line 159 of file smacc_state_machine.cpp.
References nh_, state_machine_visualization(), and timer_.
Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl().
void smacc2::ISmaccStateMachine::postEvent | ( | EventLifeTime | evlifetime = EventLifeTime::ABSOLUTE | ) |
Definition at line 215 of file smacc_state_machine_impl.hpp.
References getLogger(), and postEvent().
void smacc2::ISmaccStateMachine::postEvent | ( | EventType * | ev, |
EventLifeTime | evlifetime = EventLifeTime::ABSOLUTE |
||
) |
Definition at line 177 of file smacc_state_machine_impl.hpp.
References smacc2::CURRENT_STATE, currentState_, eventQueueMutex_, eventtypename, getLogger(), smacc2::SignalDetector::postEvent(), propagateEventToStateReactors(), signalDetector_, smacc2_event, smacc2::STATE_EXITING, stateMachineCurrentAction, TRACEPOINT(), and smacc2::TRANSITIONING.
Referenced by smacc2::ISmaccComponent::postEvent(), smacc2::ISmaccClient::postEvent(), smacc2::ISmaccClientBehavior::postEvent(), smacc2::ISmaccState::postEvent(), postEvent(), and smacc2::StateReactor::setOutputEvent().
|
private |
Definition at line 721 of file smacc_state_machine_impl.hpp.
References smacc2::ISmaccState::getClassName(), getLogger(), smacc2::ISmaccState::getParentState(), smacc2::ISmaccState::getStateReactors(), and propagateEventToStateReactors().
Referenced by postEvent(), and propagateEventToStateReactors().
void smacc2::ISmaccStateMachine::publishTransition | ( | const SmaccTransitionInfo & | transitionInfo | ) |
Definition at line 147 of file smacc_state_machine.cpp.
References nh_, smacc2::introspection::transitionInfoToMsg(), transitionLogHistory_, and transitionLogPub_.
Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl(), and smacc2::ISmaccState::notifyTransitionFromTransitionTypeInfo().
void smacc2::ISmaccStateMachine::requiresComponent | ( | SmaccComponentType *& | storage, |
bool | throwsException = false |
||
) |
Definition at line 126 of file smacc_state_machine_impl.hpp.
References smacc2::introspection::demangleSymbol(), getLogger(), m_mutex_, and orthogonals_.
Referenced by mapBehavior(), smacc2::ISmaccClientBehavior::requiresComponent(), smacc2::ISmaccOrthogonal::requiresComponent(), and smacc2::ISmaccState::requiresComponent().
|
virtual |
Reimplemented in smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >.
Definition at line 98 of file smacc_state_machine.cpp.
Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::reset().
void smacc2::ISmaccStateMachine::setGlobalSMData | ( | std::string | name, |
T | value | ||
) |
Definition at line 259 of file smacc_state_machine_impl.hpp.
References globalData_, m_mutex_, and updateStatusMessage().
Referenced by mapBehavior(), smacc2::ISmaccOrthogonal::setGlobalSMData(), and smacc2::ISmaccState::setGlobalSMData().
void smacc2::ISmaccStateMachine::state_machine_visualization | ( | ) |
Definition at line 196 of file smacc_state_machine.cpp.
References m_mutex_, nh_, stateMachineInfo_, stateMachinePub_, stateMachineStatusPub_, and status_msg_.
Referenced by onInitialized().
|
virtual |
Reimplemented in smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >.
Definition at line 100 of file smacc_state_machine.cpp.
Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::stop().
|
private |
Definition at line 218 of file smacc_state_machine.cpp.
Referenced by notifyOnStateExited().
|
private |
Definition at line 110 of file smacc_state_machine.cpp.
References currentStateInfo_, smacc2::DEBUG, globalData_, m_mutex_, nh_, runMode_, stateMachineStatusPub_, and status_msg_.
Referenced by notifyOnRuntimeConfigurationFinished(), notifyOnStateEntryEnd(), and setGlobalSMData().
|
friend |
Definition at line 220 of file smacc_state_machine.hpp.
|
friend |
Definition at line 221 of file smacc_state_machine.hpp.
|
protected |
Definition at line 178 of file smacc_state_machine.hpp.
Referenced by getCurrentState(), notifyOnRuntimeConfigurationFinished(), notifyOnStateEntryEnd(), notifyOnStateEntryStart(), notifyOnStateExited(), and postEvent().
|
protected |
Definition at line 180 of file smacc_state_machine.hpp.
Referenced by getCurrentStateInfo(), notifyOnStateEntryStart(), and updateStatusMessage().
|
private |
Definition at line 192 of file smacc_state_machine.hpp.
Referenced by postEvent().
|
private |
Definition at line 199 of file smacc_state_machine.hpp.
Referenced by getGlobalSMData(), setGlobalSMData(), and updateStatusMessage().
|
private |
Definition at line 191 of file smacc_state_machine.hpp.
Referenced by createOrthogonal(), createSignalConnection(), getGlobalSMData(), getMutex(), getOrthogonal(), lockStateMachine(), notifyOnRuntimeConfigurationFinished(), notifyOnStateEntryEnd(), notifyOnStateEntryStart(), smacc2::SignalDetector::pollOnce(), requiresComponent(), setGlobalSMData(), state_machine_visualization(), unlockStateMachine(), and updateStatusMessage().
|
protected |
Definition at line 168 of file smacc_state_machine.hpp.
Referenced by disconnectSmaccSignalObject(), getLogger(), getNode(), getTransitionLogHistory(), initializeROS(), ISmaccStateMachine(), lockStateMachine(), onInitialized(), publishTransition(), state_machine_visualization(), unlockStateMachine(), updateStatusMessage(), and ~ISmaccStateMachine().
|
protected |
Definition at line 185 of file smacc_state_machine.hpp.
Referenced by createOrthogonal(), getOrthogonal(), getOrthogonals(), notifyOnRuntimeConfigurationFinished(), notifyOnStateEntryEnd(), notifyOnStateEntryStart(), notifyOnStateExited(), notifyOnStateExitting(), and requiresComponent().
|
private |
Definition at line 204 of file smacc_state_machine.hpp.
Referenced by ISmaccStateMachine(), and updateStatusMessage().
|
private |
Definition at line 207 of file smacc_state_machine.hpp.
Referenced by ISmaccStateMachine(), notifyOnRuntimeConfigurationFinished(), notifyOnStateExited(), and postEvent().
|
private |
Definition at line 196 of file smacc_state_machine.hpp.
Referenced by createSignalConnection(), disconnectSmaccSignalObject(), and notifyOnStateExited().
|
private |
Definition at line 194 of file smacc_state_machine.hpp.
Referenced by notifyOnRuntimeConfigurationFinished(), notifyOnRuntimeConfigured(), notifyOnStateEntryEnd(), notifyOnStateExited(), notifyOnStateExitting(), smacc2::SignalDetector::pollOnce(), and postEvent().
|
protected |
Definition at line 188 of file smacc_state_machine.hpp.
Referenced by buildStateMachineInfo(), getStateMachineInfo(), smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl(), notifyOnStateEntryStart(), and state_machine_visualization().
|
protected |
Definition at line 171 of file smacc_state_machine.hpp.
Referenced by initializeROS(), and state_machine_visualization().
|
protected |
Definition at line 172 of file smacc_state_machine.hpp.
Referenced by initializeROS(), state_machine_visualization(), and updateStatusMessage().
|
private |
Definition at line 209 of file smacc_state_machine.hpp.
Referenced by getCurrentStateCounter(), and notifyOnStateEntryStart().
|
protected |
Definition at line 182 of file smacc_state_machine.hpp.
Referenced by state_machine_visualization(), and updateStatusMessage().
|
protected |
Definition at line 170 of file smacc_state_machine.hpp.
Referenced by onInitialized().
|
protected |
Definition at line 174 of file smacc_state_machine.hpp.
Referenced by initializeROS().
|
private |
Definition at line 202 of file smacc_state_machine.hpp.
Referenced by getTransitionLogHistory(), and publishTransition().
|
protected |
Definition at line 173 of file smacc_state_machine.hpp.
Referenced by initializeROS(), and publishTransition().