SMACC2
Loading...
Searching...
No Matches
cl_nav2z::CbWaitNav2Nodes Class Reference

#include <cb_wait_nav2_nodes.hpp>

Inheritance diagram for cl_nav2z::CbWaitNav2Nodes:
Inheritance graph
Collaboration diagram for cl_nav2z::CbWaitNav2Nodes:
Collaboration graph

Public Member Functions

 CbWaitNav2Nodes (std::vector< Nav2Nodes > waitNodes={ Nav2Nodes::PlannerServer, Nav2Nodes::ControllerServer, Nav2Nodes::BtNavigator})
 
void runtimeConfigure () override
 
void onEntry () override
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
 SmaccAsyncClientBehavior ()=default
 
 ~SmaccAsyncClientBehavior () override
 
 SmaccAsyncClientBehavior (const SmaccAsyncClientBehavior &)=delete
 
SmaccAsyncClientBehavior & operator= (const SmaccAsyncClientBehavior &)=delete
 
 SmaccAsyncClientBehavior (SmaccAsyncClientBehavior &&)=delete
 
SmaccAsyncClientBehavior & operator= (SmaccAsyncClientBehavior &&)=delete
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFailure (TCallbackMethod callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
 ISmaccClientBehavior (const ISmaccClientBehavior &)=delete
 
ISmaccClientBehavior & operator= (const ISmaccClientBehavior &)=delete
 
 ISmaccClientBehavior (ISmaccClientBehavior &&)=delete
 
ISmaccClientBehavior & operator= (ISmaccClientBehavior &&)=delete
 
ISmaccStateMachine * getStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename SmaccComponentType >
void requiresComponent (const std::string &name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
virtual void onExit ()
 

Private Member Functions

void onMessageReceived (const bond::msg::Status &msg)
 

Private Attributes

CpBondListener * bondListener_ = nullptr
 
std::map< Nav2Nodes, bool > receivedAliveMsg_
 
std::vector< Nav2Nodes > waitNodes_
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::SmaccAsyncClientBehavior
void postSuccessEvent ()
 
void postFailureEvent ()
 
void dispose () override
 
bool isShutdownRequested ()
 onEntry is executed in a new thread. However the current state cannot be left until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccState * getCurrentState ()
 
void postInitializationFailureEvent (const std::string &what)
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 
std::string getTraceStateName () const
 
std::string getTraceOrthogonalName () const
 

Detailed Description

Definition at line 44 of file cb_wait_nav2_nodes.hpp.

Constructor & Destructor Documentation

◆ CbWaitNav2Nodes()

cl_nav2z::CbWaitNav2Nodes::CbWaitNav2Nodes ( std::vector< Nav2Nodes > waitNodes = { Nav2Nodes::PlannerServer, Nav2Nodes::ControllerServer, Nav2Nodes::BtNavigator})

Definition at line 26 of file cb_wait_nav2_nodes.cpp.

26: waitNodes_(waitNodes) {}
std::vector< Nav2Nodes > waitNodes_

Member Function Documentation

◆ onEntry()

void cl_nav2z::CbWaitNav2Nodes::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 91 of file cb_wait_nav2_nodes.cpp.

92{
93 if (bondListener_ == nullptr)
94 {
95 this->postFailureEvent();
96 return;
97 }
98 RCLCPP_INFO(
99 getLogger(), "[CbWaitNav2Nodes] waiting for heartbeats on %s",
100 bondListener_->getTopicName().c_str());
101}
const std::string & getTopicName() const
virtual rclcpp::Logger getLogger() const

References bondListener_, smacc2::ISmaccClientBehavior::getLogger(), cl_nav2z::CpBondListener::getTopicName(), and smacc2::SmaccAsyncClientBehavior::postFailureEvent().

Here is the call graph for this function:

◆ onMessageReceived()

void cl_nav2z::CbWaitNav2Nodes::onMessageReceived ( const bond::msg::Status & msg)
private

Definition at line 49 of file cb_wait_nav2_nodes.cpp.

50{
51 auto value = fromString(msg.id);
52 bool updated = false;
53 // RCLCPP_INFO(getLogger(), "[CbWaitNav2Nodes] received '%s'", msg.id.c_str());
54
55 if (receivedAliveMsg_.count(value) && !receivedAliveMsg_[value])
56 {
57 RCLCPP_INFO(getLogger(), "[CbWaitNav2Nodes] '%s' alive received", msg.id.c_str());
58 receivedAliveMsg_[value] = true;
59 updated = true;
60 }
61
62 if (updated)
63 {
64 bool success = true;
65 std::stringstream ss;
66 for (const auto & pair : receivedAliveMsg_)
67 {
68 if (!pair.second)
69 {
70 success = false;
71 }
72 ss << "- " << toString(pair.first) << ": " << (pair.second ? "ALIVE" : "WAITING") << '\n';
73 }
74
75 RCLCPP_INFO_STREAM(
76 getLogger(), "[CbWaitNav2Nodes] waiting nodes status:" << '\n'
77 << ss.str().c_str());
78
79 if (success)
80 {
81 RCLCPP_INFO(getLogger(), "[CbWaitNav2Nodes] success event");
82 this->postSuccessEvent();
83 }
84 else
85 {
86 RCLCPP_INFO(getLogger(), "[CbWaitNav2Nodes] still missing nodes");
87 }
88 }
89}
std::map< Nav2Nodes, bool > receivedAliveMsg_
Nav2Nodes fromString(const std::string &str)
std::string toString(Nav2Nodes value)

References cl_nav2z::fromString(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), receivedAliveMsg_, and cl_nav2z::toString().

Referenced by runtimeConfigure().

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

◆ runtimeConfigure()

void cl_nav2z::CbWaitNav2Nodes::runtimeConfigure ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 28 of file cb_wait_nav2_nodes.cpp.

29{
30 std::stringstream ss;
31 for (auto v : waitNodes_)
32 {
33 receivedAliveMsg_[v] = false;
34 ss << "[CbWaitNav2Nodes] - " << toString(v) << ": waiting" << '\n';
35 }
36 RCLCPP_INFO(getLogger(), "%s", ss.str().c_str());
37
39 if (bondListener_ == nullptr)
40 {
41 RCLCPP_ERROR(getLogger(), "[CbWaitNav2Nodes] no CpBondListener component on the nav2 client");
42 return;
43 }
44 // Connected on the state machine thread through the state-lifetime signal map: dispose finalizes
45 // the slot and waits for a callback in flight, so no heartbeat runs into a disposed behavior.
47}
void onMessageReceived(const bond::msg::Status &msg)
smacc2::SmaccSignalConnection onBondMessage(void(T::*callback)(const bond::msg::Status &), T *object)
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)

References bondListener_, smacc2::ISmaccClientBehavior::getLogger(), cl_nav2z::CpBondListener::onBondMessage(), onMessageReceived(), receivedAliveMsg_, smacc2::ISmaccClientBehavior::requiresComponent(), cl_nav2z::toString(), and waitNodes_.

Here is the call graph for this function:

Member Data Documentation

◆ bondListener_

CpBondListener* cl_nav2z::CbWaitNav2Nodes::bondListener_ = nullptr
private

Definition at line 58 of file cb_wait_nav2_nodes.hpp.

Referenced by onEntry(), and runtimeConfigure().

◆ receivedAliveMsg_

std::map<Nav2Nodes, bool> cl_nav2z::CbWaitNav2Nodes::receivedAliveMsg_
private

Definition at line 59 of file cb_wait_nav2_nodes.hpp.

Referenced by onMessageReceived(), and runtimeConfigure().

◆ waitNodes_

std::vector<Nav2Nodes> cl_nav2z::CbWaitNav2Nodes::waitNodes_
private

Definition at line 61 of file cb_wait_nav2_nodes.hpp.

Referenced by runtimeConfigure().


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