SMACC2
Loading...
Searching...
No Matches
smacc2::ISmaccStateMachine Class Reference

#include <smacc_state_machine.hpp>

Inheritance diagram for smacc2::ISmaccStateMachine:
Inheritance graph
Collaboration diagram for smacc2::ISmaccStateMachine:
Collaboration graph

Public Member Functions

 ISmaccStateMachine (std::string stateMachineName, SignalDetector *signalDetector, rclcpp::NodeOptions nodeOptions=rclcpp::NodeOptions())
 
virtual ~ISmaccStateMachine ()
 
virtual void reset ()
 
virtual void stop ()
 
virtual void eStop ()
 
template<typename TOrthogonal >
TOrthogonal * getOrthogonal ()
 
template<typename TOrthogonal , typename TClientBehavior >
TClientBehavior * getClientBehavior (int index=0)
 
const std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > & getOrthogonals () const
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType)
 
template<typename SmaccComponentType >
void requiresComponent (std::string name, SmaccComponentType *&storage, ComponentRequirement requirementType)
 
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)
 
std::string getStateMachineName ()
 
void state_machine_visualization ()
 
std::shared_ptr< SmaccStateInfogetCurrentStateInfo ()
 
void publishTransition (const SmaccTransitionInfo &transitionInfo)
 
virtual void onInitialize ()
 this function should be implemented by the user to create the orthogonals
 
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 >
smacc2::SmaccSignalConnection 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 notifyOnStateExiting (StateType *state)
 
template<typename StateType >
void notifyOnStateExited (StateType *state)
 
template<typename StateType >
void notifyOnRuntimeConfigurationFinished (StateType *state)
 
int64_t getCurrentStateCounter () const
 
ISmaccStategetCurrentState () const
 
const SmaccStateMachineInfogetStateMachineInfo ()
 
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::Publisher< smacc2_msgs::msg::SmaccEvent >::SharedPtr eventsLogPub_
 
rclcpp::Service< smacc2_msgs::srv::SmaccGetTransitionHistory >::SharedPtr transitionHistoryService_
 
std::vector< ISmaccState * > currentState_
 
std::shared_ptr< SmaccStateInfocurrentStateInfo_
 
smacc2_msgs::msg::SmaccStatus status_msg_
 
std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > orthogonals_
 
std::shared_ptr< SmaccStateMachineInfostateMachineInfo_
 

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_
 
SignalDetectorsignalDetector_
 
int64_t stateSeqCounter_
 

Friends

class ISmaccState
 
class SignalDetector
 

Detailed Description

Definition at line 63 of file smacc_state_machine.hpp.

Constructor & Destructor Documentation

◆ ISmaccStateMachine()

smacc2::ISmaccStateMachine::ISmaccStateMachine ( std::string stateMachineName,
SignalDetector * signalDetector,
rclcpp::NodeOptions nodeOptions = rclcpp::NodeOptions() )

Definition at line 35 of file smacc_state_machine.cpp.

37: nh_(nullptr), stateSeqCounter_(0)
38{
39 nh_ = rclcpp::Node::make_shared(stateMachineName, nodeOptions); //
40 RCLCPP_INFO_STREAM(
41 nh_->get_logger(), "Creating state machine base: " << nh_->get_fully_qualified_name());
42
43 signalDetector_ = signalDetector;
45
46 std::string runMode;
47 if (nh_->get_parameter("run_mode", runMode))
48 {
49 if (runMode == "debug")
50 {
52 }
53 else if (runMode == "release")
54 {
56 }
57 else
58 {
59 RCLCPP_ERROR(nh_->get_logger(), "Incorrect run_mode value: %s", runMode.c_str());
60 }
61 }
62 else
63 {
65 }
66}
void initialize(ISmaccStateMachine *stateMachine)

References smacc2::DEBUG, smacc2::SignalDetector::initialize(), nh_, smacc2::RELEASE, runMode_, and signalDetector_.

Here is the call graph for this function:

◆ ~ISmaccStateMachine()

smacc2::ISmaccStateMachine::~ISmaccStateMachine ( )
virtual

Definition at line 68 of file smacc_state_machine.cpp.

69{
70 RCLCPP_INFO(nh_->get_logger(), "Finishing State Machine");
71}

References nh_.

Member Function Documentation

◆ buildStateMachineInfo()

template<typename InitialStateType >
void smacc2::ISmaccStateMachine::buildStateMachineInfo ( )

Definition at line 745 of file smacc_state_machine_impl.hpp.

746{
747 this->stateMachineInfo_ = std::make_shared<SmaccStateMachineInfo>(this->getNode());
748 this->stateMachineInfo_->buildStateMachineInfo<InitialStateType>();
749 this->stateMachineInfo_->assembleSMStructureMessage(this);
751}
rclcpp::Node::SharedPtr getNode()
std::shared_ptr< SmaccStateMachineInfo > stateMachineInfo_

References checkStateMachineConsistence(), getNode(), and stateMachineInfo_.

Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkStateMachineConsistence()

void smacc2::ISmaccStateMachine::checkStateMachineConsistence ( )
protected

Definition at line 228 of file smacc_state_machine.cpp.

228{}

Referenced by buildStateMachineInfo().

Here is the caller graph for this function:

◆ createOrthogonal()

template<typename TOrthogonal >
void smacc2::ISmaccStateMachine::createOrthogonal ( )
protected

Definition at line 85 of file smacc_state_machine_impl.hpp.

86{
87 std::lock_guard<std::recursive_mutex> guard(m_mutex_);
88
89 std::string orthogonalkey = demangledTypeName<TOrthogonal>();
90
91 if (orthogonals_.count(orthogonalkey) == 0)
92 {
93 auto ret = std::make_shared<TOrthogonal>();
94 orthogonals_[orthogonalkey] = dynamic_pointer_cast<smacc2::ISmaccOrthogonal>(ret);
95
96 ret->setStateMachine(this);
97
98 RCLCPP_INFO(getLogger(), "%s Orthogonal is created", orthogonalkey.c_str());
99 }
100 else
101 {
102 RCLCPP_WARN_STREAM(
103 getLogger(), "There were already one existing orthogonal of type "
104 << orthogonalkey.c_str() << ". Skipping creation orthogonal request. ");
105 std::stringstream ss;
106 ss << "The existing orthogonals are the following: " << std::endl;
107 for (auto & orthogonal : orthogonals_)
108 {
109 ss << " - " << orthogonal.first << std::endl;
110 }
111 RCLCPP_WARN_STREAM(getLogger(), ss.str());
112 }
113}
std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > orthogonals_
std::string demangledTypeName()

References smacc2::introspection::demangledTypeName(), getLogger(), m_mutex_, and orthogonals_.

Here is the call graph for this function:

◆ createSignalConnection()

template<typename TSmaccSignal , typename TMemberFunctionPrototype , typename TSmaccObjectType >
smacc2::SmaccSignalConnection smacc2::ISmaccStateMachine::createSignalConnection ( TSmaccSignal & signal,
TMemberFunctionPrototype callback,
TSmaccObjectType * object )

Definition at line 406 of file smacc_state_machine_impl.hpp.

408{
409 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
410
411 static_assert(
412 std::is_base_of<ISmaccState, TSmaccObjectType>::value ||
413 std::is_base_of<ISmaccClient, TSmaccObjectType>::value ||
414 std::is_base_of<ISmaccClientBehavior, TSmaccObjectType>::value ||
415 std::is_base_of<StateReactor, TSmaccObjectType>::value ||
416 std::is_base_of<ISmaccComponent, TSmaccObjectType>::value,
417 "Only are accepted smacc types as subscribers for smacc signals");
418
419 typedef decltype(callback) ft;
420 Bind<boost::function_types::function_arity<ft>::value> binder;
422
423 // long life-time objects
424 if (
425 std::is_base_of<ISmaccComponent, TSmaccObjectType>::value ||
426 std::is_base_of<ISmaccClient, TSmaccObjectType>::value ||
427 std::is_base_of<ISmaccOrthogonal, TSmaccObjectType>::value ||
428 std::is_base_of<ISmaccStateMachine, TSmaccObjectType>::value)
429 {
430 RCLCPP_INFO(
431 getLogger(),
432 "[StateMachine] Long life-time SMACC signal subscription created. Subscriber is %s. Callback "
433 "is: %s",
435 demangleSymbol(typeid(callback).name()).c_str());
436
437 connection = binder.bindaux(signal, callback, object, nullptr);
438 }
439 else if (
440 std::is_base_of<ISmaccState, TSmaccObjectType>::value ||
441 std::is_base_of<StateReactor, TSmaccObjectType>::value ||
442 std::is_base_of<ISmaccClientBehavior, TSmaccObjectType>::value)
443 {
444 RCLCPP_INFO(
445 getLogger(),
446 "[StateMachine] Life-time constrained SMACC signal subscription created. Subscriber is %s",
448
449 std::shared_ptr<CallbackCounterSemaphore> callbackCounterSemaphore;
450 if (stateCallbackConnections.count(object))
451 {
452 callbackCounterSemaphore = stateCallbackConnections[object];
453 }
454 else
455 {
456 callbackCounterSemaphore =
457 std::make_shared<CallbackCounterSemaphore>(demangledTypeName<TSmaccObjectType>().c_str());
458 stateCallbackConnections[object] = callbackCounterSemaphore;
459 }
460
461 connection = binder.bindaux(signal, callback, object, callbackCounterSemaphore);
462 callbackCounterSemaphore->addConnection(connection);
463 }
464 else // state life-time objects
465 {
466 RCLCPP_WARN(
467 getLogger(),
468 "[StateMachine] Connecting signal to an unknown object with unknown lifetime "
469 "behavior. An exception may occur if the object is destroyed during the execution.");
470
471 connection = binder.bindaux(signal, callback, object, nullptr);
472 }
473
474 return connection;
475}
std::map< void *, std::shared_ptr< CallbackCounterSemaphore > > stateCallbackConnections
std::string demangleSymbol()
boost::signals2::connection SmaccSignalConnection

References smacc2::introspection::demangledTypeName(), smacc2::introspection::demangleSymbol(), getLogger(), m_mutex_, and stateCallbackConnections.

Referenced by smacc2::ISmaccClient::connectSignal(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onAborted(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onAborted(), smacc2::client_core_components::CpActionClient< ActionType >::onAborted(), cl_gcalcli::CpCalendarPoller::onAgendaUpdated(), cl_isaac_apriltag::CpAprilTagTracker::onAprilTagDetected(), cl_keyboard::components::CpKeyboardListener1::OnArrowPress(), cl_gcalcli::CpGcalcliConnection::onAuthenticationRequired(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onCancelled(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onCancelled(), smacc2::client_core_components::CpActionClient< ActionType >::onCancelled(), smacc2::client_core_components::CpSubprocessExecutor::onCommandCompleted(), smacc2::client_core_components::CpSubprocessExecutor::onCommandFailed(), cl_modbus_tcp_relay::CpModbusConnection::onConnectionError(), cl_gcalcli::CpGcalcliConnection::onConnectionLost(), cl_modbus_tcp_relay::CpModbusConnection::onConnectionLost(), cl_gcalcli::CpGcalcliConnection::onConnectionRestored(), cl_modbus_tcp_relay::CpModbusConnection::onConnectionRestored(), cl_gcalcli::CpCalendarEventListener::onEventDetected(), cl_gcalcli::CpCalendarEventListener::onEventEnded(), cl_gcalcli::CpCalendarEventListener::onEventStarted(), smacc2::client_core_components::CpServiceClient< ServiceType >::onFailure(), smacc2::SmaccAsyncClientBehavior::onFailure(), smacc2::client_core_components::CpActionClient< ActionType >::onFeedback(), smacc2::SmaccAsyncClientBehavior::onFinished(), smacc2::client_bases::SmaccSubscriberClient< MessageType >::onFirstMessageReceived(), smacc2::client_core_components::CpTopicSubscriber< MessageType >::onFirstMessageReceived(), cl_keyboard::components::CpKeyboardListener1::OnKeyPress(), smacc2::client_bases::SmaccSubscriberClient< MessageType >::onMessageReceived(), smacc2::client_core_components::CpTopicSubscriber< MessageType >::onMessageReceived(), cl_generic_sensor::components::CpMessageTimeout< MessageType >::onMessageTimeout(), cl_moveit2z::CpMoveGroupInterface::onMotionExecutionFailed(), cl_moveit2z::CpMoveGroupInterface::onMotionExecutionSucceeded(), cl_nav2z::components::CpNav2ActionInterface::onNavigationAborted(), cl_nav2z::components::CpNav2ActionInterface::onNavigationCancelled(), cl_nav2z::components::CpNav2ActionInterface::onNavigationFeedback(), cl_nav2z::components::CpNav2ActionInterface::onNavigationSucceeded(), cl_modbus_tcp_relay::CpModbusRelay::onReadComplete(), smacc2::client_core_components::CpServiceClient< ServiceType >::onRequestSent(), smacc2::client_core_components::CpServiceClient< ServiceType >::onResponse(), smacc2::client_bases::SmaccServiceServerClient< TService >::onServiceRequestReceived(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onSucceeded(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onSucceeded(), smacc2::client_core_components::CpActionClient< ActionType >::onSucceeded(), smacc2::SmaccAsyncClientBehavior::onSuccess(), cl_ros2_timer::CbTimerCountdownLoop::onTimerTick(), cl_ros2_timer::CbTimerCountdownOnce::onTimerTick(), smacc2::client_core_components::CpRos2Timer::onTimerTick(), cl_modbus_tcp_relay::CpModbusRelay::onWriteFailure(), cl_modbus_tcp_relay::CpModbusRelay::onWriteSuccess(), cl_http::CbHttpRequestBase::runtimeConfigure(), cl_px4_mr::CbArmPX4::wireCompletionSignals(), cl_px4_mr::CbChangeAltitude::wireCompletionSignals(), cl_px4_mr::CbDisarmPX4::wireCompletionSignals(), cl_px4_mr::CbFollowWaypoints::wireCompletionSignals(), cl_px4_mr::CbGoToLocation::wireCompletionSignals(), cl_px4_mr::CbLand::wireCompletionSignals(), cl_px4_mr::CbReturnToHome::wireCompletionSignals(), and cl_px4_mr::CbTakeOff::wireCompletionSignals().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnectSmaccSignalObject()

void smacc2::ISmaccStateMachine::disconnectSmaccSignalObject ( void * object)

Definition at line 73 of file smacc_state_machine.cpp.

74{
75 RCLCPP_INFO(nh_->get_logger(), "[SmaccSignal] Object signal disconnecting %ld", (long)object_ptr);
76 if (stateCallbackConnections.count(object_ptr) > 0)
77 {
78 auto callbackSemaphore = stateCallbackConnections[object_ptr];
79 callbackSemaphore->finalize();
80 stateCallbackConnections.erase(object_ptr);
81 }
82 else
83 {
84 RCLCPP_INFO(nh_->get_logger(), "[SmaccSignal] No signals found %ld", (long)object_ptr);
85 }
86}

References nh_, and stateCallbackConnections.

Referenced by notifyOnStateExited(), and smacc2::ISmaccOrthogonal::onDispose().

Here is the caller graph for this function:

◆ eStop()

void smacc2::ISmaccStateMachine::eStop ( )
virtual

◆ getClientBehavior()

template<typename TOrthogonal , typename TClientBehavior >
TClientBehavior * smacc2::ISmaccStateMachine::getClientBehavior ( int index = 0)
inline

Definition at line 84 of file smacc_state_machine.hpp.

85 {
86 auto orthogonal = this->template getOrthogonal<TOrthogonal>();
87
88 return orthogonal->template getClientBehavior<TClientBehavior>(index);
89 }
TClientBehavior * getClientBehavior(int index=0)

References getClientBehavior(), and getOrthogonal().

Referenced by smacc2::ISmaccState::getClientBehavior(), and getClientBehavior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCurrentState()

ISmaccState * smacc2::ISmaccStateMachine::getCurrentState ( ) const
inline

Definition at line 755 of file smacc_state_machine_impl.hpp.

755{ return this->currentState_.back(); }
std::vector< ISmaccState * > currentState_

References currentState_.

Referenced by cl_nav2z::CpWaypointNavigator::sendNextGoal().

Here is the caller graph for this function:

◆ getCurrentStateCounter()

int64_t smacc2::ISmaccStateMachine::getCurrentStateCounter ( ) const
inline

Definition at line 753 of file smacc_state_machine_impl.hpp.

753{ return this->stateSeqCounter_; }

References stateSeqCounter_.

◆ getCurrentStateInfo()

std::shared_ptr< SmaccStateInfo > smacc2::ISmaccStateMachine::getCurrentStateInfo ( )
inline

Definition at line 118 of file smacc_state_machine.hpp.

118{ return currentStateInfo_; }
std::shared_ptr< SmaccStateInfo > currentStateInfo_

References currentStateInfo_.

◆ getGlobalSMData()

template<typename T >
bool smacc2::ISmaccStateMachine::getGlobalSMData ( std::string name,
T & ret )

Definition at line 240 of file smacc_state_machine_impl.hpp.

241{
242 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
243 // RCLCPP_WARN(getLogger(),"get SM Data lock acquire");
244 bool success = false;
245
246 if (!globalData_.count(name))
247 {
248 // RCLCPP_WARN(getLogger(),"get SM Data - data do not exist");
249 success = false;
250 }
251 else
252 {
253 // RCLCPP_WARN(getLogger(),"get SM DAta -data exist. accessing");
254 try
255 {
256 auto & v = globalData_[name];
257
258 // RCLCPP_WARN(getLogger(),"get SM DAta -data exist. any cast");
259 ret = boost::any_cast<T>(v.second);
260 success = true;
261 // RCLCPP_WARN(getLogger(),"get SM DAta -data exist. success");
262 }
263 catch (boost::bad_any_cast & ex)
264 {
265 RCLCPP_ERROR(getLogger(), "bad any cast: %s", ex.what());
266 success = false;
267 }
268 }
269
270 // RCLCPP_WARN(getLogger(),"get SM Data lock release");
271 return success;
272}
std::map< std::string, std::pair< std::function< std::string()>, boost::any > > globalData_

References getLogger(), globalData_, and m_mutex_.

Referenced by smacc2::ISmaccOrthogonal::getGlobalSMData(), and smacc2::ISmaccState::getGlobalSMData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLogger()

◆ getMutex()

std::recursive_mutex & smacc2::ISmaccStateMachine::getMutex ( )
inline

Definition at line 167 of file smacc_state_machine.hpp.

167{ return this->m_mutex_; }

References m_mutex_.

◆ getNode()

◆ getOrthogonal()

template<typename TOrthogonal >
TOrthogonal * smacc2::ISmaccStateMachine::getOrthogonal ( )

Definition at line 47 of file smacc_state_machine_impl.hpp.

48{
49 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
50
51 std::string orthogonalkey = demangledTypeName<TOrthogonal>();
52 TOrthogonal * ret;
53
54 auto it = orthogonals_.find(orthogonalkey);
55
56 if (it != orthogonals_.end())
57 {
58 RCLCPP_DEBUG(
59 getLogger(),
60 "Orthogonal %s resource is being required from some state, client or component. Found "
61 "resource in "
62 "cache.",
63 orthogonalkey.c_str());
64 ret = dynamic_cast<TOrthogonal *>(it->second.get());
65 return ret;
66 }
67 else
68 {
69 std::stringstream ss;
70 ss << "Orthogonal not found " << orthogonalkey.c_str() << std::endl;
71 ss << "The existing orthogonals are the following: " << std::endl;
72 for (auto & orthogonal : orthogonals_)
73 {
74 ss << " - " << orthogonal.first << std::endl;
75 }
76
77 RCLCPP_WARN_STREAM(getLogger(), ss.str());
78
79 return nullptr;
80 }
81}

References smacc2::introspection::demangledTypeName(), getLogger(), m_mutex_, and orthogonals_.

Referenced by getClientBehavior(), and smacc2::ISmaccState::getOrthogonal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getOrthogonals()

const std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > & smacc2::ISmaccStateMachine::getOrthogonals ( ) const

◆ getStateMachineInfo()

const smacc2::introspection::SmaccStateMachineInfo & smacc2::ISmaccStateMachine::getStateMachineInfo ( )
inline

Definition at line 757 of file smacc_state_machine_impl.hpp.

758{
759 return *this->stateMachineInfo_;
760}

References stateMachineInfo_.

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getStateInfo().

Here is the caller graph for this function:

◆ getStateMachineName()

std::string smacc2::ISmaccStateMachine::getStateMachineName ( )

Definition at line 223 of file smacc_state_machine.cpp.

224{
225 return demangleSymbol(typeid(*this).name());
226}

References smacc2::introspection::demangleSymbol().

Here is the call graph for this function:

◆ getTransitionLogHistory()

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 184 of file smacc_state_machine.cpp.

188{
189 RCLCPP_WARN(
190 nh_->get_logger(), "Requesting transition log history, current size: %ld",
191 this->transitionLogHistory_.size());
192 res->history = this->transitionLogHistory_;
193}
std::vector< smacc2_msgs::msg::SmaccTransitionLogEntry > transitionLogHistory_

References nh_, and transitionLogHistory_.

Referenced by initializeROS().

Here is the caller graph for this function:

◆ initializeROS()

void smacc2::ISmaccStateMachine::initializeROS ( std::string smshortname)
protected

Definition at line 158 of file smacc_state_machine.cpp.

159{
160 RCLCPP_WARN_STREAM(nh_->get_logger(), "State machine base creation: " << shortname);
161 // STATE MACHINE TOPICS
162 stateMachinePub_ = nh_->create_publisher<smacc2_msgs::msg::SmaccStateMachine>(
163 shortname + "/smacc/state_machine_description", rclcpp::QoS(1));
164 stateMachineStatusPub_ = nh_->create_publisher<smacc2_msgs::msg::SmaccStatus>(
165 shortname + "/smacc/status", rclcpp::QoS(1));
166 transitionLogPub_ = nh_->create_publisher<smacc2_msgs::msg::SmaccTransitionLogEntry>(
167 shortname + "/smacc/transition_log", rclcpp::QoS(1));
168
169 eventsLogPub_ = nh_->create_publisher<smacc2_msgs::msg::SmaccEvent>(
170 shortname + "/smacc/event_log", rclcpp::QoS(100));
171
172 // STATE MACHINE SERVICES
173 transitionHistoryService_ = nh_->create_service<smacc2_msgs::srv::SmaccGetTransitionHistory>(
174 shortname + "/smacc/transition_log_history",
175 std::bind(
176 &ISmaccStateMachine::getTransitionLogHistory, this, std::placeholders::_1,
177 std::placeholders::_2, std::placeholders::_3));
178
179 // Notify signal detector that ROS initialization is complete
180 // This allows the polling loop to start safely accessing ROS objects
182}
rclcpp::Publisher< smacc2_msgs::msg::SmaccStateMachine >::SharedPtr stateMachinePub_
rclcpp::Service< smacc2_msgs::srv::SmaccGetTransitionHistory >::SharedPtr transitionHistoryService_
rclcpp::Publisher< smacc2_msgs::msg::SmaccStatus >::SharedPtr stateMachineStatusPub_
rclcpp::Publisher< smacc2_msgs::msg::SmaccTransitionLogEntry >::SharedPtr transitionLogPub_
rclcpp::Publisher< smacc2_msgs::msg::SmaccEvent >::SharedPtr eventsLogPub_
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)

References eventsLogPub_, getTransitionLogHistory(), nh_, smacc2::SignalDetector::notifyRosInitialized(), signalDetector_, stateMachinePub_, stateMachineStatusPub_, transitionHistoryService_, and transitionLogPub_.

Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lockStateMachine()

void smacc2::ISmaccStateMachine::lockStateMachine ( std::string msg)
private

Definition at line 211 of file smacc_state_machine.cpp.

212{
213 RCLCPP_DEBUG(nh_->get_logger(), "-- locking SM: %s", msg.c_str());
214 m_mutex_.lock();
215}

References m_mutex_, and nh_.

Referenced by notifyOnStateExited().

Here is the caller graph for this function:

◆ notifyOnRuntimeConfigurationFinished()

template<typename StateType >
void smacc2::ISmaccStateMachine::notifyOnRuntimeConfigurationFinished ( StateType * state)

Definition at line 562 of file smacc_state_machine_impl.hpp.

563{
564 for (auto pair : this->orthogonals_)
565 {
566 // RCLCPP_INFO(getLogger(),"ortho onruntime configure: %s", pair.second->getName().c_str());
567 auto & orthogonal = pair.second;
568 orthogonal->runtimeConfigure();
569 }
570
571 {
572 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
573 this->updateStatusMessage();
575
577 }
578}
StateMachineInternalAction stateMachineCurrentAction
void notifyStateConfigured(ISmaccState *currentState)

References currentState_, m_mutex_, smacc2::SignalDetector::notifyStateConfigured(), orthogonals_, signalDetector_, smacc2::STATE_ENTERING, stateMachineCurrentAction, and updateStatusMessage().

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notifyOnRuntimeConfigured()

template<typename StateType >
void smacc2::ISmaccStateMachine::notifyOnRuntimeConfigured ( StateType * state)

◆ notifyOnStateEntryEnd()

template<typename StateType >
void smacc2::ISmaccStateMachine::notifyOnStateEntryEnd ( StateType * state)

Definition at line 494 of file smacc_state_machine_impl.hpp.

495{
496 RCLCPP_INFO(
497 getLogger(), "[%s] State OnEntry code finished.",
498 demangleSymbol(typeid(StateType).name()).c_str());
499
500 auto currentState = this->currentState_.back();
501 for (auto pair : this->orthogonals_)
502 {
503 RCLCPP_DEBUG(getLogger(), "Orthogonal onEntry: %s.", pair.second->getName().c_str());
504 auto & orthogonal = pair.second;
505 try
506 {
507 orthogonal->onEntry();
508 }
509 catch (const std::exception & e)
510 {
511 RCLCPP_ERROR(
512 getLogger(),
513 "[Orthogonal %s] Exception on Entry - continuing with next orthogonal. Exception info: %s",
514 pair.second->getName().c_str(), e.what());
515 }
516 }
517
518 for (auto & sr : currentState->getStateReactors())
519 {
520 auto srname = smacc2::demangleSymbol(typeid(*sr).name());
521 RCLCPP_INFO_STREAM(getLogger(), "State reactor onEntry: " << srname);
522 try
523 {
524 sr->onEntry();
525 }
526 catch (const std::exception & e)
527 {
528 RCLCPP_ERROR(
529 getLogger(),
530 "[State Reactor %s] Exception on Entry - continuing with next state reactor. Exception "
531 "info: %s",
532 srname.c_str(), e.what());
533 }
534 }
535
536 for (auto & eg : currentState->getEventGenerators())
537 {
538 auto egname = smacc2::demangleSymbol(typeid(*eg).name());
539 RCLCPP_INFO_STREAM(getLogger(), "Event generator onEntry: " << egname);
540 try
541 {
542 eg->onEntry();
543 }
544 catch (const std::exception & e)
545 {
546 RCLCPP_ERROR(
547 getLogger(),
548 "[Event generator %s] Exception on Entry - continuing with next state reactor. Exception "
549 "info: %s",
550 egname.c_str(), e.what());
551 }
552 }
553
554 {
555 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
556 this->updateStatusMessage();
558 }
559}

References currentState_, smacc2::introspection::demangleSymbol(), getLogger(), m_mutex_, orthogonals_, smacc2::STATE_RUNNING, stateMachineCurrentAction, and updateStatusMessage().

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notifyOnStateEntryStart()

template<typename StateType >
void smacc2::ISmaccStateMachine::notifyOnStateEntryStart ( StateType * state)

Definition at line 478 of file smacc_state_machine_impl.hpp.

479{
480 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
481
482 RCLCPP_DEBUG(
483 getLogger(),
484 "[State Machine] Initializing a new state '%s' and updating current state. Getting state "
485 "meta-information. number of orthogonals: %ld",
486 demangleSymbol(typeid(StateType).name()).c_str(), this->orthogonals_.size());
487
489 currentState_.push_back(state);
490 currentStateInfo_ = stateMachineInfo_->getState<StateType>();
491}

References currentState_, currentStateInfo_, smacc2::introspection::demangleSymbol(), getLogger(), m_mutex_, orthogonals_, stateMachineInfo_, and stateSeqCounter_.

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notifyOnStateExited()

template<typename StateType >
void smacc2::ISmaccStateMachine::notifyOnStateExited ( StateType * state)

Definition at line 648 of file smacc_state_machine_impl.hpp.

649{
650 this->lockStateMachine("state exit");
651
653
654 auto fullname = demangleSymbol(typeid(StateType).name());
655 RCLCPP_WARN_STREAM(getLogger(), "Exiting state: " << fullname);
656
657 RCLCPP_INFO_STREAM(getLogger(), "Notification state disposing: leaving state" << state);
658 for (auto pair : this->orthogonals_)
659 {
660 auto & orthogonal = pair.second;
661 try
662 {
663 orthogonal->onDispose();
664 }
665 catch (const std::exception & e)
666 {
667 RCLCPP_ERROR(
668 getLogger(),
669 "[Orthogonal %s] Exception onDispose - continuing with next orthogonal. Exception info: %s",
670 pair.second->getName().c_str(), e.what());
671 }
672 }
673
674 for (auto & sr : state->getStateReactors())
675 {
676 auto srname = smacc2::demangleSymbol(typeid(*sr).name()).c_str();
677 RCLCPP_INFO(getLogger(), "State reactor disposing: %s", srname);
678 try
679 {
680 this->disconnectSmaccSignalObject(sr.get());
681 }
682 catch (const std::exception & e)
683 {
684 RCLCPP_ERROR(
685 getLogger(),
686 "[State Reactor %s] Exception on OnDispose - continuing with next state reactor. Exception "
687 "info: %s",
688 srname, e.what());
689 }
690 }
691
692 for (auto & eg : state->getEventGenerators())
693 {
694 auto egname = smacc2::demangleSymbol(typeid(*eg).name()).c_str();
695 RCLCPP_INFO(getLogger(), "Event generator disposing: %s", egname);
696 try
697 {
698 this->disconnectSmaccSignalObject(eg.get());
699 }
700 catch (const std::exception & e)
701 {
702 RCLCPP_ERROR(
703 getLogger(),
704 "[State Reactor %s] Exception on OnDispose - continuing with next state reactor. Exception "
705 "info: %s",
706 egname, e.what());
707 }
708 }
709
710 // NOTE: do NOT clear stateCallbackConnections here. Entries are erased
711 // per-object by disconnectSmaccSignalObject when each owner is disposed
712 // (behaviors via orthogonal onDispose, state reactors and event generators
713 // above). A blanket clear also dropped - without finalizing - the entries of
714 // container-state behaviors that outlive this inner state exit, so their
715 // boost connections were never disconnected and the next signal emission
716 // invoked a callback on a destroyed object (use-after-free segfault).
717 currentState_.pop_back();
718
719 // then call exit state
720 RCLCPP_WARN_STREAM(getLogger(), "State exit: " << fullname);
721
723 this->unlockStateMachine("state exit");
724}
void lockStateMachine(std::string msg)
void disconnectSmaccSignalObject(void *object)
void unlockStateMachine(std::string msg)
void notifyStateExited(ISmaccState *currentState)

References currentState_, smacc2::introspection::demangleSymbol(), disconnectSmaccSignalObject(), getLogger(), lockStateMachine(), smacc2::SignalDetector::notifyStateExited(), orthogonals_, signalDetector_, stateMachineCurrentAction, smacc2::TRANSITIONING, and unlockStateMachine().

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::exit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notifyOnStateExiting()

template<typename StateType >
void smacc2::ISmaccStateMachine::notifyOnStateExiting ( StateType * state)

Definition at line 587 of file smacc_state_machine_impl.hpp.

588{
590 auto fullname = demangleSymbol(typeid(StateType).name());
591 RCLCPP_WARN_STREAM(getLogger(), "Exiting state: " << fullname);
592
593 RCLCPP_INFO_STREAM(getLogger(), "Notification state exit: leaving state " << state);
594 for (auto pair : this->orthogonals_)
595 {
596 auto & orthogonal = pair.second;
597 try
598 {
599 orthogonal->onExit();
600 }
601 catch (const std::exception & e)
602 {
603 RCLCPP_ERROR(
604 getLogger(),
605 "[Orthogonal %s] Exception onExit - continuing with next orthogonal. Exception info: %s",
606 pair.second->getName().c_str(), e.what());
607 }
608 }
609
610 for (auto & sr : state->getStateReactors())
611 {
612 auto srname = smacc2::demangleSymbol(typeid(*sr).name());
613 RCLCPP_INFO_STREAM(getLogger(), "State reactor OnExit: " << srname);
614 try
615 {
616 sr->onExit();
617 }
618 catch (const std::exception & e)
619 {
620 RCLCPP_ERROR(
621 getLogger(),
622 "[State Reactor %s] Exception on OnExit - continuing with next state reactor. Exception "
623 "info: %s",
624 srname.c_str(), e.what());
625 }
626 }
627
628 for (auto & eg : state->getEventGenerators())
629 {
630 auto egname = smacc2::demangleSymbol(typeid(*eg).name());
631 RCLCPP_INFO_STREAM(getLogger(), "Event generator OnExit: " << egname);
632 try
633 {
634 eg->onExit();
635 }
636 catch (const std::exception & e)
637 {
638 RCLCPP_ERROR(
639 getLogger(),
640 "[State Reactor %s] Exception on OnExit - continuing with next state reactor. Exception "
641 "info: %s",
642 egname.c_str(), e.what());
643 }
644 }
645}

References smacc2::introspection::demangleSymbol(), getLogger(), orthogonals_, smacc2::STATE_EXITING, and stateMachineCurrentAction.

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::exit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onInitialize()

void smacc2::ISmaccStateMachine::onInitialize ( )
virtual

this function should be implemented by the user to create the orthogonals

Definition at line 149 of file smacc_state_machine.cpp.

149{}

Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl().

Here is the caller graph for this function:

◆ onInitialized()

void smacc2::ISmaccStateMachine::onInitialized ( )
protected

Definition at line 151 of file smacc_state_machine.cpp.

152{
153 auto ros_clock = rclcpp::Clock::make_shared();
154 timer_ =
155 rclcpp::create_timer(nh_, ros_clock, 0.5s, [=]() { this->state_machine_visualization(); });
156}
rclcpp::TimerBase::SharedPtr timer_

References nh_, state_machine_visualization(), and timer_.

Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ postEvent() [1/2]

template<typename EventType >
void smacc2::ISmaccStateMachine::postEvent ( EventLifeTime evlifetime = EventLifeTime::ABSOLUTE)

Definition at line 231 of file smacc_state_machine_impl.hpp.

232{
234 RCLCPP_INFO_STREAM(getLogger(), "Event: " << evname);
235 auto * ev = new EventType();
236 this->postEvent(ev, evlifetime);
237}
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)

References smacc2::introspection::demangleSymbol(), getLogger(), and postEvent().

Here is the call graph for this function:

◆ postEvent() [2/2]

template<typename EventType >
void smacc2::ISmaccStateMachine::postEvent ( EventType * ev,
EventLifeTime evlifetime = EventLifeTime::ABSOLUTE )

Definition at line 177 of file smacc_state_machine_impl.hpp.

178{
179 std::lock_guard<std::recursive_mutex> guard(eventQueueMutex_);
180
181#define eventtypename demangleSymbol<EventType>().c_str()
182
183 TRACETOOLS_TRACEPOINT(smacc2_event, eventtypename);
184
185 {
186 auto evinfo = SmaccEventInfo(TypeInfo::getTypeInfoFromType<EventType>());
187 EventLabel<EventType>(evinfo.label);
188
189 smacc2_msgs::msg::SmaccEvent event;
190 event.event_type = evinfo.getEventTypeName();
191 event.event_source = evinfo.getEventSourceName();
192 event.event_object_tag = evinfo.getOrthogonalName();
193 event.label = evinfo.label;
194
195 if (this->eventsLogPub_)
196 {
197 this->eventsLogPub_->publish(event);
198 }
199 }
200
201 if (
202 evlifetime == EventLifeTime::CURRENT_STATE &&
205 {
206 RCLCPP_WARN_STREAM(
207 getLogger(),
208 "[ISmaccStateMachine] CURRENT STATE SCOPED EVENT DISCARDED, state is exiting/transitioning "
209 << eventtypename);
210 return;
211 // in this case we may lose/skip events, if this is not right for some cases we should create a
212 // queue to lock the events during the transitions. This issues appeared when a client
213 // asyncbehavior was posting an event meanwhile we were doing the transition, but the main
214 // thread was waiting for its correct finalization (with thread.join)
215 }
216
217 // when a postting event is requested by any component, client, or client behavior
218 // we reach this place. Now, we propagate the events to all the state state reactors to generate
219 // some more events
220
221 RCLCPP_DEBUG_STREAM(getLogger(), "[PostEvent entry point] " << eventtypename);
222 if (!currentState_.empty())
223 {
225 }
226
227 this->signalDetector_->postEvent(ev);
228}
std::recursive_mutex eventQueueMutex_
void propagateEventToStateReactors(ISmaccState *st, EventType *ev)
static TypeInfo::Ptr getTypeInfoFromType()
std::enable_if< HasEventLabel< T >::value, void >::type EventLabel(std::string &label)
#define eventtypename
smacc2_event

References smacc2::CURRENT_STATE, currentState_, smacc2::introspection::EventLabel(), eventQueueMutex_, eventsLogPub_, eventtypename, getLogger(), smacc2::introspection::TypeInfo::getTypeInfoFromType(), smacc2::SignalDetector::postEvent(), propagateEventToStateReactors(), signalDetector_, smacc2_event, smacc2::STATE_EXITING, stateMachineCurrentAction, and smacc2::TRANSITIONING.

Referenced by smacc2::ISmaccClient::postEvent(), smacc2::ISmaccClient::postEvent(), smacc2::ISmaccClientBehavior::postEvent(), smacc2::ISmaccComponent::postEvent(), smacc2::ISmaccComponent::postEvent(), smacc2::ISmaccState::postEvent(), smacc2::ISmaccState::postEvent(), postEvent(), and smacc2::StateReactor::setOutputEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ propagateEventToStateReactors()

template<typename EventType >
void smacc2::ISmaccStateMachine::propagateEventToStateReactors ( ISmaccState * st,
EventType * ev )
private

Definition at line 727 of file smacc_state_machine_impl.hpp.

728{
729 RCLCPP_DEBUG(
730 getLogger(), "PROPAGATING EVENT [%s] TO SRs [%s]: ", demangleSymbol<EventType>().c_str(),
731 st->getClassName().c_str());
732 for (auto & sb : st->getStateReactors())
733 {
734 sb->notifyEvent(ev);
735 }
736
737 auto * pst = st->getParentState();
738 if (pst != nullptr)
739 {
741 }
742}

References smacc2::introspection::demangleSymbol(), smacc2::ISmaccState::getClassName(), getLogger(), smacc2::ISmaccState::getParentState(), smacc2::ISmaccState::getStateReactors(), and propagateEventToStateReactors().

Referenced by postEvent(), and propagateEventToStateReactors().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publishTransition()

void smacc2::ISmaccStateMachine::publishTransition ( const SmaccTransitionInfo & transitionInfo)

Definition at line 139 of file smacc_state_machine.cpp.

140{
141 smacc2_msgs::msg::SmaccTransitionLogEntry transitionLogEntry;
142 transitionLogEntry.timestamp = this->nh_->now();
143 transitionInfoToMsg(transitionInfo, transitionLogEntry.transition);
144 this->transitionLogHistory_.push_back(transitionLogEntry);
145
146 transitionLogPub_->publish(transitionLogEntry);
147}
void transitionInfoToMsg(const SmaccTransitionInfo &transition, smacc2_msgs::msg::SmaccTransition &transitionMsg)

References nh_, smacc2::introspection::transitionInfoToMsg(), transitionLogHistory_, and transitionLogPub_.

Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl(), and smacc2::ISmaccState::notifyTransitionFromTransitionTypeInfo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ requiresComponent() [1/2]

template<typename SmaccComponentType >
void smacc2::ISmaccStateMachine::requiresComponent ( SmaccComponentType *& storage,
ComponentRequirement requirementType )

Definition at line 117 of file smacc_state_machine_impl.hpp.

119{
120 bool throwsException = requirementType == ComponentRequirement::HARD;
121 RCLCPP_DEBUG(
122 getLogger(), "component %s is required",
123 demangleSymbol(typeid(SmaccComponentType).name()).c_str());
124 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
125
126 for (auto ortho : this->orthogonals_)
127 {
128 for (auto & client : ortho.second->clients_)
129 {
130 storage = client->getComponent<SmaccComponentType>();
131 if (storage != nullptr)
132 {
133 return;
134 }
135 }
136 }
137
138 RCLCPP_WARN(
139 getLogger(), "component %s is required but it was not found in any orthogonal",
140 demangleSymbol(typeid(SmaccComponentType).name()).c_str());
141
142 if (throwsException)
143 throw std::runtime_error("component is required but it was not found in any orthogonal");
144}

References smacc2::introspection::demangleSymbol(), getLogger(), smacc2::HARD, m_mutex_, and orthogonals_.

Referenced by smacc2::ISmaccClientBehavior::requiresComponent(), smacc2::ISmaccClientBehavior::requiresComponent(), smacc2::ISmaccOrthogonal::requiresComponent(), and smacc2::ISmaccState::requiresComponent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ requiresComponent() [2/2]

template<typename SmaccComponentType >
void smacc2::ISmaccStateMachine::requiresComponent ( std::string name,
SmaccComponentType *& storage,
ComponentRequirement requirementType )

Definition at line 147 of file smacc_state_machine_impl.hpp.

149{
150 bool throwsException = requirementType == ComponentRequirement::HARD;
151 RCLCPP_DEBUG(
152 getLogger(), "component %s (named '%s') is required",
153 demangleSymbol(typeid(SmaccComponentType).name()).c_str(), name.c_str());
154 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
155
156 for (auto ortho : this->orthogonals_)
157 {
158 for (auto & client : ortho.second->clients_)
159 {
160 storage = client->getComponent<SmaccComponentType>(name);
161 if (storage != nullptr)
162 {
163 return;
164 }
165 }
166 }
167
168 RCLCPP_WARN(
169 getLogger(), "component %s (named '%s') is required but it was not found in any orthogonal",
170 demangleSymbol(typeid(SmaccComponentType).name()).c_str(), name.c_str());
171
172 if (throwsException)
173 throw std::runtime_error("named component is required but it was not found in any orthogonal");
174}

References smacc2::introspection::demangleSymbol(), getLogger(), smacc2::HARD, m_mutex_, and orthogonals_.

Here is the call graph for this function:

◆ reset()

void smacc2::ISmaccStateMachine::reset ( )
virtual

◆ setGlobalSMData()

template<typename T >
void smacc2::ISmaccStateMachine::setGlobalSMData ( std::string name,
T value )

Definition at line 275 of file smacc_state_machine_impl.hpp.

276{
277 {
278 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
279 // RCLCPP_WARN(getLogger(),"set SM Data lock acquire");
280
281 globalData_[name] = {
282 [this, name]()
283 {
284 std::stringstream ss;
285 auto val = any_cast<T>(globalData_[name].second);
286 ss << val;
287 return ss.str();
288 },
289 value};
290 }
291
292 this->updateStatusMessage();
293}

References globalData_, m_mutex_, and updateStatusMessage().

Referenced by smacc2::ISmaccOrthogonal::setGlobalSMData(), and smacc2::ISmaccState::setGlobalSMData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ state_machine_visualization()

void smacc2::ISmaccStateMachine::state_machine_visualization ( )

Definition at line 195 of file smacc_state_machine.cpp.

196{
197 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
198
199 smacc2_msgs::msg::SmaccStateMachine state_machine_msg;
200 state_machine_msg.states = stateMachineInfo_->stateMsgs;
201
202 std::sort(
203 state_machine_msg.states.begin(), state_machine_msg.states.end(),
204 [](auto & a, auto & b) { return a.index < b.index; });
205 stateMachinePub_->publish(state_machine_msg);
206
207 status_msg_.header.stamp = this->nh_->now();
209}
smacc2_msgs::msg::SmaccStatus status_msg_

References m_mutex_, nh_, stateMachineInfo_, stateMachinePub_, stateMachineStatusPub_, and status_msg_.

Referenced by onInitialized().

Here is the caller graph for this function:

◆ stop()

void smacc2::ISmaccStateMachine::stop ( )
virtual

◆ unlockStateMachine()

void smacc2::ISmaccStateMachine::unlockStateMachine ( std::string msg)
private

Definition at line 217 of file smacc_state_machine.cpp.

218{
219 RCLCPP_DEBUG(nh_->get_logger(), "-- unlocking SM: %s", msg.c_str());
220 m_mutex_.unlock();
221}

References m_mutex_, and nh_.

Referenced by notifyOnStateExited().

Here is the caller graph for this function:

◆ updateStatusMessage()

void smacc2::ISmaccStateMachine::updateStatusMessage ( )
private

Definition at line 102 of file smacc_state_machine.cpp.

103{
104 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
105
106 if (currentStateInfo_ != nullptr)
107 {
108 RCLCPP_WARN_STREAM(
109 nh_->get_logger(),
110 "[StateMachine] Setting state active: " << currentStateInfo_->getFullPath());
111
113 {
114 status_msg_.current_states.clear();
115 std::list<const SmaccStateInfo *> ancestorList;
116 currentStateInfo_->getAncestors(ancestorList);
117
118 for (auto & ancestor : ancestorList)
119 {
120 status_msg_.current_states.push_back(ancestor->toShortName());
121 }
122
123 status_msg_.global_variable_names.clear();
124 status_msg_.global_variable_values.clear();
125
126 for (auto entry : this->globalData_)
127 {
128 status_msg_.global_variable_names.push_back(entry.first);
129 status_msg_.global_variable_values.push_back(
130 entry.second.first()); // <- invoke to_string()
131 }
132
133 status_msg_.header.stamp = this->nh_->now();
135 }
136 }
137}

References currentStateInfo_, smacc2::DEBUG, globalData_, m_mutex_, nh_, runMode_, stateMachineStatusPub_, and status_msg_.

Referenced by notifyOnRuntimeConfigurationFinished(), notifyOnStateEntryEnd(), and setGlobalSMData().

Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ ISmaccState

friend class ISmaccState
friend

Definition at line 235 of file smacc_state_machine.hpp.

◆ SignalDetector

friend class SignalDetector
friend

Definition at line 236 of file smacc_state_machine.hpp.

Member Data Documentation

◆ currentState_

std::vector<ISmaccState *> smacc2::ISmaccStateMachine::currentState_
protected

◆ currentStateInfo_

std::shared_ptr<SmaccStateInfo> smacc2::ISmaccStateMachine::currentStateInfo_
protected

◆ eventQueueMutex_

std::recursive_mutex smacc2::ISmaccStateMachine::eventQueueMutex_
private

Definition at line 207 of file smacc_state_machine.hpp.

Referenced by postEvent().

◆ eventsLogPub_

rclcpp::Publisher<smacc2_msgs::msg::SmaccEvent>::SharedPtr smacc2::ISmaccStateMachine::eventsLogPub_
protected

Definition at line 187 of file smacc_state_machine.hpp.

Referenced by initializeROS(), and postEvent().

◆ globalData_

std::map<std::string, std::pair<std::function<std::string()>, boost::any> > smacc2::ISmaccStateMachine::globalData_
private

Definition at line 214 of file smacc_state_machine.hpp.

Referenced by getGlobalSMData(), setGlobalSMData(), and updateStatusMessage().

◆ m_mutex_

◆ nh_

◆ orthogonals_

◆ runMode_

smacc2::SMRunMode smacc2::ISmaccStateMachine::runMode_
private

Definition at line 219 of file smacc_state_machine.hpp.

Referenced by ISmaccStateMachine(), and updateStatusMessage().

◆ signalDetector_

SignalDetector* smacc2::ISmaccStateMachine::signalDetector_
private

◆ stateCallbackConnections

std::map<void *, std::shared_ptr<CallbackCounterSemaphore> > smacc2::ISmaccStateMachine::stateCallbackConnections
private

Definition at line 211 of file smacc_state_machine.hpp.

Referenced by createSignalConnection(), and disconnectSmaccSignalObject().

◆ stateMachineCurrentAction

◆ stateMachineInfo_

◆ stateMachinePub_

rclcpp::Publisher<smacc2_msgs::msg::SmaccStateMachine>::SharedPtr smacc2::ISmaccStateMachine::stateMachinePub_
protected

Definition at line 183 of file smacc_state_machine.hpp.

Referenced by initializeROS(), and state_machine_visualization().

◆ stateMachineStatusPub_

rclcpp::Publisher<smacc2_msgs::msg::SmaccStatus>::SharedPtr smacc2::ISmaccStateMachine::stateMachineStatusPub_
protected

◆ stateSeqCounter_

int64_t smacc2::ISmaccStateMachine::stateSeqCounter_
private

Definition at line 224 of file smacc_state_machine.hpp.

Referenced by getCurrentStateCounter(), and notifyOnStateEntryStart().

◆ status_msg_

smacc2_msgs::msg::SmaccStatus smacc2::ISmaccStateMachine::status_msg_
protected

Definition at line 197 of file smacc_state_machine.hpp.

Referenced by state_machine_visualization(), and updateStatusMessage().

◆ timer_

rclcpp::TimerBase::SharedPtr smacc2::ISmaccStateMachine::timer_
protected

Definition at line 182 of file smacc_state_machine.hpp.

Referenced by onInitialized().

◆ transitionHistoryService_

rclcpp::Service<smacc2_msgs::srv::SmaccGetTransitionHistory>::SharedPtr smacc2::ISmaccStateMachine::transitionHistoryService_
protected

Definition at line 189 of file smacc_state_machine.hpp.

Referenced by initializeROS().

◆ transitionLogHistory_

std::vector<smacc2_msgs::msg::SmaccTransitionLogEntry> smacc2::ISmaccStateMachine::transitionLogHistory_
private

Definition at line 217 of file smacc_state_machine.hpp.

Referenced by getTransitionLogHistory(), and publishTransition().

◆ transitionLogPub_

rclcpp::Publisher<smacc2_msgs::msg::SmaccTransitionLogEntry>::SharedPtr smacc2::ISmaccStateMachine::transitionLogPub_
protected

Definition at line 185 of file smacc_state_machine.hpp.

Referenced by initializeROS(), and publishTransition().


The documentation for this class was generated from the following files: