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 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::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 // 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 756 of file smacc_state_machine_impl.hpp.

757{
758 this->stateMachineInfo_ = std::make_shared<SmaccStateMachineInfo>(this->getNode());
759 this->stateMachineInfo_->buildStateMachineInfo<InitialStateType>();
760 this->stateMachineInfo_->assembleSMStructureMessage(this);
762}
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 234 of file smacc_state_machine.cpp.

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

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

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

766{ 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 764 of file smacc_state_machine_impl.hpp.

764{ return this->stateSeqCounter_; }

References stateSeqCounter_.

◆ getCurrentStateInfo()

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

Definition at line 117 of file smacc_state_machine.hpp.

117{ 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 235 of file smacc_state_machine_impl.hpp.

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

166{ 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 768 of file smacc_state_machine_impl.hpp.

769{
770 return *this->stateMachineInfo_;
771}

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

230{
231 return demangleSymbol(typeid(*this).name());
232}

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

194{
195 RCLCPP_WARN(
196 nh_->get_logger(), "Requesting transition log history, current size: %ld",
197 this->transitionLogHistory_.size());
198 res->history = this->transitionLogHistory_;
199}
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
185 // Notify signal detector that ROS initialization is complete
186 // This allows the polling loop to start safely accessing ROS objects
188}
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 217 of file smacc_state_machine.cpp.

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

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

579{
580 for (auto pair : this->orthogonals_)
581 {
582 // RCLCPP_INFO(getLogger(),"ortho onruntime configure: %s", pair.second->getName().c_str());
583 auto & orthogonal = pair.second;
584 orthogonal->runtimeConfigure();
585 }
586
587 {
588 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
589 this->updateStatusMessage();
591
593 }
594}
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 510 of file smacc_state_machine_impl.hpp.

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

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

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

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

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

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

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

227{
229 RCLCPP_INFO_STREAM(getLogger(), "Event: " << evname);
230 auto * ev = new EventType();
231 this->postEvent(ev, evlifetime);
232}
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 172 of file smacc_state_machine_impl.hpp.

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

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

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,
ComponentRequirement requirementType )

Definition at line 119 of file smacc_state_machine_impl.hpp.

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

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

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

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

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

224{
225 RCLCPP_DEBUG(nh_->get_logger(), "-- unlocking SM: %s", msg.c_str());
226 m_mutex_.unlock();
227}

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

◆ SignalDetector

friend class SignalDetector
friend

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

Referenced by postEvent().

◆ eventsLogPub_

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

Definition at line 186 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 213 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 218 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 182 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 223 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 196 of file smacc_state_machine.hpp.

Referenced by state_machine_visualization(), and updateStatusMessage().

◆ timer_

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

Definition at line 181 of file smacc_state_machine.hpp.

Referenced by onInitialized().

◆ transitionHistoryService_

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

Definition at line 188 of file smacc_state_machine.hpp.

Referenced by initializeROS().

◆ transitionLogHistory_

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

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

Referenced by initializeROS(), and publishTransition().


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