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 TSourceObject >
void onComponentInitialization ()
 
void onInitialize () override
 
template<typename T >
boost::signals2::connection onNavigationSucceeded (void(T::*callback)(const WrappedResult &), T *object)
 
template<typename T >
boost::signals2::connection onNavigationAborted (void(T::*callback)(const WrappedResult &), T *object)
 
template<typename T >
boost::signals2::connection onNavigationCancelled (void(T::*callback)(const WrappedResult &), T *object)
 
template<typename T >
boost::signals2::connection onNavigationFeedback (void(T::*callback)(const Feedback &), T *object)
 
ActionClientgetActionClient () const
 
- 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 onNavigationSuccess (const WrappedResult &result)
 
void onNavigationAborted (const WrappedResult &result)
 
void onNavigationCancelled (const WrappedResult &result)
 
void onNavigationFeedback (const Feedback &feedback)
 
Goal createNavigationGoal (const geometry_msgs::msg::PoseStamped &target)
 

Private Attributes

ActionClientactionClient_ = 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 onOrthogonalAllocation ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, bool throwExceptionIfNotExist=false)
 
template<typename TComponent >
void requiresComponent (std::string name, TComponent *&requiredComponentStorage, bool throwExceptionIfNotExist=false)
 
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 31 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 35 of file cp_nav2_action_interface.hpp.

◆ Feedback

Definition at line 38 of file cp_nav2_action_interface.hpp.

◆ Goal

Definition at line 36 of file cp_nav2_action_interface.hpp.

◆ GoalHandle

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

Definition at line 39 of file cp_nav2_action_interface.hpp.

◆ Result

Definition at line 37 of file cp_nav2_action_interface.hpp.

◆ WrappedResult

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

Definition at line 40 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 89 of file cp_nav2_action_interface.hpp.

90 {
91 if (!actionClient_)
92 {
93 RCLCPP_WARN(getLogger(), "[CpNav2ActionInterface] Action client not available for cancel!");
94 return false;
95 }
96
97 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Cancelling navigation goal");
98 return actionClient_->cancelGoal();
99 }
rclcpp::Logger getLogger() const

References actionClient_, smacc2::client_core_components::CpActionClient< ActionType >::cancelGoal(), 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:

◆ createNavigationGoal()

Goal cl_nav2z::components::CpNav2ActionInterface::createNavigationGoal ( const geometry_msgs::msg::PoseStamped & target)
inlineprivate

Definition at line 246 of file cp_nav2_action_interface.hpp.

247 {
248 Goal goal;
249 goal.pose = target;
250
251 // Set default behavior_tree if not specified
252 if (goal.behavior_tree.empty())
253 {
254 goal.behavior_tree = ""; // Let Nav2 use default behavior tree
255 }
256
257 return goal;
258 }

Referenced by sendNavigationGoal().

Here is the caller graph for this function:

◆ getActionClient()

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

Definition at line 199 of file cp_nav2_action_interface.hpp.

199{ return actionClient_; }

References actionClient_.

◆ isNavigationServerReady()

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

◆ onComponentInitialization()

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

Definition at line 113 of file cp_nav2_action_interface.hpp.

114 {
115 // Require the underlying action client component
117
118 // Set up nav2-specific event posting functions
119 postNavigationSuccessEvent = [this](const WrappedResult & result)
120 {
122 this->postEvent(ev);
123 };
124
125 postNavigationAbortedEvent = [this](const WrappedResult & result)
126 {
128 this->postEvent(ev);
129 };
130
131 postNavigationCancelledEvent = [this](const WrappedResult & result)
132 {
134 this->postEvent(ev);
135 };
136
137 postNavigationFeedbackEvent = [this](const Feedback & feedback)
138 {
140 ev->feedbackMessage = feedback;
141 this->postEvent(ev);
142 };
143
144 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Component initialized");
145 }
std::function< void(const Feedback &)> postNavigationFeedbackEvent
std::function< void(const WrappedResult &)> postNavigationSuccessEvent
std::function< void(const WrappedResult &)> postNavigationCancelledEvent
std::function< void(const WrappedResult &)> postNavigationAbortedEvent
void requiresComponent(TComponent *&requiredComponentStorage, bool throwExceptionIfNotExist=false)

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

