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 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 709 of file smacc_state_machine_impl.hpp.

710{
711 this->stateMachineInfo_ = std::make_shared<SmaccStateMachineInfo>(this->getNode());
712 this->stateMachineInfo_->buildStateMachineInfo<InitialStateType>();
713 this->stateMachineInfo_->assembleSMStructureMessage(this);
715}
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 376 of file smacc_state_machine_impl.hpp.

378{
379 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
380
381 static_assert(
382 std::is_base_of<ISmaccState, TSmaccObjectType>::value ||
383 std::is_base_of<ISmaccClient, TSmaccObjectType>::value ||
384 std::is_base_of<ISmaccClientBehavior, TSmaccObjectType>::value ||
385 std::is_base_of<StateReactor, TSmaccObjectType>::value ||
386 std::is_base_of<ISmaccComponent, TSmaccObjectType>::value,
387 "Only are accepted smacc types as subscribers for smacc signals");
388
389 typedef decltype(callback) ft;
390 Bind<boost::function_types::function_arity<ft>::value> binder;
392
393 // long life-time objects
394 if (
395 std::is_base_of<ISmaccComponent, TSmaccObjectType>::value ||
396 std::is_base_of<ISmaccClient, TSmaccObjectType>::value ||
397 std::is_base_of<ISmaccOrthogonal, TSmaccObjectType>::value ||
398 std::is_base_of<ISmaccStateMachine, TSmaccObjectType>::value)
399 {
400 RCLCPP_INFO(
401 getLogger(),
402 "[StateMachine] Long life-time SMACC signal subscription created. Subscriber is %s. Callback "
403 "is: %s",
405 demangleSymbol(typeid(callback).name()).c_str());
406
407 connection = binder.bindaux(signal, callback, object, nullptr);
408 }
409 else if (
410 std::is_base_of<ISmaccState, TSmaccObjectType>::value ||
411 std::is_base_of<StateReactor, TSmaccObjectType>::value ||
412 std::is_base_of<ISmaccClientBehavior, TSmaccObjectType>::value)
413 {
414 RCLCPP_INFO(
415 getLogger(),
416 "[StateMachine] Life-time constrained SMACC signal subscription created. Subscriber is %s",
418
419 std::shared_ptr<CallbackCounterSemaphore> callbackCounterSemaphore;
420 if (stateCallbackConnections.count(object))
421 {
422 callbackCounterSemaphore = stateCallbackConnections[object];
423 }
424 else
425 {
426 callbackCounterSemaphore =
427 std::make_shared<CallbackCounterSemaphore>(demangledTypeName<TSmaccObjectType>().c_str());
428 stateCallbackConnections[object] = callbackCounterSemaphore;
429 }
430
431 connection = binder.bindaux(signal, callback, object, callbackCounterSemaphore);
432 callbackCounterSemaphore->addConnection(connection);
433 }
434 else // state life-time objects
435 {
436 RCLCPP_WARN(
437 getLogger(),
438 "[StateMachine] Connecting signal to an unknown object with unknown lifetime "
439 "behavior. An exception may occur if the object is destroyed during the execution.");
440
441 connection = binder.bindaux(signal, callback, object, nullptr);
442 }
443
444 return connection;
445}
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_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_px4_mr::CbArmPX4::onEntry(), cl_px4_mr::CbChangeAltitude::onEntry(), cl_px4_mr::CbDisarmPX4::onEntry(), cl_px4_mr::CbFollowWaypoints::onEntry(), cl_px4_mr::CbGoToLocation::onEntry(), cl_px4_mr::CbLand::onEntry(), cl_px4_mr::CbReturnToHome::onEntry(), cl_px4_mr::CbTakeOff::onEntry(), 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(), and cl_http::CbHttpRequestBase::runtimeConfigure().

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 719 of file smacc_state_machine_impl.hpp.

719{ 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 717 of file smacc_state_machine_impl.hpp.

717{ return this->stateSeqCounter_; }

References stateSeqCounter_.

◆ getCurrentStateInfo()

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

Definition at line 114 of file smacc_state_machine.hpp.

114{ 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 210 of file smacc_state_machine_impl.hpp.

211{
212 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
213 // RCLCPP_WARN(getLogger(),"get SM Data lock acquire");
214 bool success = false;
215
216 if (!globalData_.count(name))
217 {
218 // RCLCPP_WARN(getLogger(),"get SM Data - data do not exist");
219 success = false;
220 }
221 else
222 {
223 // RCLCPP_WARN(getLogger(),"get SM DAta -data exist. accessing");
224 try
225 {
226 auto & v = globalData_[name];
227
228 // RCLCPP_WARN(getLogger(),"get SM DAta -data exist. any cast");
229 ret = boost::any_cast<T>(v.second);
230 success = true;
231 // RCLCPP_WARN(getLogger(),"get SM DAta -data exist. success");
232 }
233 catch (boost::bad_any_cast & ex)
234 {
235 RCLCPP_ERROR(getLogger(), "bad any cast: %s", ex.what());
236 success = false;
237 }
238 }
239
240 // RCLCPP_WARN(getLogger(),"get SM Data lock release");
241 return success;
242}
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 163 of file smacc_state_machine.hpp.

163{ 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 721 of file smacc_state_machine_impl.hpp.

722{
723 return *this->stateMachineInfo_;
724}

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 532 of file smacc_state_machine_impl.hpp.

533{
534 for (auto pair : this->orthogonals_)
535 {
536 // RCLCPP_INFO(getLogger(),"ortho onruntime configure: %s", pair.second->getName().c_str());
537 auto & orthogonal = pair.second;
538 orthogonal->runtimeConfigure();
539 }
540
541 {
542 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
543 this->updateStatusMessage();
545
547 }
548}
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 464 of file smacc_state_machine_impl.hpp.

465{
466 RCLCPP_INFO(
467 getLogger(), "[%s] State OnEntry code finished.",
468 demangleSymbol(typeid(StateType).name()).c_str());
469
470 auto currentState = this->currentState_.back();
471 for (auto pair : this->orthogonals_)
472 {
473 RCLCPP_DEBUG(getLogger(), "Orthogonal onEntry: %s.", pair.second->getName().c_str());
474 auto & orthogonal = pair.second;
475 try
476 {
477 orthogonal->onEntry();
478 }
479 catch (const std::exception & e)
480 {
481 RCLCPP_ERROR(
482 getLogger(),
483 "[Orthogonal %s] Exception on Entry - continuing with next orthogonal. Exception info: %s",
484 pair.second->getName().c_str(), e.what());
485 }
486 }
487
488 for (auto & sr : currentState->getStateReactors())
489 {
490 auto srname = smacc2::demangleSymbol(typeid(*sr).name());
491 RCLCPP_INFO_STREAM(getLogger(), "State reactor onEntry: " << srname);
492 try
493 {
494 sr->onEntry();
495 }
496 catch (const std::exception & e)
497 {
498 RCLCPP_ERROR(
499 getLogger(),
500 "[State Reactor %s] Exception on Entry - continuing with next state reactor. Exception "
501 "info: %s",
502 srname.c_str(), e.what());
503 }
504 }
505
506 for (auto & eg : currentState->getEventGenerators())
507 {
508 auto egname = smacc2::demangleSymbol(typeid(*eg).name());
509 RCLCPP_INFO_STREAM(getLogger(), "Event generator onEntry: " << egname);
510 try
511 {
512 eg->onEntry();
513 }
514 catch (const std::exception & e)
515 {
516 RCLCPP_ERROR(
517 getLogger(),
518 "[Event generator %s] Exception on Entry - continuing with next state reactor. Exception "
519 "info: %s",
520 egname.c_str(), e.what());
521 }
522 }
523
524 {
525 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
526 this->updateStatusMessage();
528 }
529}

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 448 of file smacc_state_machine_impl.hpp.

449{
450 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
451
452 RCLCPP_DEBUG(
453 getLogger(),
454 "[State Machine] Initializing a new state '%s' and updating current state. Getting state "
455 "meta-information. number of orthogonals: %ld",
456 demangleSymbol(typeid(StateType).name()).c_str(), this->orthogonals_.size());
457
459 currentState_.push_back(state);
460 currentStateInfo_ = stateMachineInfo_->getState<StateType>();
461}

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 618 of file smacc_state_machine_impl.hpp.

619{
620 this->lockStateMachine("state exit");
621
623
624 auto fullname = demangleSymbol(typeid(StateType).name());
625 RCLCPP_WARN_STREAM(getLogger(), "Exiting state: " << fullname);
626
627 RCLCPP_INFO_STREAM(getLogger(), "Notification state disposing: leaving state" << state);
628 for (auto pair : this->orthogonals_)
629 {
630 auto & orthogonal = pair.second;
631 try
632 {
633 orthogonal->onDispose();
634 }
635 catch (const std::exception & e)
636 {
637 RCLCPP_ERROR(
638 getLogger(),
639 "[Orthogonal %s] Exception onDispose - continuing with next orthogonal. Exception info: %s",
640 pair.second->getName().c_str(), e.what());
641 }
642 }
643
644 for (auto & sr : state->getStateReactors())
645 {
646 auto srname = smacc2::demangleSymbol(typeid(*sr).name()).c_str();
647 RCLCPP_INFO(getLogger(), "State reactor disposing: %s", srname);
648 try
649 {
650 this->disconnectSmaccSignalObject(sr.get());
651 }
652 catch (const std::exception & e)
653 {
654 RCLCPP_ERROR(
655 getLogger(),
656 "[State Reactor %s] Exception on OnDispose - continuing with next state reactor. Exception "
657 "info: %s",
658 srname, e.what());
659 }
660 }
661
662 for (auto & eg : state->getEventGenerators())
663 {
664 auto egname = smacc2::demangleSymbol(typeid(*eg).name()).c_str();
665 RCLCPP_INFO(getLogger(), "Event generator disposing: %s", egname);
666 try
667 {
668 this->disconnectSmaccSignalObject(eg.get());
669 }
670 catch (const std::exception & e)
671 {
672 RCLCPP_ERROR(
673 getLogger(),
674 "[State Reactor %s] Exception on OnDispose - continuing with next state reactor. Exception "
675 "info: %s",
676 egname, e.what());
677 }
678 }
679
680 this->stateCallbackConnections.clear();
681 currentState_.pop_back();
682
683 // then call exit state
684 RCLCPP_WARN_STREAM(getLogger(), "State exit: " << fullname);
685
687 this->unlockStateMachine("state exit");
688}
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_, stateCallbackConnections, 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 557 of file smacc_state_machine_impl.hpp.

558{
560 auto fullname = demangleSymbol(typeid(StateType).name());
561 RCLCPP_WARN_STREAM(getLogger(), "Exiting state: " << fullname);
562
563 RCLCPP_INFO_STREAM(getLogger(), "Notification state exit: leaving state " << state);
564 for (auto pair : this->orthogonals_)
565 {
566 auto & orthogonal = pair.second;
567 try
568 {
569 orthogonal->onExit();
570 }
571 catch (const std::exception & e)
572 {
573 RCLCPP_ERROR(
574 getLogger(),
575 "[Orthogonal %s] Exception onExit - continuing with next orthogonal. Exception info: %s",
576 pair.second->getName().c_str(), e.what());
577 }
578 }
579
580 for (auto & sr : state->getStateReactors())
581 {
582 auto srname = smacc2::demangleSymbol(typeid(*sr).name());
583 RCLCPP_INFO_STREAM(getLogger(), "State reactor OnExit: " << srname);
584 try
585 {
586 sr->onExit();
587 }
588 catch (const std::exception & e)
589 {
590 RCLCPP_ERROR(
591 getLogger(),
592 "[State Reactor %s] Exception on OnExit - continuing with next state reactor. Exception "
593 "info: %s",
594 srname.c_str(), e.what());
595 }
596 }
597
598 for (auto & eg : state->getEventGenerators())
599 {
600 auto egname = smacc2::demangleSymbol(typeid(*eg).name());
601 RCLCPP_INFO_STREAM(getLogger(), "Event generator OnExit: " << egname);
602 try
603 {
604 eg->onExit();
605 }
606 catch (const std::exception & e)
607 {
608 RCLCPP_ERROR(
609 getLogger(),
610 "[State Reactor %s] Exception on OnExit - continuing with next state reactor. Exception "
611 "info: %s",
612 egname.c_str(), e.what());
613 }
614 }
615}

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 201 of file smacc_state_machine_impl.hpp.

202{
204 RCLCPP_INFO_STREAM(getLogger(), "Event: " << evname);
205 auto * ev = new EventType();
206 this->postEvent(ev, evlifetime);
207}
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 147 of file smacc_state_machine_impl.hpp.

148{
149 std::lock_guard<std::recursive_mutex> guard(eventQueueMutex_);
150
151#define eventtypename demangleSymbol<EventType>().c_str()
152
153 TRACETOOLS_TRACEPOINT(smacc2_event, eventtypename);
154
155 {
156 auto evinfo = SmaccEventInfo(TypeInfo::getTypeInfoFromType<EventType>());
157 EventLabel<EventType>(evinfo.label);
158
159 smacc2_msgs::msg::SmaccEvent event;
160 event.event_type = evinfo.getEventTypeName();
161 event.event_source = evinfo.getEventSourceName();
162 event.event_object_tag = evinfo.getOrthogonalName();
163 event.label = evinfo.label;
164
165 if (this->eventsLogPub_)
166 {
167 this->eventsLogPub_->publish(event);
168 }
169 }
170
171 if (
172 evlifetime == EventLifeTime::CURRENT_STATE &&
175 {
176 RCLCPP_WARN_STREAM(
177 getLogger(),
178 "[ISmaccStateMachine] CURRENT STATE SCOPED EVENT DISCARDED, state is exiting/transitioning "
179 << eventtypename);
180 return;
181 // in this case we may lose/skip events, if this is not right for some cases we should create a
182 // queue to lock the events during the transitions. This issues appeared when a client
183 // asyncbehavior was posting an event meanwhile we were doing the transition, but the main
184 // thread was waiting for its correct finalization (with thread.join)
185 }
186
187 // when a postting event is requested by any component, client, or client behavior
188 // we reach this place. Now, we propagate the events to all the state state reactors to generate
189 // some more events
190
191 RCLCPP_DEBUG_STREAM(getLogger(), "[PostEvent entry point] " << eventtypename);
192 if (!currentState_.empty())
193 {
195 }
196
197 this->signalDetector_->postEvent(ev);
198}
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 691 of file smacc_state_machine_impl.hpp.

692{
693 RCLCPP_DEBUG(
694 getLogger(), "PROPAGATING EVENT [%s] TO SRs [%s]: ", demangleSymbol<EventType>().c_str(),
695 st->getClassName().c_str());
696 for (auto & sb : st->getStateReactors())
697 {
698 sb->notifyEvent(ev);
699 }
700
701 auto * pst = st->getParentState();
702 if (pst != nullptr)
703 {
705 }
706}

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()

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::ISmaccOrthogonal::requiresComponent(), and smacc2::ISmaccState::requiresComponent().

Here is the call graph for this function:
Here is the caller 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 245 of file smacc_state_machine_impl.hpp.

246{
247 {
248 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
249 // RCLCPP_WARN(getLogger(),"set SM Data lock acquire");
250
251 globalData_[name] = {
252 [this, name]()
253 {
254 std::stringstream ss;
255 auto val = any_cast<T>(globalData_[name].second);
256 ss << val;
257 return ss.str();
258 },
259 value};
260 }
261
262 this->updateStatusMessage();
263}

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 231 of file smacc_state_machine.hpp.

◆ SignalDetector

friend class SignalDetector
friend

Definition at line 232 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 203 of file smacc_state_machine.hpp.

Referenced by postEvent().

◆ eventsLogPub_

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

Definition at line 183 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 210 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 215 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

◆ stateMachineCurrentAction

◆ stateMachineInfo_

◆ stateMachinePub_

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

Definition at line 179 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 220 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 193 of file smacc_state_machine.hpp.

Referenced by state_machine_visualization(), and updateStatusMessage().

◆ timer_

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

Definition at line 178 of file smacc_state_machine.hpp.

Referenced by onInitialized().

◆ transitionHistoryService_

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

Definition at line 185 of file smacc_state_machine.hpp.

Referenced by initializeROS().

◆ transitionLogHistory_

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

Definition at line 213 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 181 of file smacc_state_machine.hpp.

Referenced by initializeROS(), and publishTransition().


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