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, bool throwsExceptionIfNotExist=false)
 
template<typename EventType >
void postEvent (EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
 
template<typename EventType >
void postEvent (EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
 
template<typename T >
bool getGlobalSMData (std::string name, T &ret)
 
template<typename T >
void setGlobalSMData (std::string name, T value)
 
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 >
boost::signals2::connection createSignalConnection (TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
 
void disconnectSmaccSignalObject (void *object)
 
template<typename StateType >
void notifyOnStateEntryStart (StateType *state)
 
template<typename StateType >
void notifyOnStateEntryEnd (StateType *state)
 
template<typename StateType >
void notifyOnRuntimeConfigured (StateType *state)
 
template<typename StateType >
void notifyOnStateExitting (StateType *state)
 
template<typename StateType >
void notifyOnStateExited (StateType *state)
 
template<typename StateType >
void notifyOnRuntimeConfigurationFinished (StateType *state)
 
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::vector< boost::signals2::scoped_connection > longLivedSignalConnections_
 
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 64 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 // This enables loading arbitrary parameters
40 // However, best practice would be to declare parameters in the corresponding classes
41 // and provide descriptions about expected use
42 // TODO(henningkayser): remove once all parameters are declared inside the components
43 // node_options.automatically_declare_parameters_from_overrides(true);
44
45 nh_ = rclcpp::Node::make_shared(stateMachineName, nodeOptions); //
46 RCLCPP_INFO_STREAM(
47 nh_->get_logger(), "Creating state machine base: " << nh_->get_fully_qualified_name());
48
49 signalDetector_ = signalDetector;
51
52 std::string runMode;
53 if (nh_->get_parameter("run_mode", runMode))
54 {
55 if (runMode == "debug")
56 {
58 }
59 else if (runMode == "release")
60 {
62 }
63 else
64 {
65 RCLCPP_ERROR(nh_->get_logger(), "Incorrect run_mode value: %s", runMode.c_str());
66 }
67 }
68 else
69 {
71 }
72}
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 74 of file smacc_state_machine.cpp.

75{
76 RCLCPP_INFO(nh_->get_logger(), "Finishing State Machine");
77}

References nh_.

Member Function Documentation

◆ buildStateMachineInfo()

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

Definition at line 762 of file smacc_state_machine_impl.hpp.

763{
764 this->stateMachineInfo_ = std::make_shared<SmaccStateMachineInfo>(this->getNode());
765 this->stateMachineInfo_->buildStateMachineInfo<InitialStateType>();
766 this->stateMachineInfo_->assembleSMStructureMessage(this);
768}
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 230 of file smacc_state_machine.cpp.

231{
232 // transition from an orthogonal that doesn’t exist.
233 // transition from a source that doesn’t exist.
234
235 // std::stringstream errorbuffer;
236 // bool errorFound = false;
237
238 // for (auto &stentry : this->stateMachineInfo_->states)
239 // {
240 // auto stinfo = stentry.second;
241
242 // for (auto &transition : stinfo->transitions_)
243 // {
244 // auto evinfo = transition.eventInfo;
245 // bool found = false;
246 // for (auto &orthogonal : orthogonals_)
247 // {
248 // if (orthogonal.first == evinfo->getOrthogonalName())
249 // {
250 // found = true;
251 // break;
252 // }
253 // }
254
255 // if (!found)
256 // {
257 // errorbuffer << "---------" << std::endl
258 // << "[Consistency Checking] Transition event refers not existing orthogonal." << std::endl
259 // << "State: " << demangleType(*stinfo->tid_) << std::endl
260 // << "Transition: " << transition.transitionTypeInfo->getFullName() << std::endl
261 // << "Orthogonal: " << evinfo->getOrthogonalName() << std::endl
262 // << "---------" << std::endl;
263
264 // errorFound = true;
265 // }
266 // //std::string getEventSourceName();
267 // //std::string getOrthogonalName();
268 // }
269 // }
270
271 // if (errorFound)
272 // {
273 // RCLCPP_WARN_STREAM(nh_->get_logger(),"== STATE MACHINE CONSISTENCY CHECK: ==" << std::endl
274 // << errorbuffer.str() << std::endl
275 // << "=================");
276 // }
277 // cb from a client that doesn’t exist – don’t worry about making clients dynamically.
278}

Referenced by buildStateMachineInfo().

Here is the caller graph for this function:

◆ createOrthogonal()

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

Definition at line 93 of file smacc_state_machine_impl.hpp.

94{
95 //this->lockStateMachine("create orthogonal");
96 std::lock_guard<std::recursive_mutex> guard(m_mutex_);
97
98 std::string orthogonalkey = demangledTypeName<TOrthogonal>();
99
100 if (orthogonals_.count(orthogonalkey) == 0)
101 {
102 auto ret = std::make_shared<TOrthogonal>();
103 orthogonals_[orthogonalkey] = dynamic_pointer_cast<smacc2::ISmaccOrthogonal>(ret);
104
105 ret->setStateMachine(this);
106
107 RCLCPP_INFO(getLogger(), "%s Orthogonal is created", orthogonalkey.c_str());
108 }
109 else
110 {
111 RCLCPP_WARN_STREAM(
112 getLogger(), "There were already one existing orthogonal of type "
113 << orthogonalkey.c_str() << ". Skipping creation orthogonal request. ");
114 std::stringstream ss;
115 ss << "The existing orthogonals are the following: " << std::endl;
116 for (auto & orthogonal : orthogonals_)
117 {
118 ss << " - " << orthogonal.first << std::endl;
119 }
120 RCLCPP_WARN_STREAM(getLogger(), ss.str());
121 }
122 //this->unlockStateMachine("create orthogonal");
123}
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 >
boost::signals2::connection smacc2::ISmaccStateMachine::createSignalConnection ( TSmaccSignal & signal,
TMemberFunctionPrototype callback,
TSmaccObjectType * object )

Definition at line 428 of file smacc_state_machine_impl.hpp.

430{
431 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
432
433 static_assert(
434 std::is_base_of<ISmaccState, TSmaccObjectType>::value ||
435 std::is_base_of<ISmaccClient, TSmaccObjectType>::value ||
436 std::is_base_of<ISmaccClientBehavior, TSmaccObjectType>::value ||
437 std::is_base_of<StateReactor, TSmaccObjectType>::value ||
438 std::is_base_of<ISmaccComponent, TSmaccObjectType>::value,
439 "Only are accepted smacc types as subscribers for smacc signals");
440
441 typedef decltype(callback) ft;
442 Bind<boost::function_types::function_arity<ft>::value> binder;
443 boost::signals2::connection connection;
444
445 // long life-time objects
446 if (
447 std::is_base_of<ISmaccComponent, TSmaccObjectType>::value ||
448 std::is_base_of<ISmaccClient, TSmaccObjectType>::value ||
449 std::is_base_of<ISmaccOrthogonal, TSmaccObjectType>::value ||
450 std::is_base_of<ISmaccStateMachine, TSmaccObjectType>::value)
451 {
452 RCLCPP_INFO(
453 getLogger(),
454 "[StateMachine] Long life-time SMACC signal subscription created. Subscriber is %s. Callback "
455 "is: %s",
457 demangleSymbol(typeid(callback).name()).c_str());
458
459 connection = binder.bindaux(signal, callback, object, nullptr);
460 }
461 else if (
462 std::is_base_of<ISmaccState, TSmaccObjectType>::value ||
463 std::is_base_of<StateReactor, TSmaccObjectType>::value ||
464 std::is_base_of<ISmaccClientBehavior, TSmaccObjectType>::value)
465 {
466 RCLCPP_INFO(
467 getLogger(),
468 "[StateMachine] Life-time constrained SMACC signal subscription created. Subscriber is %s",
470
471 std::shared_ptr<CallbackCounterSemaphore> callbackCounterSemaphore;
472 if (stateCallbackConnections.count(object))
473 {
474 callbackCounterSemaphore = stateCallbackConnections[object];
475 }
476 else
477 {
478 callbackCounterSemaphore =
479 std::make_shared<CallbackCounterSemaphore>(demangledTypeName<TSmaccObjectType>().c_str());
480 stateCallbackConnections[object] = callbackCounterSemaphore;
481 }
482
483 connection = binder.bindaux(signal, callback, object, callbackCounterSemaphore);
484 callbackCounterSemaphore->addConnection(connection);
485 }
486 else // state life-time objects
487 {
488 RCLCPP_WARN(
489 getLogger(),
490 "[StateMachine] Connecting signal to an unknown object with unknown lifetime "
491 "behavior. An exception may occur if the object is destroyed during the execution.");
492
493 connection = binder.bindaux(signal, callback, object, nullptr);
494 }
495
496 return connection;
497}
std::map< void *, std::shared_ptr< CallbackCounterSemaphore > > stateCallbackConnections
std::string demangleSymbol()

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(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onCancelled(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onCancelled(), smacc2::client_core_components::CpActionClient< ActionType >::onCancelled(), 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_multirole_sensor::ClMultiroleSensor< MessageType >::onMessageTimeout(), cl_moveit2z::ClMoveit2z::onMotionExecutionFailed(), cl_moveit2z::ClMoveit2z::onMotionExecutionSuccedded(), cl_nav2z::components::CpNav2ActionInterface::onNavigationAborted(), cl_nav2z::components::CpNav2ActionInterface::onNavigationCancelled(), cl_nav2z::components::CpNav2ActionInterface::onNavigationFeedback(), cl_nav2z::components::CpNav2ActionInterface::onNavigationSucceeded(), cl_http::ClHttp::onResponseReceived(), 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::components::CpTimerListener1::onTimerCompleted(), cl_ros2_timer::CbTimerCountdownLoop::onTimerTick(), cl_ros2_timer::CbTimerCountdownOnce::onTimerTick(), cl_ros_timer::CbTimerCountdownLoop::onTimerTick(), cl_ros_timer::CbTimerCountdownOnce::onTimerTick(), cl_ros_timer::ClRosTimer::onTimerTick(), smacc2::client_core_components::CpRos2Timer::onTimerTick(), and cl_nav2z::CbNav2ZClientBehaviorBase::sendGoal().

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

80{
81 RCLCPP_INFO(nh_->get_logger(), "[SmaccSignal] Object signal disconnecting %ld", (long)object_ptr);
82 if (stateCallbackConnections.count(object_ptr) > 0)
83 {
84 auto callbackSemaphore = stateCallbackConnections[object_ptr];
85 callbackSemaphore->finalize();
86 stateCallbackConnections.erase(object_ptr);
87 }
88 else
89 {
90 RCLCPP_INFO(nh_->get_logger(), "[SmaccSignal] No signals found %ld", (long)object_ptr);
91 }
92}

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

86 {
87 auto orthogonal = this->template getOrthogonal<TOrthogonal>();
88
89 return orthogonal->template getClientBehavior<TClientBehavior>(index);
90 }
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 772 of file smacc_state_machine_impl.hpp.

772{ 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 770 of file smacc_state_machine_impl.hpp.

770{ 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 241 of file smacc_state_machine_impl.hpp.

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

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

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

775{
776 return *this->stateMachineInfo_;
777}

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

226{
227 return demangleSymbol(typeid(*this).name());
228}

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

190{
191 RCLCPP_WARN(
192 nh_->get_logger(), "Requesting transition log history, current size: %ld",
193 this->transitionLogHistory_.size());
194 res->history = this->transitionLogHistory_;
195}
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 164 of file smacc_state_machine.cpp.

165{
166 RCLCPP_WARN_STREAM(nh_->get_logger(), "State machine base creation: " << shortname);
167 // STATE MACHINE TOPICS
168 stateMachinePub_ = nh_->create_publisher<smacc2_msgs::msg::SmaccStateMachine>(
169 shortname + "/smacc/state_machine_description", rclcpp::QoS(1));
170 stateMachineStatusPub_ = nh_->create_publisher<smacc2_msgs::msg::SmaccStatus>(
171 shortname + "/smacc/status", rclcpp::QoS(1));
172 transitionLogPub_ = nh_->create_publisher<smacc2_msgs::msg::SmaccTransitionLogEntry>(
173 shortname + "/smacc/transition_log", rclcpp::QoS(1));
174
175 eventsLogPub_ = nh_->create_publisher<smacc2_msgs::msg::SmaccEvent>(
176 shortname + "/smacc/event_log", rclcpp::QoS(100));
177
178 // STATE MACHINE SERVICES
179 transitionHistoryService_ = nh_->create_service<smacc2_msgs::srv::SmaccGetTransitionHistory>(
180 shortname + "/smacc/transition_log_history",
181 std::bind(
182 &ISmaccStateMachine::getTransitionLogHistory, this, std::placeholders::_1,
183 std::placeholders::_2, std::placeholders::_3));
184}
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_, 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 213 of file smacc_state_machine.cpp.

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

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

585{
586 for (auto pair : this->orthogonals_)
587 {
588 // RCLCPP_INFO(getLogger(),"ortho onruntime configure: %s", pair.second->getName().c_str());
589 auto & orthogonal = pair.second;
590 orthogonal->runtimeConfigure();
591 }
592
593 {
594 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
595 this->updateStatusMessage();
597
599 }
600}
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 516 of file smacc_state_machine_impl.hpp.

517{
518 RCLCPP_INFO(
519 getLogger(), "[%s] State OnEntry code finished.",
520 demangleSymbol(typeid(StateType).name()).c_str());
521
522 auto currentState = this->currentState_.back();
523 for (auto pair : this->orthogonals_)
524 {
525 RCLCPP_DEBUG(getLogger(), "Orthogonal onEntry: %s.", pair.second->getName().c_str());
526 auto & orthogonal = pair.second;
527 try
528 {
529 orthogonal->onEntry();
530 }
531 catch (const std::exception & e)
532 {
533 RCLCPP_ERROR(
534 getLogger(),
535 "[Orthogonal %s] Exception on Entry - continuing with next orthogonal. Exception info: %s",
536 pair.second->getName().c_str(), e.what());
537 }
538 }
539
540 for (auto & sr : currentState->getStateReactors())
541 {
542 auto srname = smacc2::demangleSymbol(typeid(*sr).name());
543 RCLCPP_INFO_STREAM(getLogger(), "State reactor onEntry: " << srname);
544 try
545 {
546 sr->onEntry();
547 }
548 catch (const std::exception & e)
549 {
550 RCLCPP_ERROR(
551 getLogger(),
552 "[State Reactor %s] Exception on Entry - continuing with next state reactor. Exception "
553 "info: %s",
554 srname.c_str(), e.what());
555 }
556 }
557
558 for (auto & eg : currentState->getEventGenerators())
559 {
560 auto egname = smacc2::demangleSymbol(typeid(*eg).name());
561 RCLCPP_INFO_STREAM(getLogger(), "Event generator onEntry: " << egname);
562 try
563 {
564 eg->onEntry();
565 }
566 catch (const std::exception & e)
567 {
568 RCLCPP_ERROR(
569 getLogger(),
570 "[Event generator %s] Exception on Entry - continuing with next state reactor. Exception "
571 "info: %s",
572 egname.c_str(), e.what());
573 }
574 }
575
576 {
577 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
578 this->updateStatusMessage();
580 }
581}

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

501{
502 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
503
504 RCLCPP_DEBUG(
505 getLogger(),
506 "[State Machine] Initializing a new state '%s' and updating current state. Getting state "
507 "meta-information. number of orthogonals: %ld",
508 demangleSymbol(typeid(StateType).name()).c_str(), this->orthogonals_.size());
509
511 currentState_.push_back(state);
512 currentStateInfo_ = stateMachineInfo_->getState<StateType>();
513}

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

672{
673 this->lockStateMachine("state exit");
674
676
677 auto fullname = demangleSymbol(typeid(StateType).name());
678 RCLCPP_WARN_STREAM(getLogger(), "Exiting state: " << fullname);
679
680 RCLCPP_INFO_STREAM(getLogger(), "Notification state disposing: leaving state" << state);
681 for (auto pair : this->orthogonals_)
682 {
683 auto & orthogonal = pair.second;
684 try
685 {
686 orthogonal->onDispose();
687 }
688 catch (const std::exception & e)
689 {
690 RCLCPP_ERROR(
691 getLogger(),
692 "[Orthogonal %s] Exception onDispose - continuing with next orthogonal. Exception info: %s",
693 pair.second->getName().c_str(), e.what());
694 }
695 }
696
697 for (auto & sr : state->getStateReactors())
698 {
699 auto srname = smacc2::demangleSymbol(typeid(*sr).name()).c_str();
700 RCLCPP_INFO(getLogger(), "State reactor disposing: %s", srname);
701 try
702 {
703 this->disconnectSmaccSignalObject(sr.get());
704 }
705 catch (const std::exception & e)
706 {
707 RCLCPP_ERROR(
708 getLogger(),
709 "[State Reactor %s] Exception on OnDispose - continuing with next state reactor. Exception "
710 "info: %s",
711 srname, e.what());
712 }
713 }
714
715 for (auto & eg : state->getEventGenerators())
716 {
717 auto egname = smacc2::demangleSymbol(typeid(*eg).name()).c_str();
718 RCLCPP_INFO(getLogger(), "Event generator disposing: %s", egname);
719 try
720 {
721 this->disconnectSmaccSignalObject(eg.get());
722 }
723 catch (const std::exception & e)
724 {
725 RCLCPP_ERROR(
726 getLogger(),
727 "[State Reactor %s] Exception on OnDispose - continuing with next state reactor. Exception "
728 "info: %s",
729 egname, e.what());
730 }
731 }
732
733 this->stateCallbackConnections.clear();
734 currentState_.pop_back();
735
736 // then call exit state
737 RCLCPP_WARN_STREAM(getLogger(), "State exit: " << fullname);
738
740 this->unlockStateMachine("state exit");
741}
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:

◆ notifyOnStateExitting()

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

Definition at line 609 of file smacc_state_machine_impl.hpp.

610{
612 auto fullname = demangleSymbol(typeid(StateType).name());
613 RCLCPP_WARN_STREAM(getLogger(), "Exiting state: " << fullname);
614 // this->set_parameter("destroyed", true);
615
616 RCLCPP_INFO_STREAM(getLogger(), "Notification state exit: leaving state " << state);
617 for (auto pair : this->orthogonals_)
618 {
619 auto & orthogonal = pair.second;
620 try
621 {
622 orthogonal->onExit();
623 }
624 catch (const std::exception & e)
625 {
626 RCLCPP_ERROR(
627 getLogger(),
628 "[Orthogonal %s] Exception onExit - continuing with next orthogonal. Exception info: %s",
629 pair.second->getName().c_str(), e.what());
630 }
631 }
632
633 for (auto & sr : state->getStateReactors())
634 {
635 auto srname = smacc2::demangleSymbol(typeid(*sr).name());
636 RCLCPP_INFO_STREAM(getLogger(), "State reactor OnExit: " << srname);
637 try
638 {
639 sr->onExit();
640 }
641 catch (const std::exception & e)
642 {
643 RCLCPP_ERROR(
644 getLogger(),
645 "[State Reactor %s] Exception on OnExit - continuing with next state reactor. Exception "
646 "info: %s",
647 srname.c_str(), e.what());
648 }
649 }
650
651 for (auto & eg : state->getEventGenerators())
652 {
653 auto egname = smacc2::demangleSymbol(typeid(*eg).name());
654 RCLCPP_INFO_STREAM(getLogger(), "Event generator OnExit: " << egname);
655 try
656 {
657 eg->onExit();
658 }
659 catch (const std::exception & e)
660 {
661 RCLCPP_ERROR(
662 getLogger(),
663 "[State Reactor %s] Exception on OnExit - continuing with next state reactor. Exception "
664 "info: %s",
665 egname.c_str(), e.what());
666 }
667 }
668}

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

155{}

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

158{
159 auto ros_clock = rclcpp::Clock::make_shared();
160 timer_ =
161 rclcpp::create_timer(nh_, ros_clock, 0.5s, [=]() { this->state_machine_visualization(); });
162}
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 232 of file smacc_state_machine_impl.hpp.

233{
235 RCLCPP_INFO_STREAM(getLogger(), "Event: " << evname);
236 auto * ev = new EventType();
237 this->postEvent(ev, evlifetime);
238}
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 178 of file smacc_state_machine_impl.hpp.

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

745{
746 RCLCPP_DEBUG(
747 getLogger(), "PROPAGATING EVENT [%s] TO SRs [%s]: ", demangleSymbol<EventType>().c_str(),
748 st->getClassName().c_str());
749 for (auto & sb : st->getStateReactors())
750 {
751 sb->notifyEvent(ev);
752 }
753
754 auto * pst = st->getParentState();
755 if (pst != nullptr)
756 {
758 }
759}

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

146{
147 smacc2_msgs::msg::SmaccTransitionLogEntry transitionLogEntry;
148 transitionLogEntry.timestamp = this->nh_->now();
149 transitionInfoToMsg(transitionInfo, transitionLogEntry.transition);
150 this->transitionLogHistory_.push_back(transitionLogEntry);
151
152 transitionLogPub_->publish(transitionLogEntry);
153}
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,
bool throwsExceptionIfNotExist = false )

Definition at line 127 of file smacc_state_machine_impl.hpp.

128{
129 RCLCPP_DEBUG(
130 getLogger(), "component %s is required",
131 demangleSymbol(typeid(SmaccComponentType).name()).c_str());
132 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
133
134 for (auto ortho : this->orthogonals_)
135 {
136 for (auto & client : ortho.second->clients_)
137 {
138 storage = client->getComponent<SmaccComponentType>();
139 if (storage != nullptr)
140 {
141 return;
142 }
143 }
144 }
145
146 RCLCPP_WARN(
147 getLogger(), "component %s is required but it was not found in any orthogonal",
148 demangleSymbol(typeid(SmaccComponentType).name()).c_str());
149
150 if (throwsException)
151 throw std::runtime_error("component is required but it was not found in any orthogonal");
152
153 // std::string componentkey = demangledTypeName<SmaccComponentType>();
154 // SmaccComponentType *ret;
155
156 // auto it = components_.find(componentkey);
157
158 // if (it == components_.end())
159 // {
160 // RCLCPP_DEBUG(getLogger(),"%s smacc component is required. Creating a new instance.",
161 // componentkey.c_str());
162
163 // ret = new SmaccComponentType();
164 // ret->setStateMachine(this);
165 // components_[componentkey] = static_cast<smacc2::ISmaccComponent *>(ret);
166 // RCLCPP_DEBUG(getLogger(),"%s resource is required. Done.", componentkey.c_str());
167 // }
168 // else
169 // {
170 // RCLCPP_DEBUG(getLogger(),"%s resource is required. Found resource in cache.",
171 // componentkey.c_str()); ret = dynamic_cast<SmaccComponentType *>(it->second);
172 // }
173
174 // storage = ret;
175}

References smacc2::introspection::demangleSymbol(), getLogger(), 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 276 of file smacc_state_machine_impl.hpp.

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

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

198{
199 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
200
201 smacc2_msgs::msg::SmaccStateMachine state_machine_msg;
202 state_machine_msg.states = stateMachineInfo_->stateMsgs;
203
204 std::sort(
205 state_machine_msg.states.begin(), state_machine_msg.states.end(),
206 [](auto & a, auto & b) { return a.index < b.index; });
207 stateMachinePub_->publish(state_machine_msg);
208
209 status_msg_.header.stamp = this->nh_->now();
211}
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 219 of file smacc_state_machine.cpp.

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

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

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

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

◆ SignalDetector

friend class SignalDetector
friend

Definition at line 238 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 209 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 216 of file smacc_state_machine.hpp.

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

◆ longLivedSignalConnections_

std::vector<boost::signals2::scoped_connection> smacc2::ISmaccStateMachine::longLivedSignalConnections_
protected

Definition at line 202 of file smacc_state_machine.hpp.

◆ m_mutex_

◆ nh_

◆ orthogonals_

◆ runMode_

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

Definition at line 221 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 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 226 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 219 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: