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
 
 ~CpNav2ActionInterface () override=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
 
ActionClient * getActionClient () 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 ()
 
 ISmaccComponent (const ISmaccComponent &)=delete
 
ISmaccComponent & operator= (const ISmaccComponent &)=delete
 
 ISmaccComponent (ISmaccComponent &&)=delete
 
ISmaccComponent & operator= (ISmaccComponent &&)=delete
 
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 (const 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 (const TArgs &... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (const std::string &name, const TArgs &... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachine * getStateMachine ()
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachine * stateMachine_ = nullptr
 
ISmaccClient * owner_ = nullptr
 

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()

cl_nav2z::components::CpNav2ActionInterface::~CpNav2ActionInterface ( )
overridedefault

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

186{ 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 {
126 auto ev =
128 ev->resultMessage = result;
129 this->postEvent(ev);
130 };
131
132 postNavigationAbortedEvent = [this](const WrappedResult & result)
133 {
135 ev->resultMessage = result;
136 this->postEvent(ev);
137 };
138
139 postNavigationCancelledEvent = [this](const WrappedResult & result)
140 {
141 auto ev =
143 ev->resultMessage = result;
144 this->postEvent(ev);
145 };
146
147 postNavigationFeedbackEvent = [this](const Feedback & feedback)
148 {
149 auto ev =
151 ev->feedbackMessage = feedback;
152 this->postEvent(ev);
153 };
154
155 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Component initialized");
156 }
std::function< void(const Feedback &)> postNavigationFeedbackEvent
std::function< void(const WrappedResult &)> postNavigationSuccessEvent
std::function< void(const WrappedResult &)> postNavigationCancelledEvent
std::function< void(const WrappedResult &)> postNavigationAbortedEvent
boost::intrusive_ptr< EventType > makeEvent(Args &&... args)

References smacc2::ISmaccComponent::getLogger(), smacc2::makeEvent(), 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 158 of file cp_nav2_action_interface.hpp.

159 {
160 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Component initializing");
161
162 // Require the underlying action client component
163 this->requiresComponent(actionClient_, ComponentRequirement::HARD);
164
165 // Wire up signal connections from action client to nav2-specific signals
166 if (actionClient_)
167 {
168 // Connect action client signals to our nav2-specific signals and event posting using method pointers
169 // these are the main smacc signals in the action client, our navigation client behavior subscribes to them and reacts accordingly
170 // each derived behavior do something different in reaction to these signals
175
176 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Signal connections established");
177 }
178 else
179 {
180 RCLCPP_ERROR(
181 getLogger(), "[CpNav2ActionInterface] Action client not found during initialization!");
182 }
183 }
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 198 of file cp_nav2_action_interface.hpp.

200 {
201 return this->getStateMachine()->createSignalConnection(onNavigationAborted_, callback, object);
202 }
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::CbAbortNavigation::onEntry(), 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 233 of file cp_nav2_action_interface.hpp.

234 {
235 RCLCPP_WARN(getLogger(), "[CpNav2ActionInterface] Navigation aborted");
236 onNavigationAborted_(result);
238 {
240 }
241 }

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

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

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

Referenced by cl_nav2z::CbAbortNavigation::onEntry(), 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 243 of file cp_nav2_action_interface.hpp.

244 {
245 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Navigation cancelled");
248 {
250 }
251 }

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

215 {
216 return this->getStateMachine()->createSignalConnection(onNavigationFeedback_, callback, object);
217 }
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 253 of file cp_nav2_action_interface.hpp.

254 {
255 RCLCPP_DEBUG(getLogger(), "[CpNav2ActionInterface] Navigation feedback received");
256 onNavigationFeedback_(feedback);
258 {
260 }
261 }

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

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

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

Referenced by cl_nav2z::CbAbortNavigation::onEntry(), 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 223 of file cp_nav2_action_interface.hpp.

224 {
225 RCLCPP_INFO(getLogger(), "[CpNav2ActionInterface] Navigation succeeded");
228 {
230 }
231 }

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::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: