SMACC2
Loading...
Searching...
No Matches
cl_nav2z::components::CpNav2ActionInterface Class Reference

#include <cp_nav2_action_interface.hpp>

Inheritance diagram for cl_nav2z::components::CpNav2ActionInterface:
Inheritance graph
Collaboration diagram for cl_nav2z::components::CpNav2ActionInterface:
Collaboration graph

Public Types

using ActionType = nav2_msgs::action::NavigateToPose
 
using Goal = ActionType::Goal
 
using Result = ActionType::Result
 
using Feedback = ActionType::Feedback
 
using GoalHandle = rclcpp_action::ClientGoalHandle<ActionType>
 
using WrappedResult = typename GoalHandle::WrappedResult
 
using ActionClient = smacc2::client_core_components::CpActionClient<ActionType>
 

Public Member Functions

 CpNav2ActionInterface ()=default
 
virtual ~CpNav2ActionInterface ()=default
 
std::shared_future< typename GoalHandle::SharedPtr > sendNavigationGoal (const geometry_msgs::msg::PoseStamped &target)
 
std::shared_future< typename GoalHandle::SharedPtr > sendGoal (Goal &goal)
 
bool cancelNavigation ()
 
bool isNavigationServerReady () const
 
void waitForNavigationServer ()
 
template<typename TOrthogonal , typename TClient >
void onComponentInitialization ()
 
void onInitialize () override
 
ActionClientgetActionClient () const
 
template<typename T >
smacc2::SmaccSignalConnection onNavigationSucceeded (void(T::*callback)(const WrappedResult &), T *object)
 
template<typename T >
smacc2::SmaccSignalConnection onNavigationAborted (void(T::*callback)(const WrappedResult &), T *object)
 
template<typename T >
smacc2::SmaccSignalConnection onNavigationCancelled (void(T::*callback)(const WrappedResult &), T *object)
 
template<typename T >
smacc2::SmaccSignalConnection onNavigationFeedback (void(T::*callback)(const Feedback &), T *object)
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
virtual std::string getName () const
 

Public Attributes

smacc2::SmaccSignal< void(const WrappedResult &)> onNavigationSucceeded_
 
smacc2::SmaccSignal< void(const WrappedResult &)> onNavigationAborted_
 
smacc2::SmaccSignal< void(const WrappedResult &)> onNavigationCancelled_
 
smacc2::SmaccSignal< void(const Feedback &)> onNavigationFeedback_
 
std::function< void(const WrappedResult &)> postNavigationSuccessEvent
 
std::function< void(const WrappedResult &)> postNavigationAbortedEvent
 
std::function< void(const WrappedResult &)> postNavigationCancelledEvent
 
std::function< void(const Feedback &)> postNavigationFeedbackEvent
 

Private Member Functions

void onNavigationSuccessCallback (const WrappedResult &result)
 
void onNavigationAbortedCallback (const WrappedResult &result)
 
void onNavigationCancelledCallback (const WrappedResult &result)
 
void onNavigationFeedbackCallback (const Feedback &feedback)
 

Private Attributes

smacc2::client_core_components::CpActionClient< ActionType > * actionClient_ = nullptr
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::ISmaccComponent
template<typename TOrthogonal , typename TClient >
void onComponentInitialization ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TComponent >
void requiresComponent (std::string name, TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (TArgs... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (std::string name, TArgs... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachinegetStateMachine ()
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachinestateMachine_
 
ISmaccClientowner_
 

Detailed Description

Definition at line 32 of file cp_nav2_action_interface.hpp.

Member Typedef Documentation

◆ ActionClient

◆ ActionType

using cl_nav2z::components::CpNav2ActionInterface::ActionType = nav2_msgs::action::NavigateToPose

Definition at line 36 of file cp_nav2_action_interface.hpp.

◆ Feedback

Definition at line 39 of file cp_nav2_action_interface.hpp.

◆ Goal

Definition at line 37 of file cp_nav2_action_interface.hpp.

◆ GoalHandle

using cl_nav2z::components::CpNav2ActionInterface::GoalHandle = rclcpp_action::ClientGoalHandle<ActionType>

Definition at line 40 of file cp_nav2_action_interface.hpp.

◆ Result

Definition at line 38 of file cp_nav2_action_interface.hpp.

◆ WrappedResult

using cl_nav2z::components::CpNav2ActionInterface::WrappedResult = typename GoalHandle::WrappedResult

Definition at line 41 of file cp_nav2_action_interface.hpp.

Constructor & Destructor Documentation

◆ CpNav2ActionInterface()

cl_nav2z::components::CpNav2ActionInterface::CpNav2ActionInterface ( )
default

◆ ~CpNav2ActionInterface()

virtual cl_nav2z::components::CpNav2ActionInterface::~CpNav2ActionInterface ( )
virtualdefault

Member Function Documentation

◆ cancelNavigation()

bool cl_nav2z::components::CpNav2ActionInterface::cancelNavigation ( )
inline

Definition at line 97 of file cp_nav2_action_interface.hpp.

98 {
99 if (!actionClient_)
100 {
101 RCLCPP_WARN(getLogger(), "[CpNav2ActionInterface] Action client not available for cancel!");
102 return false;
103 }
104
105 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Cancelling navigation goal");
106 return actionClient_->cancelGoal();
107 }
smacc2::client_core_components::CpActionClient< ActionType > * actionClient_
rclcpp::Logger getLogger() const

References actionClient_, and smacc2::ISmaccComponent::getLogger().

Referenced by cl_nav2z::CbNav2ZClientBehaviorBase::cancelGoal(), and cl_nav2z::CbAbortNavigation::onEntry().

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

◆ getActionClient()

ActionClient * cl_nav2z::components::CpNav2ActionInterface::getActionClient ( ) const
inline

Definition at line 183 of file cp_nav2_action_interface.hpp.

183{ return actionClient_; }

References actionClient_.

◆ isNavigationServerReady()

bool cl_nav2z::components::CpNav2ActionInterface::isNavigationServerReady ( ) const
inline

Definition at line 109 of file cp_nav2_action_interface.hpp.

109{ return actionClient_ && actionClient_->isServerReady(); }

References actionClient_.

◆ onComponentInitialization()

template<typename TOrthogonal , typename TClient >
void cl_nav2z::components::CpNav2ActionInterface::onComponentInitialization ( )
inline

Definition at line 121 of file cp_nav2_action_interface.hpp.

122 {
123 // Set up nav2-specific event posting functions
124 postNavigationSuccessEvent = [this](const WrappedResult & result)
125 {
127 ev->resultMessage = result;
128 this->postEvent(ev);
129 };
130
131 postNavigationAbortedEvent = [this](const WrappedResult & result)
132 {
134 ev->resultMessage = result;
135 this->postEvent(ev);
136 };
137
138 postNavigationCancelledEvent = [this](const WrappedResult & result)
139 {
141 ev->resultMessage = result;
142 this->postEvent(ev);
143 };
144
145 postNavigationFeedbackEvent = [this](const Feedback & feedback)
146 {
148 ev->feedbackMessage = feedback;
149 this->postEvent(ev);
150 };
151
152 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Component initialized");
153 }
std::function< void(const Feedback &)> postNavigationFeedbackEvent
std::function< void(const WrappedResult &)> postNavigationSuccessEvent
std::function< void(const WrappedResult &)> postNavigationCancelledEvent
std::function< void(const WrappedResult &)> postNavigationAbortedEvent

References smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::postEvent(), postNavigationAbortedEvent, postNavigationCancelledEvent, postNavigationFeedbackEvent, and postNavigationSuccessEvent.

Here is the call graph for this function:

◆ onInitialize()

void cl_nav2z::components::CpNav2ActionInterface::onInitialize ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccComponent.

Definition at line 155 of file cp_nav2_action_interface.hpp.

156 {
157 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Component initializing");
158
159 // Require the underlying action client component
160 this->requiresComponent(actionClient_, ComponentRequirement::HARD);
161
162 // Wire up signal connections from action client to nav2-specific signals
163 if (actionClient_)
164 {
165 // Connect action client signals to our nav2-specific signals and event posting using method pointers
166 // these are the main smacc signals in the action client, our navigation client behavior subscribes to them and reacts accordingly
167 // each derived behavior do something different in reaction to these signals
172
173 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Signal connections established");
174 }
175 else
176 {
177 RCLCPP_ERROR(
178 getLogger(), "[CpNav2ActionInterface] Action client not found during initialization!");
179 }
180 }
void onNavigationCancelledCallback(const WrappedResult &result)
void onNavigationSuccessCallback(const WrappedResult &result)
void onNavigationAbortedCallback(const WrappedResult &result)
void onNavigationFeedbackCallback(const Feedback &feedback)
void requiresComponent(TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)

References actionClient_, smacc2::ISmaccComponent::getLogger(), onNavigationAbortedCallback(), onNavigationCancelledCallback(), onNavigationFeedbackCallback(), onNavigationSuccessCallback(), and smacc2::ISmaccComponent::requiresComponent().

Here is the call graph for this function:

◆ onNavigationAborted()

template<typename T >
smacc2::SmaccSignalConnection cl_nav2z::components::CpNav2ActionInterface::onNavigationAborted ( void(T::* callback )(const WrappedResult &),
T * object )
inline

Definition at line 195 of file cp_nav2_action_interface.hpp.

197 {
198 return this->getStateMachine()->createSignalConnection(onNavigationAborted_, callback, object);
199 }
smacc2::SmaccSignal< void(const WrappedResult &)> onNavigationAborted_
ISmaccStateMachine * getStateMachine()
smacc2::SmaccSignalConnection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)

References smacc2::ISmaccStateMachine::createSignalConnection(), and smacc2::ISmaccComponent::getStateMachine().

Referenced by cl_nav2z::CbNav2ZClientBehaviorBase::onNavigationAborted(), and cl_nav2z::CpWaypointNavigator::sendNextGoal().

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

◆ onNavigationAbortedCallback()

void cl_nav2z::components::CpNav2ActionInterface::onNavigationAbortedCallback ( const WrappedResult & result)
inlineprivate

Definition at line 230 of file cp_nav2_action_interface.hpp.

231 {
232 RCLCPP_WARN(getLogger(), "[CpNav2ActionInterface] Navigation aborted");
233 onNavigationAborted_(result);
235 {
237 }
238 }

References smacc2::ISmaccComponent::getLogger(), onNavigationAborted_, and postNavigationAbortedEvent.

Referenced by onInitialize().

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

◆ onNavigationCancelled()

template<typename T >
smacc2::SmaccSignalConnection cl_nav2z::components::CpNav2ActionInterface::onNavigationCancelled ( void(T::* callback )(const WrappedResult &),
T * object )
inline

Definition at line 202 of file cp_nav2_action_interface.hpp.

204 {
206 onNavigationCancelled_, callback, object);
207 }
smacc2::SmaccSignal< void(const WrappedResult &)> onNavigationCancelled_

References smacc2::ISmaccStateMachine::createSignalConnection(), and smacc2::ISmaccComponent::getStateMachine().

Referenced by cl_nav2z::CbNav2ZClientBehaviorBase::onNavigationCancelled(), and cl_nav2z::CpWaypointNavigator::sendNextGoal().

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

◆ onNavigationCancelledCallback()

void cl_nav2z::components::CpNav2ActionInterface::onNavigationCancelledCallback ( const WrappedResult & result)
inlineprivate

Definition at line 240 of file cp_nav2_action_interface.hpp.

241 {
242 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Navigation cancelled");
245 {
247 }
248 }

References smacc2::ISmaccComponent::getLogger(), onNavigationCancelled_, and postNavigationCancelledEvent.

Referenced by onInitialize().

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

◆ onNavigationFeedback()

template<typename T >
smacc2::SmaccSignalConnection cl_nav2z::components::CpNav2ActionInterface::onNavigationFeedback ( void(T::* callback )(const Feedback &),
T * object )
inline

Definition at line 210 of file cp_nav2_action_interface.hpp.

212 {
213 return this->getStateMachine()->createSignalConnection(onNavigationFeedback_, callback, object);
214 }
smacc2::SmaccSignal< void(const Feedback &)> onNavigationFeedback_

References smacc2::ISmaccStateMachine::createSignalConnection(), and smacc2::ISmaccComponent::getStateMachine().

Here is the call graph for this function:

◆ onNavigationFeedbackCallback()

void cl_nav2z::components::CpNav2ActionInterface::onNavigationFeedbackCallback ( const Feedback & feedback)
inlineprivate

Definition at line 250 of file cp_nav2_action_interface.hpp.

251 {
252 RCLCPP_DEBUG(getLogger(), "[CpNav2ActionInterface] Navigation feedback received");
253 onNavigationFeedback_(feedback);
255 {
257 }
258 }

References smacc2::ISmaccComponent::getLogger(), onNavigationFeedback_, and postNavigationFeedbackEvent.

Referenced by onInitialize().

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

◆ onNavigationSucceeded()

template<typename T >
smacc2::SmaccSignalConnection cl_nav2z::components::CpNav2ActionInterface::onNavigationSucceeded ( void(T::* callback )(const WrappedResult &),
T * object )
inline

Definition at line 187 of file cp_nav2_action_interface.hpp.

189 {
191 onNavigationSucceeded_, callback, object);
192 }
smacc2::SmaccSignal< void(const WrappedResult &)> onNavigationSucceeded_

References smacc2::ISmaccStateMachine::createSignalConnection(), and smacc2::ISmaccComponent::getStateMachine().

Referenced by cl_nav2z::CbNav2ZClientBehaviorBase::onNavigationSucceeded(), and cl_nav2z::CpWaypointNavigator::sendNextGoal().

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

◆ onNavigationSuccessCallback()

void cl_nav2z::components::CpNav2ActionInterface::onNavigationSuccessCallback ( const WrappedResult & result)
inlineprivate

Definition at line 220 of file cp_nav2_action_interface.hpp.

221 {
222 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Navigation succeeded");
225 {
227 }
228 }

References smacc2::ISmaccComponent::getLogger(), onNavigationSucceeded_, and postNavigationSuccessEvent.

Referenced by onInitialize().

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

◆ sendGoal()

std::shared_future< typename GoalHandle::SharedPtr > cl_nav2z::components::CpNav2ActionInterface::sendGoal ( Goal & goal)
inline

Definition at line 86 of file cp_nav2_action_interface.hpp.

87 {
88 if (!actionClient_)
89 {
90 RCLCPP_ERROR(getLogger(), "[CpNav2ActionInterface] Action client not available!");
91 throw std::runtime_error("Action client not initialized");
92 }
93
94 return actionClient_->sendGoal(goal);
95 }

References actionClient_, and smacc2::ISmaccComponent::getLogger().

Referenced by cl_nav2z::CbNav2ZClientBehaviorBase::sendGoal(), and cl_nav2z::CpWaypointNavigator::sendNextGoal().

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

◆ sendNavigationGoal()

std::shared_future< typename GoalHandle::SharedPtr > cl_nav2z::components::CpNav2ActionInterface::sendNavigationGoal ( const geometry_msgs::msg::PoseStamped & target)
inline

Definition at line 60 of file cp_nav2_action_interface.hpp.

62 {
63 if (!actionClient_)
64 {
65 RCLCPP_ERROR(getLogger(), "[CpNav2ActionInterface] Action client not available!");
66 throw std::runtime_error("Action client not initialized");
67 }
68
69 Goal goal;
70 goal.pose = target;
71
72 // Set default behavior_tree if not specified
73 if (goal.behavior_tree.empty())
74 {
75 goal.behavior_tree = ""; // Let Nav2 use default behavior tree
76 }
77
78 RCLCPP_INFO_STREAM(
79 getLogger(), "[CpNav2ActionInterface] Sending navigation goal to: "
80 << "x=" << target.pose.position.x << ", y=" << target.pose.position.y
81 << ", frame=" << target.header.frame_id);
82
83 return actionClient_->sendGoal(goal);
84 }

References actionClient_, and smacc2::ISmaccComponent::getLogger().

Here is the call graph for this function:

◆ waitForNavigationServer()

void cl_nav2z::components::CpNav2ActionInterface::waitForNavigationServer ( )
inline

Definition at line 111 of file cp_nav2_action_interface.hpp.

112 {
113 if (actionClient_)
114 {
115 actionClient_->waitForServer();
116 }
117 }

References actionClient_.

Member Data Documentation

◆ actionClient_

smacc2::client_core_components::CpActionClient<ActionType>* cl_nav2z::components::CpNav2ActionInterface::actionClient_ = nullptr
private

◆ onNavigationAborted_

smacc2::SmaccSignal<void(const WrappedResult &)> cl_nav2z::components::CpNav2ActionInterface::onNavigationAborted_

Definition at line 46 of file cp_nav2_action_interface.hpp.

Referenced by onNavigationAbortedCallback().

◆ onNavigationCancelled_

smacc2::SmaccSignal<void(const WrappedResult &)> cl_nav2z::components::CpNav2ActionInterface::onNavigationCancelled_

Definition at line 47 of file cp_nav2_action_interface.hpp.

Referenced by onNavigationCancelledCallback().

◆ onNavigationFeedback_

smacc2::SmaccSignal<void(const Feedback &)> cl_nav2z::components::CpNav2ActionInterface::onNavigationFeedback_

Definition at line 48 of file cp_nav2_action_interface.hpp.

Referenced by onNavigationFeedbackCallback().

◆ onNavigationSucceeded_

smacc2::SmaccSignal<void(const WrappedResult &)> cl_nav2z::components::CpNav2ActionInterface::onNavigationSucceeded_

Definition at line 45 of file cp_nav2_action_interface.hpp.

Referenced by onNavigationSuccessCallback().

◆ postNavigationAbortedEvent

std::function<void(const WrappedResult &)> cl_nav2z::components::CpNav2ActionInterface::postNavigationAbortedEvent

◆ postNavigationCancelledEvent

std::function<void(const WrappedResult &)> cl_nav2z::components::CpNav2ActionInterface::postNavigationCancelledEvent

◆ postNavigationFeedbackEvent

std::function<void(const Feedback &)> cl_nav2z::components::CpNav2ActionInterface::postNavigationFeedbackEvent

◆ postNavigationSuccessEvent

std::function<void(const WrappedResult &)> cl_nav2z::components::CpNav2ActionInterface::postNavigationSuccessEvent

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