Here is the call graph for this function:

◆ onInitialize()

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

Reimplemented from smacc2::ISmaccComponent.

Definition at line 147 of file cp_nav2_action_interface.hpp.

148 {
149 // Wire up signal connections from action client to nav2-specific signals
150 if (actionClient_)
151 {
152 // Connect action client signals to our nav2-specific signals and event posting using method pointers
157
158 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Signal connections established");
159 }
160 else
161 {
162 RCLCPP_ERROR(
163 getLogger(), "[CpNav2ActionInterface] Action client not found during initialization!");
164 }
165 }
void onNavigationSuccess(const WrappedResult &result)
boost::signals2::connection onNavigationCancelled(void(T::*callback)(const WrappedResult &), T *object)
boost::signals2::connection onNavigationFeedback(void(T::*callback)(const Feedback &), T *object)
boost::signals2::connection onNavigationAborted(void(T::*callback)(const WrappedResult &), T *object)
boost::signals2::connection onSucceeded(void(T::*callback)(const WrappedResult &), T *object)
boost::signals2::connection onCancelled(void(T::*callback)(const WrappedResult &), T *object)
boost::signals2::connection onFeedback(void(T::*callback)(const Feedback &), T *object)
boost::signals2::connection onAborted(void(T::*callback)(const WrappedResult &), T *object)

References actionClient_, smacc2::ISmaccComponent::getLogger(), smacc2::client_core_components::CpActionClient< ActionType >::onAborted(), smacc2::client_core_components::CpActionClient< ActionType >::onCancelled(), smacc2::client_core_components::CpActionClient< ActionType >::onFeedback(), onNavigationAborted(), onNavigationCancelled(), onNavigationFeedback(), onNavigationSuccess(), and smacc2::client_core_components::CpActionClient< ActionType >::onSucceeded().

Here is the call graph for this function:

◆ onNavigationAborted() [1/2]

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

Definition at line 215 of file cp_nav2_action_interface.hpp.

216 {
217 RCLCPP_WARN(getLogger(), "[CpNav2ActionInterface] Navigation aborted");
218 onNavigationAborted_(result);
220 {
222 }
223 }
smacc2::SmaccSignal< void(const WrappedResult &)> onNavigationAborted_

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

Here is the call graph for this function:

◆ onNavigationAborted() [2/2]

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

Definition at line 177 of file cp_nav2_action_interface.hpp.

179 {
180 return this->getStateMachine()->createSignalConnection(onNavigationAborted_, callback, object);
181 }
ISmaccStateMachine * getStateMachine()
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)

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

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

◆ onNavigationCancelled() [1/2]

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

Definition at line 225 of file cp_nav2_action_interface.hpp.

226 {
227 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Navigation cancelled");
230 {
232 }
233 }
smacc2::SmaccSignal< void(const WrappedResult &)> onNavigationCancelled_

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

Here is the call graph for this function:

◆ onNavigationCancelled() [2/2]

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

Definition at line 184 of file cp_nav2_action_interface.hpp.

186 {
188 onNavigationCancelled_, callback, object);
189 }

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

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

◆ onNavigationFeedback() [1/2]

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

Definition at line 235 of file cp_nav2_action_interface.hpp.

236 {
237 RCLCPP_DEBUG(getLogger(), "[CpNav2ActionInterface] Navigation feedback received");
238 onNavigationFeedback_(feedback);
240 {
242 }
243 }
smacc2::SmaccSignal< void(const Feedback &)> onNavigationFeedback_

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

Here is the call graph for this function:

