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

180{ 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 this->postEvent(ev);
128 };
129
130 postNavigationAbortedEvent = [this](const WrappedResult & result)
131 {
133 this->postEvent(ev);
134 };
135
136 postNavigationCancelledEvent = [this](const WrappedResult & result)
137 {
139 this->postEvent(ev);
140 };
141
142 postNavigationFeedbackEvent = [this](const Feedback & feedback)
143 {
145 //ev->feedbackMessage = feedback;
146 this->postEvent(ev);
147 };
148
149 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Component initialized");
150 }
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 152 of file cp_nav2_action_interface.hpp.

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

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 >
boost::signals2::connection cl_nav2z::components::CpNav2ActionInterface::onNavigationAborted ( void(T::* callback )(const WrappedResult &),
T * object )
inline

Definition at line 192 of file cp_nav2_action_interface.hpp.

194 {
195 return this->getStateMachine()->createSignalConnection(onNavigationAborted_, callback, object);
196 }
smacc2::SmaccSignal< void(const WrappedResult &)> onNavigationAborted_
ISmaccStateMachine * getStateMachine()
boost::signals2::connection 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 227 of file cp_nav2_action_interface.hpp.

228 {
229 RCLCPP_WARN(getLogger(), "[CpNav2ActionInterface] Navigation aborted");
230 onNavigationAborted_(result);
232 {
234 }
235 }

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 >
boost::signals2::connection cl_nav2z::components::CpNav2ActionInterface::onNavigationCancelled ( void(T::* callback )(const WrappedResult &),
T * object )
inline

Definition at line 199 of file cp_nav2_action_interface.hpp.

201 {
203 onNavigationCancelled_, callback, object);
204 }
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 237 of file cp_nav2_action_interface.hpp.

238 {
239 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Navigation cancelled");
242 {
244 }
245 }

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 >
boost::signals2::connection cl_nav2z::components::CpNav2ActionInterface::onNavigationFeedback ( void(T::* callback )(const Feedback &),
T * object )
inline

Definition at line 207 of file cp_nav2_action_interface.hpp.

209 {
210 return this->getStateMachine()->createSignalConnection(onNavigationFeedback_, callback, object);
211 }
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 247 of file cp_nav2_action_interface.hpp.

248 {
249 RCLCPP_DEBUG(getLogger(), "[CpNav2ActionInterface] Navigation feedback received");
250 onNavigationFeedback_(feedback);
252 {
254 }
255 }

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 >
boost::signals2::connection cl_nav2z::components::CpNav2ActionInterface::onNavigationSucceeded ( void(T::* callback )(const WrappedResult &),
T * object )
inline

Definition at line 184 of file cp_nav2_action_interface.hpp.

186 {
188 onNavigationSucceeded_, callback, object);
189 }
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 217 of file cp_nav2_action_interface.hpp.

218 {
219 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Navigation succeeded");
222 {
224 }
225 }

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: