SMACC2
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
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)
 
virtual ~ISmaccStateMachine ()
 
virtual void reset ()
 
virtual void stop ()
 
virtual void eStop ()
 
template<typename TOrthogonal >
TOrthogonal * getOrthogonal ()
 
const std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > & getOrthogonals () const
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage)
 
template<typename EventType >
void postEvent (EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
 
template<typename EventType >
void postEvent (EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
 
template<typename T >
bool getGlobalSMData (std::string name, T &ret)
 
template<typename T >
void setGlobalSMData (std::string name, T value)
 
template<typename StateField , typename BehaviorType >
void mapBehavior ()
 
std::string getStateMachineName ()
 
void state_machine_visualization ()
 
std::shared_ptr< SmaccStateInfogetCurrentStateInfo ()
 
void publishTransition (const SmaccTransitionInfo &transitionInfo)
 
virtual void onInitialize ()
 this function should be implemented by the user to create the orthogonals More...
 
void getTransitionLogHistory (const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< smacc2_msgs::srv::SmaccGetTransitionHistory::Request > req, std::shared_ptr< smacc2_msgs::srv::SmaccGetTransitionHistory::Response > res)
 
template<typename TSmaccSignal , typename TMemberFunctionPrototype , typename TSmaccObjectType >
boost::signals2::connection createSignalConnection (TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
 
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)
 
void disposeStateAndDisconnectSignals ()
 
template<typename StateType >
void notifyOnRuntimeConfigurationFinished (StateType *state)
 
unsigned long 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::Service< smacc2_msgs::srv::SmaccGetTransitionHistory >::SharedPtr transitionHistoryService_
 
ISmaccStatecurrentState_
 
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

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::list< boost::signals2::connection > 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_
 
unsigned long 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 
)

Definition at line 35 of file smacc_state_machine.cpp.

38{
39 rclcpp::NodeOptions node_options;
40 // This enables loading arbitrary parameters
41 // However, best practice would be to declare parameters in the corresponding classes
42 // and provide descriptions about expected use
43 // TODO(henningkayser): remove once all parameters are declared inside the components
44 // node_options.automatically_declare_parameters_from_overrides(true);
45
46 nh_ = rclcpp::Node::make_shared(stateMachineName, node_options); //
47 RCLCPP_INFO_STREAM(
48 nh_->get_logger(), "Creating State Machine Base: " << nh_->get_fully_qualified_name());
49
50 signalDetector_ = signalDetector;
52
53 std::string runMode;
54 if (nh_->get_parameter("run_mode", runMode))
55 {
56 if (runMode == "debug")
57 {
59 }
60 else if (runMode == "release")
61 {
63 }
64 else
65 {
66 RCLCPP_ERROR(nh_->get_logger(), "Incorrect run_mode value: %s", runMode.c_str());
67 }
68 }
69 else
70 {
72 }
73}
rclcpp::Node::SharedPtr nh_
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 75 of file smacc_state_machine.cpp.

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

References nh_.

Member Function Documentation

◆ buildStateMachineInfo()

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

Definition at line 598 of file smacc_state_machine_impl.hpp.

599{
600 this->stateMachineInfo_ = std::make_shared<SmaccStateMachineInfo>(this->getNode());
601 this->stateMachineInfo_->buildStateMachineInfo<InitialStateType>();
602 this->stateMachineInfo_->assembleSMStructureMessage(this);
604}
rclcpp::Node::SharedPtr getNode()
std::shared_ptr< SmaccStateMachineInfo > stateMachineInfo_

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

Here is the call graph for this function:

◆ checkStateMachineConsistence()

void smacc2::ISmaccStateMachine::checkStateMachineConsistence ( )
protected

Definition at line 229 of file smacc_state_machine.cpp.

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

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

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

357{
358 static_assert(
359 std::is_base_of<ISmaccState, TSmaccObjectType>::value ||
360 std::is_base_of<ISmaccClient, TSmaccObjectType>::value ||
361 std::is_base_of<ISmaccClientBehavior, TSmaccObjectType>::value ||
362 std::is_base_of<StateReactor, TSmaccObjectType>::value ||
363 std::is_base_of<ISmaccComponent, TSmaccObjectType>::value,
364 "Only are accepted smacc types as subscribers for smacc signals");
365
366 typedef decltype(callback) ft;
367 Bind<boost::function_types::function_arity<ft>::value> binder;
368 boost::signals2::connection connection = binder.bindaux(signal, callback, object);
369
370 // long life-time objects
371 if (
372 std::is_base_of<ISmaccComponent, TSmaccObjectType>::value ||
373 std::is_base_of<ISmaccClient, TSmaccObjectType>::value ||
374 std::is_base_of<ISmaccOrthogonal, TSmaccObjectType>::value ||
375 std::is_base_of<ISmaccStateMachine, TSmaccObjectType>::value)
376 {
377 }
378 else if (
379 std::is_base_of<ISmaccState, TSmaccObjectType>::value ||
380 std::is_base_of<StateReactor, TSmaccObjectType>::value ||
381 std::is_base_of<ISmaccClientBehavior, TSmaccObjectType>::value)
382 {
383 RCLCPP_INFO(
384 getLogger(),
385 "[StateMachine] life-time constrained smacc signal subscription created. Subscriber is %s",
386 demangledTypeName<TSmaccObjectType>().c_str());
387 stateCallbackConnections.push_back(connection);
388 }
389 else // state life-time objects
390 {
391 RCLCPP_WARN(
392 getLogger(),
393 "[StateMachine] connecting signal to an unknown object with life-time unknown "
394 "behavior. It might provoke "
395 "an exception if the object is destroyed during the execution.");
396 }
397
398 return connection;
399}
std::list< boost::signals2::connection > stateCallbackConnections
void callback(const image_tools::ROSCvMatContainer &img)

References smacc2::utils::Bind< arity >::bindaux(), callback(), getLogger(), and stateCallbackConnections.

Referenced by smacc2::ISmaccClient::connectSignal(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onAborted(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onCancelled(), smacc2::SmaccAsyncClientBehavior::onFailure(), smacc2::SmaccAsyncClientBehavior::onFinished(), smacc2::components::CpTopicSubscriber< MessageType >::onFirstMessageReceived(), smacc2::client_bases::SmaccSubscriberClient< MessageType >::onFirstMessageReceived(), cl_keyboard::ClKeyboard::OnKeyPress(), smacc2::components::CpTopicSubscriber< MessageType >::onMessageReceived(), smacc2::client_bases::SmaccSubscriberClient< MessageType >::onMessageReceived(), cl_multirole_sensor::ClMultiroleSensor< MessageType >::onMessageTimeout(), cl_move_group_interface::ClMoveGroup::onMotionExecutionFailed(), cl_move_group_interface::ClMoveGroup::onMotionExecutionSuccedded(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onSucceeded(), smacc2::SmaccAsyncClientBehavior::onSuccess(), cl_ros_timer::ClRosTimer::onTimerTick(), cl_ros_timer::CbTimerCountdownLoop::onTimerTick(), and cl_ros_timer::CbTimerCountdownOnce::onTimerTick().

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

◆ disposeStateAndDisconnectSignals()

void smacc2::ISmaccStateMachine::disposeStateAndDisconnectSignals ( )

Definition at line 213 of file smacc_state_machine.cpp.

214{
215 for (auto & conn : this->stateCallbackConnections)
216 {
217 RCLCPP_WARN_STREAM(
218 getLogger(),
219 "[StateMachine] Disconnecting scoped-lifetime SmaccSignal "
220 "subscription");
221 conn.disconnect();
222 }
223
224 this->stateCallbackConnections.clear();
225
226 currentState_ = nullptr;
227}

References currentState_, getLogger(), and stateCallbackConnections.

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:

◆ eStop()

void smacc2::ISmaccStateMachine::eStop ( )
virtual

Reimplemented in smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >, smacc2::SmaccStateMachineBase< $SmName$, State1 >, smacc2::SmaccStateMachineBase< SmAdvancedRecovery1, MsRun >, smacc2::SmaccStateMachineBase< SmAtomic, State1 >, smacc2::SmaccStateMachineBase< SmAtomic24Hr, State1 >, smacc2::SmaccStateMachineBase< SmAtomicPerformanceTrace1, State1 >, smacc2::SmaccStateMachineBase< SmAtomicSubscribersPerformanceTest, State1 >, smacc2::SmaccStateMachineBase< SmAutowareAvp, StAcquireSensors >, smacc2::SmaccStateMachineBase< SmAwsWarehouseNavigation, StAcquireSensors >, smacc2::SmaccStateMachineBase< SmBranching, State1 >, smacc2::SmaccStateMachineBase< SmCoretestTransitionSpeed1, State1 >, smacc2::SmaccStateMachineBase< SmDanceBot, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotStrikesBack, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotWarehouse, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotWareHouse2, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotWareHouse3, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmFerrari, MsRun >, smacc2::SmaccStateMachineBase< SmHuskyBarrelSearch1, StAcquireSensors >, smacc2::SmaccStateMachineBase< SmMultiStage1, MsMode1 >, smacc2::SmaccStateMachineBase< SmPubsub1, MsRun >, smacc2::SmaccStateMachineBase< SmRespira1, MsRun >, smacc2::SmaccStateMachineBase< SmTestMoveitUr5Sim, StAcquireSensors >, and smacc2::SmaccStateMachineBase< SmThreeSome, MsRun >.

Definition at line 86 of file smacc_state_machine.cpp.

86{}

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

Here is the caller graph for this function:

◆ getCurrentState()

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

Definition at line 608 of file smacc_state_machine_impl.hpp.

608{ return this->currentState_; }

References currentState_.

Referenced by smacc2::SignalDetector::pollOnce(), and cl_nav2z::WaypointNavigator::sendNextGoal().

Here is the caller graph for this function:

◆ getCurrentStateCounter()

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

Definition at line 606 of file smacc_state_machine_impl.hpp.

606{ return this->stateSeqCounter_; }

References stateSeqCounter_.

Referenced by smacc2::SignalDetector::pollOnce().

Here is the caller graph for this function:

◆ getCurrentStateInfo()

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

Definition at line 105 of file smacc_state_machine.hpp.

105{ 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 222 of file smacc_state_machine_impl.hpp.

223{
224 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
225 // RCLCPP_WARN(getLogger(),"get SM Data lock acquire");
226 bool success = false;
227
228 if (!globalData_.count(name))
229 {
230 // RCLCPP_WARN(getLogger(),"get SM Data - data do not exist");
231 success = false;
232 }
233 else
234 {
235 // RCLCPP_WARN(getLogger(),"get SM DAta -data exist. accessing");
236 try
237 {
238 auto & v = globalData_[name];
239
240 // RCLCPP_WARN(getLogger(),"get SM DAta -data exist. any cast");
241 ret = boost::any_cast<T>(v.second);
242 success = true;
243 // RCLCPP_WARN(getLogger(),"get SM DAta -data exist. success");
244 }
245 catch (boost::bad_any_cast & ex)
246 {
247 RCLCPP_ERROR(getLogger(), "bad any cast: %s", ex.what());
248 success = false;
249 }
250 }
251
252 // RCLCPP_WARN(getLogger(),"get SM Data lock release");
253 return success;
254}
std::map< std::string, std::pair< std::function< std::string()>, boost::any > > globalData_

References getLogger(), globalData_, and m_mutex_.

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

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

◆ getLogger()

rclcpp::Logger smacc2::ISmaccStateMachine::getLogger ( )
inline

◆ getMutex()

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

Definition at line 157 of file smacc_state_machine.hpp.

157{ return this->m_mutex_; }

References m_mutex_.

◆ getNode()

rclcpp::Node::SharedPtr smacc2::ISmaccStateMachine::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 getLogger(), m_mutex_, and orthogonals_.

Referenced by 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 610 of file smacc_state_machine_impl.hpp.

611{
612 return *this->stateMachineInfo_;
613}

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

209{
210 return demangleSymbol(typeid(*this).name());
211}
std::string demangleSymbol(const std::string &name)

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

173{
174 RCLCPP_WARN(
175 nh_->get_logger(), "Requesting Transition Log History, current size: %ld",
176 this->transitionLogHistory_.size());
177 res->history = this->transitionLogHistory_;
178}
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 150 of file smacc_state_machine.cpp.

151{
152 RCLCPP_WARN_STREAM(nh_->get_logger(), "State machine base creation:" << shortname);
153 // STATE MACHINE TOPICS
154 stateMachinePub_ = nh_->create_publisher<smacc2_msgs::msg::SmaccStateMachine>(
155 shortname + "/smacc/state_machine_description", 1);
157 nh_->create_publisher<smacc2_msgs::msg::SmaccStatus>(shortname + "/smacc/status", 1);
158 transitionLogPub_ = nh_->create_publisher<smacc2_msgs::msg::SmaccTransitionLogEntry>(
159 shortname + "/smacc/transition_log", 1);
160
161 // STATE MACHINE SERVICES
162 transitionHistoryService_ = nh_->create_service<smacc2_msgs::srv::SmaccGetTransitionHistory>(
163 shortname + "/smacc/transition_log_history",
164 std::bind(
165 &ISmaccStateMachine::getTransitionLogHistory, this, std::placeholders::_1,
166 std::placeholders::_2, std::placeholders::_3));
167}
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_
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 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:

◆ mapBehavior()

template<typename StateField , typename BehaviorType >
void smacc2::ISmaccStateMachine::mapBehavior

Definition at line 277 of file smacc_state_machine_impl.hpp.

278{
279 std::string stateFieldName = demangleSymbol(typeid(StateField).name());
280 std::string behaviorType = demangleSymbol(typeid(BehaviorType).name());
281 RCLCPP_INFO(
282 getLogger(), "Mapping state field '%s' to stateReactor '%s'", stateFieldName.c_str(),
283 behaviorType.c_str());
284 SmaccClientBehavior * globalreference;
285 if (!this->getGlobalSMData(stateFieldName, globalreference))
286 {
287 // Using the requires component approach, we force a unique existence
288 // of this component
289 BehaviorType * behavior;
290 this->requiresComponent(behavior);
291 globalreference = dynamic_cast<ISmaccClientBehavior *>(behavior);
292
293 this->setGlobalSMData(stateFieldName, globalreference);
294 }
295}
bool getGlobalSMData(std::string name, T &ret)
void setGlobalSMData(std::string name, T value)
void requiresComponent(SmaccComponentType *&storage)

References smacc2::introspection::demangleSymbol(), getGlobalSMData(), getLogger(), requiresComponent(), and setGlobalSMData().

Here is the call graph for this function:

◆ notifyOnRuntimeConfigurationFinished()

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

Definition at line 482 of file smacc_state_machine_impl.hpp.

483{
484 for (auto pair : this->orthogonals_)
485 {
486 // RCLCPP_INFO(getLogger(),"ortho onruntime configure: %s", pair.second->getName().c_str());
487 auto & orthogonal = pair.second;
488 orthogonal->runtimeConfigure();
489 }
490
491 this->updateStatusMessage();
492
494}
StateMachineInternalAction stateMachineCurrentAction

References orthogonals_, 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 418 of file smacc_state_machine_impl.hpp.

419{
420 RCLCPP_INFO(
421 getLogger(), "[%s] State OnEntry code finished",
422 demangleSymbol(typeid(StateType).name()).c_str());
423
424 for (auto pair : this->orthogonals_)
425 {
426 RCLCPP_DEBUG(getLogger(), "ortho onentry: %s", pair.second->getName().c_str());
427 auto & orthogonal = pair.second;
428 try
429 {
430 orthogonal->onEntry();
431 }
432 catch (const std::exception & e)
433 {
434 RCLCPP_ERROR(
435 getLogger(),
436 "[Orthogonal %s] Exception on Entry - continuing with next orthogonal. Exception info: %s",
437 pair.second->getName().c_str(), e.what());
438 }
439 }
440
441 for (auto & sr : this->currentState_->getStateReactors())
442 {
443 auto srname = smacc2::demangleSymbol(typeid(*sr).name());
444 RCLCPP_INFO_STREAM(getLogger(), "state reactor onEntry: " << srname);
445 try
446 {
447 sr->onEntry();
448 }
449 catch (const std::exception & e)
450 {
451 RCLCPP_ERROR(
452 getLogger(),
453 "[State Reactor %s] Exception on Entry - continuing with next state reactor. Exception "
454 "info: %s",
455 srname.c_str(), e.what());
456 }
457 }
458
459 for (auto & eg : this->currentState_->getEventGenerators())
460 {
461 auto egname = smacc2::demangleSymbol(typeid(*eg).name());
462 RCLCPP_INFO_STREAM(getLogger(), "event generator onEntry: " << egname);
463 try
464 {
465 eg->onEntry();
466 }
467 catch (const std::exception & e)
468 {
469 RCLCPP_ERROR(
470 getLogger(),
471 "[Event generator %s] Exception on Entry - continuing with next state reactor. Exception "
472 "info: %s",
473 egname.c_str(), e.what());
474 }
475 }
476
477 this->updateStatusMessage();
479}
std::vector< std::shared_ptr< StateReactor > > & getStateReactors()
Definition: smacc_state.hpp:80
std::vector< std::shared_ptr< SmaccEventGenerator > > & getEventGenerators()
Definition: smacc_state.hpp:82

References currentState_, smacc2::introspection::demangleSymbol(), smacc2::ISmaccState::getEventGenerators(), getLogger(), smacc2::ISmaccState::getStateReactors(), orthogonals_, smacc2::STATE_STEADY, 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 402 of file smacc_state_machine_impl.hpp.

403{
404 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
405
406 RCLCPP_DEBUG(
407 getLogger(),
408 "[State Machne] Initializating a new state '%s' and updating current state. Getting state "
409 "meta-information. number of orthogonals: %ld",
410 demangleSymbol(typeid(StateType).name()).c_str(), this->orthogonals_.size());
411
413 currentState_ = state;
414 currentStateInfo_ = stateMachineInfo_->getState<StateType>();
415}

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

569{
570 auto fullname = demangleSymbol(typeid(StateType).name());
571
572 // then call exit state
573 RCLCPP_WARN_STREAM(getLogger(), "state exit: " << fullname);
574
576 //this->unlockStateMachine("state exit");
577}

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

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

504{
506
507 auto fullname = demangleSymbol(typeid(StateType).name());
508 RCLCPP_WARN_STREAM(getLogger(), "exiting state: " << fullname);
509 // this->set_parameter("destroyed", true);
510
511 RCLCPP_INFO_STREAM(getLogger(), "Notification State Exit: leaving state " << state);
512 for (auto pair : this->orthogonals_)
513 {
514 auto & orthogonal = pair.second;
515 try
516 {
517 orthogonal->onExit();
518 }
519 catch (const std::exception & e)
520 {
521 RCLCPP_ERROR(
522 getLogger(),
523 "[Orthogonal %s] Exception onExit - continuing with next orthogonal. Exception info: %s",
524 pair.second->getName().c_str(), e.what());
525 }
526 }
527
528 for (auto & sr : state->getStateReactors())
529 {
530 auto srname = smacc2::demangleSymbol(typeid(*sr).name());
531 RCLCPP_INFO_STREAM(getLogger(), "state reactor OnExit: " << srname);
532 try
533 {
534 sr->onExit();
535 }
536 catch (const std::exception & e)
537 {
538 RCLCPP_ERROR(
539 getLogger(),
540 "[State Reactor %s] Exception on OnExit - continuing with next state reactor. Exception "
541 "info: %s",
542 srname.c_str(), e.what());
543 }
544 }
545
546 for (auto & eg : state->getEventGenerators())
547 {
548 auto egname = smacc2::demangleSymbol(typeid(*eg).name());
549 RCLCPP_INFO_STREAM(getLogger(), "event generator OnExit: " << egname);
550 try
551 {
552 eg->onExit();
553 }
554 catch (const std::exception & e)
555 {
556 RCLCPP_ERROR(
557 getLogger(),
558 "[State Reactor %s] Exception on OnExit - continuing with next state reactor. Exception "
559 "info: %s",
560 egname.c_str(), e.what());
561 }
562 }
563
564 //this->lockStateMachine("state exit");
565}

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

◆ onInitialized()

void smacc2::ISmaccStateMachine::onInitialized ( )
protected

Definition at line 143 of file smacc_state_machine.cpp.

144{
145 auto ros_clock = rclcpp::Clock::make_shared();
146 timer_ =
147 rclcpp::create_timer(nh_, ros_clock, 0.5s, [=]() { this->state_machine_visualization(); });
148}
rclcpp::TimerBase::SharedPtr timer_

References nh_, service_node_3::s, 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 213 of file smacc_state_machine_impl.hpp.

214{
215 auto evname = smacc2::introspection::demangleSymbol<EventType>();
216 RCLCPP_INFO_STREAM(getLogger(), "Event " << evname);
217 auto * ev = new EventType();
218 this->postEvent(ev, evlifetime);
219}
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)

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

175{
176 std::lock_guard<std::recursive_mutex> guard(eventQueueMutex_);
177
178#define eventtypename demangleSymbol<EventType>().c_str()
179
181
182 if (
183 evlifetime == EventLifeTime::CURRENT_STATE &&
186 {
187 RCLCPP_WARN_STREAM(
188 getLogger(),
189 "[ISmaccStateMachine] CURRENT STATE SCOPED EVENT DISCARDED, state is exiting/transitioning "
190 << eventtypename);
191 return;
192 // in this case we may lose/skip events, if this is not right for some cases we should create a
193 // queue to lock the events during the transitions. This issues appeared when a client
194 // asyncbehavior was posting an event meanwhile we were doing the transition, but the main
195 // thread was waiting for its correct finalization (with thread.join)
196 }
197
198 // when a postting event is requested by any component, client, or client behavior
199 // we reach this place. Now, we propagate the events to all the state state reactors to generate
200 // some more events
201
202 RCLCPP_DEBUG_STREAM(getLogger(), "[PostEvent entry point] " << eventtypename);
203 auto currentstate = currentState_;
204 if (currentstate != nullptr)
205 {
206 propagateEventToStateReactors(currentstate, ev);
207 }
208
209 this->signalDetector_->postEvent(ev);
210}
std::recursive_mutex eventQueueMutex_
void propagateEventToStateReactors(ISmaccState *st, EventType *ev)
void postEvent(EventType *ev)
#define eventtypename
void TRACEPOINT(spinOnce)
smacc2_event

References smacc2::CURRENT_STATE, currentState_, eventQueueMutex_, eventtypename, getLogger(), smacc2::SignalDetector::postEvent(), propagateEventToStateReactors(), signalDetector_, smacc2_event, smacc2::STATE_EXITING, stateMachineCurrentAction, TRACEPOINT(), and smacc2::TRANSITIONING.

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

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

581{
582 RCLCPP_DEBUG(
583 getLogger(), "PROPAGATING EVENT [%s] TO SRs [%s]: ", demangleSymbol<EventType>().c_str(),
584 st->getClassName().c_str());
585 for (auto & sb : st->getStateReactors())
586 {
587 sb->notifyEvent(ev);
588 }
589
590 auto * pst = st->getParentState();
591 if (pst != nullptr)
592 {
594 }
595}

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

132{
133 smacc2_msgs::msg::SmaccTransitionLogEntry transitionLogEntry;
134 transitionLogEntry.timestamp = this->nh_->now();
135 transitionInfoToMsg(transitionInfo, transitionLogEntry.transition);
136 this->transitionLogHistory_.push_back(transitionLogEntry);
137
138 transitionLogPub_->publish(transitionLogEntry);
139}
void transitionInfoToMsg(const SmaccTransitionInfo &transition, smacc2_msgs::msg::SmaccTransition &transitionMsg)
Definition: reflection.cpp:30

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)

Definition at line 126 of file smacc_state_machine_impl.hpp.

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

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

Referenced by mapBehavior(), 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

Reimplemented in smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >, smacc2::SmaccStateMachineBase< $SmName$, State1 >, smacc2::SmaccStateMachineBase< SmAdvancedRecovery1, MsRun >, smacc2::SmaccStateMachineBase< SmAtomic, State1 >, smacc2::SmaccStateMachineBase< SmAtomic24Hr, State1 >, smacc2::SmaccStateMachineBase< SmAtomicPerformanceTrace1, State1 >, smacc2::SmaccStateMachineBase< SmAtomicSubscribersPerformanceTest, State1 >, smacc2::SmaccStateMachineBase< SmAutowareAvp, StAcquireSensors >, smacc2::SmaccStateMachineBase< SmAwsWarehouseNavigation, StAcquireSensors >, smacc2::SmaccStateMachineBase< SmBranching, State1 >, smacc2::SmaccStateMachineBase< SmCoretestTransitionSpeed1, State1 >, smacc2::SmaccStateMachineBase< SmDanceBot, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotStrikesBack, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotWarehouse, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotWareHouse2, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotWareHouse3, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmFerrari, MsRun >, smacc2::SmaccStateMachineBase< SmHuskyBarrelSearch1, StAcquireSensors >, smacc2::SmaccStateMachineBase< SmMultiStage1, MsMode1 >, smacc2::SmaccStateMachineBase< SmPubsub1, MsRun >, smacc2::SmaccStateMachineBase< SmRespira1, MsRun >, smacc2::SmaccStateMachineBase< SmTestMoveitUr5Sim, StAcquireSensors >, and smacc2::SmaccStateMachineBase< SmThreeSome, MsRun >.

Definition at line 82 of file smacc_state_machine.cpp.

82{}

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

Here is the caller graph for this function:

◆ setGlobalSMData()

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

Definition at line 257 of file smacc_state_machine_impl.hpp.

258{
259 {
260 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
261 // RCLCPP_WARN(getLogger(),"set SM Data lock acquire");
262
263 globalData_[name] = {
264 [this, name]() {
265 std::stringstream ss;
266 auto val = any_cast<T>(globalData_[name].second);
267 ss << val;
268 return ss.str();
269 },
270 value};
271 }
272
273 this->updateStatusMessage();
274}

References globalData_, m_mutex_, and updateStatusMessage().

Referenced by cl_nav2z::CbNavigateGlobalPosition::execute(), mapBehavior(), $sm_name$::$SmName$::onInitialize(), sm_dance_bot::SmDanceBot::onInitialize(), sm_dance_bot_strikes_back::SmDanceBotStrikesBack::onInitialize(), sm_dance_bot_warehouse::SmDanceBotWarehouse::onInitialize(), sm_dance_bot_warehouse_2::SmDanceBotWareHouse2::onInitialize(), sm_dance_bot_warehouse_3::SmDanceBotWareHouse3::onInitialize(), 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 180 of file smacc_state_machine.cpp.

181{
182 std::lock_guard<std::recursive_mutex> lock(m_mutex_);
183
184 smacc2_msgs::msg::SmaccStateMachine state_machine_msg;
185 state_machine_msg.states = stateMachineInfo_->stateMsgs;
186
187 std::sort(
188 state_machine_msg.states.begin(), state_machine_msg.states.end(),
189 [](auto & a, auto & b) { return a.index < b.index; });
190 stateMachinePub_->publish(state_machine_msg);
191
192 status_msg_.header.stamp = this->nh_->now();
194}
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

Reimplemented in smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >, smacc2::SmaccStateMachineBase< $SmName$, State1 >, smacc2::SmaccStateMachineBase< SmAdvancedRecovery1, MsRun >, smacc2::SmaccStateMachineBase< SmAtomic, State1 >, smacc2::SmaccStateMachineBase< SmAtomic24Hr, State1 >, smacc2::SmaccStateMachineBase< SmAtomicPerformanceTrace1, State1 >, smacc2::SmaccStateMachineBase< SmAtomicSubscribersPerformanceTest, State1 >, smacc2::SmaccStateMachineBase< SmAutowareAvp, StAcquireSensors >, smacc2::SmaccStateMachineBase< SmAwsWarehouseNavigation, StAcquireSensors >, smacc2::SmaccStateMachineBase< SmBranching, State1 >, smacc2::SmaccStateMachineBase< SmCoretestTransitionSpeed1, State1 >, smacc2::SmaccStateMachineBase< SmDanceBot, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotStrikesBack, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotWarehouse, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotWareHouse2, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmDanceBotWareHouse3, MsDanceBotRunMode >, smacc2::SmaccStateMachineBase< SmFerrari, MsRun >, smacc2::SmaccStateMachineBase< SmHuskyBarrelSearch1, StAcquireSensors >, smacc2::SmaccStateMachineBase< SmMultiStage1, MsMode1 >, smacc2::SmaccStateMachineBase< SmPubsub1, MsRun >, smacc2::SmaccStateMachineBase< SmRespira1, MsRun >, smacc2::SmaccStateMachineBase< SmTestMoveitUr5Sim, StAcquireSensors >, and smacc2::SmaccStateMachineBase< SmThreeSome, MsRun >.

Definition at line 84 of file smacc_state_machine.cpp.

84{}

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

Here is the caller graph for this function:

◆ updateStatusMessage()

void smacc2::ISmaccStateMachine::updateStatusMessage ( )
private

Definition at line 94 of file smacc_state_machine.cpp.

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

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 Function Documentation

◆ ISmaccState

friend class ISmaccState
friend

Definition at line 222 of file smacc_state_machine.hpp.

◆ SignalDetector

friend class SignalDetector
friend

Definition at line 223 of file smacc_state_machine.hpp.

Member Data Documentation

◆ currentState_

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

Referenced by postEvent().

◆ globalData_

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

Definition at line 201 of file smacc_state_machine.hpp.

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

◆ m_mutex_

std::recursive_mutex smacc2::ISmaccStateMachine::m_mutex_
private

◆ nh_

rclcpp::Node::SharedPtr smacc2::ISmaccStateMachine::nh_
protected

◆ orthogonals_

std::map<std::string, std::shared_ptr<smacc2::ISmaccOrthogonal> > smacc2::ISmaccStateMachine::orthogonals_
protected

◆ runMode_

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

Definition at line 206 of file smacc_state_machine.hpp.

Referenced by ISmaccStateMachine(), and updateStatusMessage().

◆ signalDetector_

SignalDetector* smacc2::ISmaccStateMachine::signalDetector_
private

Definition at line 209 of file smacc_state_machine.hpp.

Referenced by ISmaccStateMachine(), and postEvent().

◆ stateCallbackConnections

std::list<boost::signals2::connection> smacc2::ISmaccStateMachine::stateCallbackConnections
private

◆ stateMachineCurrentAction

StateMachineInternalAction smacc2::ISmaccStateMachine::stateMachineCurrentAction
private

◆ stateMachineInfo_

std::shared_ptr<SmaccStateMachineInfo> smacc2::ISmaccStateMachine::stateMachineInfo_
protected

◆ stateMachinePub_

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

Definition at line 173 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_

unsigned long smacc2::ISmaccStateMachine::stateSeqCounter_
private

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

Referenced by state_machine_visualization(), and updateStatusMessage().

◆ timer_

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

Definition at line 172 of file smacc_state_machine.hpp.

Referenced by onInitialized().

◆ transitionHistoryService_

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

Definition at line 176 of file smacc_state_machine.hpp.

Referenced by initializeROS().

◆ transitionLogHistory_

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

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

Referenced by initializeROS(), and publishTransition().


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