◆ onNavigationFeedback() [2/2]

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

Definition at line 192 of file cp_nav2_action_interface.hpp.

194 {
195 return this->getStateMachine()->createSignalConnection(onNavigationFeedback_, callback, object);
196 }

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

Referenced by onInitialize().

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

◆ onNavigationSucceeded()

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

Definition at line 169 of file cp_nav2_action_interface.hpp.

171 {
173 onNavigationSucceeded_, callback, object);
174 }
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:

◆ onNavigationSuccess()

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

Definition at line 205 of file cp_nav2_action_interface.hpp.

206 {
207 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Navigation succeeded");
210 {
212 }
213 }

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 78 of file cp_nav2_action_interface.hpp.

79 {
80 if (!actionClient_)
81 {
82 RCLCPP_ERROR(getLogger(), "[CpNav2ActionInterface] Action client not available!");
83 throw std::runtime_error("Action client not initialized");
84 }
85
86 return actionClient_->sendGoal(goal);
87 }
std::shared_future< typename GoalHandle::SharedPtr > sendGoal(Goal &goal, typename smacc2::SmaccSignal< void(const WrappedResult &)>::WeakPtr resultCallback=typename smacc2::SmaccSignal< void(const WrappedResult &)>::WeakPtr())

References actionClient_, smacc2::ISmaccComponent::getLogger(), and smacc2::client_core_components::CpActionClient< ActionType >::sendGoal().

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 59 of file cp_nav2_action_interface.hpp.

61 {
62 if (!actionClient_)
63 {
64 RCLCPP_ERROR(getLogger(), "[CpNav2ActionInterface] Action client not available!");
65 throw std::runtime_error("Action client not initialized");
66 }
67
68 auto goal = createNavigationGoal(target);
69
70 RCLCPP_INFO_STREAM(
71 getLogger(), "[CpNav2ActionInterface] Sending navigation goal to: "
72 << "x=" << target.pose.position.x << ", y=" << target.pose.position.y
73 << ", frame=" << target.header.frame_id);
74
75 return actionClient_->sendGoal(goal);
76 }
Goal createNavigationGoal(const geometry_msgs::msg::PoseStamped &target)

References actionClient_, createNavigationGoal(), smacc2::ISmaccComponent::getLogger(), and smacc2::client_core_components::CpActionClient< ActionType >::sendGoal().

Here is the call graph for this function:

◆ waitForNavigationServer()

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

Definition at line 103 of file cp_nav2_action_interface.hpp.

References actionClient_, and smacc2::client_core_components::CpActionClient< ActionType >::waitForServer().

Here is the call graph for this function:

Member Data Documentation

◆ actionClient_

ActionClient* cl_nav2z::components::CpNav2ActionInterface::actionClient_ = nullptr
private

◆ onNavigationAborted_

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

Definition at line 45 of file cp_nav2_action_interface.hpp.

Referenced by onNavigationAborted().

◆ onNavigationCancelled_

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

Definition at line 46 of file cp_nav2_action_interface.hpp.

Referenced by onNavigationCancelled().

◆ onNavigationFeedback_

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

Definition at line 47 of file cp_nav2_action_interface.hpp.

Referenced by onNavigationFeedback().

◆ onNavigationSucceeded_

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

Definition at line 44 of file cp_nav2_action_interface.hpp.

Referenced by onNavigationSuccess().

◆ postNavigationAbortedEvent

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

Definition at line 51 of file cp_nav2_action_interface.hpp.

Referenced by onComponentInitialization(), and onNavigationAborted().

◆ postNavigationCancelledEvent

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

◆ postNavigationFeedbackEvent

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

Definition at line 53 of file cp_nav2_action_interface.hpp.

Referenced by onComponentInitialization(), and onNavigationFeedback().

◆ postNavigationSuccessEvent

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

Definition at line 50 of file cp_nav2_action_interface.hpp.

Referenced by onNavigationSuccess().


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