SMACC2
Loading...
Searching...
No Matches
smacc2::client_core_components::CpActionClient< ActionType > Class Template Reference

#include <cp_action_client.hpp>

Inheritance diagram for smacc2::client_core_components::CpActionClient< ActionType >:
Inheritance graph
Collaboration diagram for smacc2::client_core_components::CpActionClient< ActionType >:
Collaboration graph

Public Types

using ActionClient = rclcpp_action::Client<ActionType>
 
using Goal = typename ActionType::Goal
 
using Feedback = typename ActionType::Feedback
 
using Result = typename ActionType::Result
 
using GoalHandle = rclcpp_action::ClientGoalHandle<ActionType>
 
using WrappedResult = typename GoalHandle::WrappedResult
 
using SendGoalOptions = typename ActionClient::SendGoalOptions
 
using GoalResponseCallback
 
using FeedbackCallback = typename GoalHandle::FeedbackCallback
 
using ResultCallback = typename GoalHandle::ResultCallback
 

Public Member Functions

 CpActionClient ()=default
 
 CpActionClient (const std::string &actionServerName)
 
 ~CpActionClient () override=default
 
std::shared_future< typename GoalHandle::SharedPtr > sendGoal (Goal &goal, typename smacc2::SmaccSignal< void(const WrappedResult &)>::WeakPtr resultCallback=typename smacc2::SmaccSignal< void(const WrappedResult &)>::WeakPtr())
 
bool cancelGoal ()
 
bool isServerReady () const
 
void waitForServer ()
 
void onInitialize () override
 
template<typename TOrthogonal , typename TSourceObject >
void onComponentInitialization ()
 
template<typename T >
smacc2::SmaccSignalConnection onSucceeded (void(T::*callback)(const WrappedResult &), T *object)
 
template<typename T >
smacc2::SmaccSignalConnection onAborted (void(T::*callback)(const WrappedResult &), T *object)
 
template<typename T >
smacc2::SmaccSignalConnection onCancelled (void(T::*callback)(const WrappedResult &), T *object)
 
template<typename T >
smacc2::SmaccSignalConnection onFeedback (void(T::*callback)(const Feedback &), T *object)
 
std::shared_ptr< ActionClient > getActionClient () const
 
- 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

std::optional< std::string > actionServerName
 
std::optional< std::chrono::milliseconds > serverTimeout
 
smacc2::SmaccSignal< void(const WrappedResult &)> onActionSucceeded_
 
smacc2::SmaccSignal< void(const WrappedResult &)> onActionAborted_
 
smacc2::SmaccSignal< void(const WrappedResult &)> onActionCancelled_
 
smacc2::SmaccSignal< void(const Feedback &)> onActionFeedback_
 
smacc2::SmaccSignal< void()> onGoalAccepted_
 
smacc2::SmaccSignal< void()> onGoalRejected_
 
std::function< void(const WrappedResult &)> postSuccessEvent
 
std::function< void(const WrappedResult &)> postAbortedEvent
 
std::function< void(const WrappedResult &)> postCancelledEvent
 
std::function< void(const Feedback &)> postFeedbackEvent
 

Private Member Functions

void onFeedback (typename GoalHandle::SharedPtr, const std::shared_ptr< const Feedback > feedback_msg)
 
void onResult (const WrappedResult &result_msg)
 
template<typename EvType >
void postResultEvent (const WrappedResult &result)
 

Private Attributes

std::shared_ptr< ActionClient > client_ = nullptr
 
std::optional< std::shared_future< typename GoalHandle::SharedPtr > > lastRequest_
 
std::optional< std::shared_future< typename rclcpp_action::Client< ActionType >::CancelResponse::SharedPtr > > lastCancelResponse_
 
FeedbackCallback feedbackCallback_
 
std::mutex actionMutex_
 

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

template<typename ActionType>
class smacc2::client_core_components::CpActionClient< ActionType >

Definition at line 36 of file cp_action_client.hpp.

Member Typedef Documentation

◆ ActionClient

template<typename ActionType >
using smacc2::client_core_components::CpActionClient< ActionType >::ActionClient = rclcpp_action::Client<ActionType>

Definition at line 40 of file cp_action_client.hpp.

◆ Feedback

template<typename ActionType >
using smacc2::client_core_components::CpActionClient< ActionType >::Feedback = typename ActionType::Feedback

Definition at line 42 of file cp_action_client.hpp.

◆ FeedbackCallback

template<typename ActionType >
using smacc2::client_core_components::CpActionClient< ActionType >::FeedbackCallback = typename GoalHandle::FeedbackCallback

Definition at line 49 of file cp_action_client.hpp.

◆ Goal

template<typename ActionType >
using smacc2::client_core_components::CpActionClient< ActionType >::Goal = typename ActionType::Goal

Definition at line 41 of file cp_action_client.hpp.

◆ GoalHandle

template<typename ActionType >
using smacc2::client_core_components::CpActionClient< ActionType >::GoalHandle = rclcpp_action::ClientGoalHandle<ActionType>

Definition at line 44 of file cp_action_client.hpp.

◆ GoalResponseCallback

template<typename ActionType >
using smacc2::client_core_components::CpActionClient< ActionType >::GoalResponseCallback
Initial value:
std::function<void(std::shared_future<typename GoalHandle::SharedPtr>)>

Definition at line 47 of file cp_action_client.hpp.

◆ Result

template<typename ActionType >
using smacc2::client_core_components::CpActionClient< ActionType >::Result = typename ActionType::Result

Definition at line 43 of file cp_action_client.hpp.

◆ ResultCallback

template<typename ActionType >
using smacc2::client_core_components::CpActionClient< ActionType >::ResultCallback = typename GoalHandle::ResultCallback

Definition at line 50 of file cp_action_client.hpp.

◆ SendGoalOptions

template<typename ActionType >
using smacc2::client_core_components::CpActionClient< ActionType >::SendGoalOptions = typename ActionClient::SendGoalOptions

Definition at line 46 of file cp_action_client.hpp.

◆ WrappedResult

template<typename ActionType >
using smacc2::client_core_components::CpActionClient< ActionType >::WrappedResult = typename GoalHandle::WrappedResult

Definition at line 45 of file cp_action_client.hpp.

Constructor & Destructor Documentation

◆ CpActionClient() [1/2]

template<typename ActionType >
smacc2::client_core_components::CpActionClient< ActionType >::CpActionClient ( )
default

◆ CpActionClient() [2/2]

template<typename ActionType >
smacc2::client_core_components::CpActionClient< ActionType >::CpActionClient ( const std::string & actionServerName)
inline

Definition at line 73 of file cp_action_client.hpp.

◆ ~CpActionClient()

template<typename ActionType >
smacc2::client_core_components::CpActionClient< ActionType >::~CpActionClient ( )
overridedefault

Member Function Documentation

◆ cancelGoal()

template<typename ActionType >
bool smacc2::client_core_components::CpActionClient< ActionType >::cancelGoal ( )
inline

Definition at line 158 of file cp_action_client.hpp.

159 {
160 // Same rule as sendGoal: the cancel call runs outside actionMutex_. A goal whose sendGoal is
161 // between its two lock scopes is not seen here; no caller cancels while another thread sends.
162 std::shared_ptr<ActionClient> client;
163 std::shared_future<typename GoalHandle::SharedPtr> request;
164 {
165 std::lock_guard<std::mutex> lock(actionMutex_);
166 if (client_ != nullptr && lastRequest_ && lastRequest_->valid())
167 {
168 client = client_;
169 request = *lastRequest_;
170 }
171 }
172
173 if (client == nullptr)
174 {
175 RCLCPP_WARN_STREAM(getLogger(), "[" << this->getName() << "] No active goal to cancel");
176 return false;
177 }
178
179 RCLCPP_INFO_STREAM(getLogger(), "[" << this->getName() << "] Cancelling current goal");
180
181 // Only the last goal is cancelled, never every goal of the server: the next state may already
182 // have sent its own through this component when the server processes the request.
183 std::shared_future<typename ActionClient::CancelResponse::SharedPtr> cancelFuture;
184 typename GoalHandle::SharedPtr goalHandle;
185 if (request.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
186 {
187 goalHandle = request.get();
188 }
189 try
190 {
191 // A goal whose response has not arrived yet has no handle; it is cancelled by its send time.
192 cancelFuture = goalHandle != nullptr ? client->async_cancel_goal(goalHandle)
193 : client->async_cancel_goals_before(getNode()->now());
194 }
195 catch (const rclcpp_action::exceptions::UnknownGoalHandleError &)
196 {
197 RCLCPP_INFO_STREAM(getLogger(), "[" << this->getName() << "] The goal has already finished");
198 return false;
199 }
200 {
201 std::lock_guard<std::mutex> lock(actionMutex_);
202 lastCancelResponse_ = cancelFuture;
203 }
204 return true;
205 }
virtual std::string getName() const
rclcpp::Logger getLogger() const
rclcpp::Node::SharedPtr getNode()
std::optional< std::shared_future< typename GoalHandle::SharedPtr > > lastRequest_
std::optional< std::shared_future< typename rclcpp_action::Client< ActionType >::CancelResponse::SharedPtr > > lastCancelResponse_

References smacc2::client_core_components::CpActionClient< ActionType >::actionMutex_, smacc2::client_core_components::CpActionClient< ActionType >::client_, smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getName(), smacc2::ISmaccComponent::getNode(), smacc2::client_core_components::CpActionClient< ActionType >::lastCancelResponse_, and smacc2::client_core_components::CpActionClient< ActionType >::lastRequest_.

Referenced by smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::cancelGoal().

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

◆ getActionClient()

template<typename ActionType >
std::shared_ptr< ActionClient > smacc2::client_core_components::CpActionClient< ActionType >::getActionClient ( ) const
inline

Definition at line 296 of file cp_action_client.hpp.

296{ return client_; }

References smacc2::client_core_components::CpActionClient< ActionType >::client_.

Referenced by smacc2::client_behaviors::CbWaitActionServer2< ActionT >::onEntry().

Here is the caller graph for this function:

◆ isServerReady()

template<typename ActionType >
bool smacc2::client_core_components::CpActionClient< ActionType >::isServerReady ( ) const
inline

Definition at line 207 of file cp_action_client.hpp.

207{ return client_ && client_->action_server_is_ready(); }

References smacc2::client_core_components::CpActionClient< ActionType >::client_.

Referenced by smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::sendGoal().

Here is the caller graph for this function:

◆ onAborted()

template<typename ActionType >
template<typename T >
smacc2::SmaccSignalConnection smacc2::client_core_components::CpActionClient< ActionType >::onAborted ( void(T::* callback )(const WrappedResult &),
T * object )
inline

Definition at line 278 of file cp_action_client.hpp.

279 {
280 return this->getStateMachine()->createSignalConnection(onActionAborted_, callback, object);
281 }
ISmaccStateMachine * getStateMachine()
smacc2::SmaccSignalConnection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
smacc2::SmaccSignal< void(const WrappedResult &)> onActionAborted_

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

Referenced by smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::onStateOrthogonalAllocation().

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

◆ onCancelled()

template<typename ActionType >
template<typename T >
smacc2::SmaccSignalConnection smacc2::client_core_components::CpActionClient< ActionType >::onCancelled ( void(T::* callback )(const WrappedResult &),
T * object )
inline

Definition at line 284 of file cp_action_client.hpp.

285 {
286 return this->getStateMachine()->createSignalConnection(onActionCancelled_, callback, object);
287 }
smacc2::SmaccSignal< void(const WrappedResult &)> onActionCancelled_

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

Referenced by smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::onStateOrthogonalAllocation().

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

◆ onComponentInitialization()

template<typename ActionType >
template<typename TOrthogonal , typename TSourceObject >
void smacc2::client_core_components::CpActionClient< ActionType >::onComponentInitialization ( )
inline

Definition at line 244 of file cp_action_client.hpp.

245 {
246 // Event source type is THIS COMPONENT, not the owning client: the event
247 // payload type is TSource::WrappedResult, and typing it on the client would
248 // wrongly assume the client's WrappedResult typedef matches this component's
249 // action - which breaks as soon as a client owns action clients of more than
250 // one action type. Nothing in-tree listens to client-typed events from this
251 // component (domain interfaces like CpNav2ActionInterface post those).
252 postSuccessEvent = [this](const WrappedResult & result)
253 { this->postResultEvent<EvActionSucceeded<CpActionClient<ActionType>, TOrthogonal>>(result); };
254
255 postAbortedEvent = [this](const WrappedResult & result)
256 { this->postResultEvent<EvActionAborted<CpActionClient<ActionType>, TOrthogonal>>(result); };
257
258 postCancelledEvent = [this](const WrappedResult & result)
259 { this->postResultEvent<EvActionCancelled<CpActionClient<ActionType>, TOrthogonal>>(result); };
260
261 postFeedbackEvent = [this](const Feedback & feedback)
262 {
264 actionFeedbackEvent->feedbackMessage = feedback;
265 this->postEvent(actionFeedbackEvent);
266 RCLCPP_DEBUG(getLogger(), "[%s] FEEDBACK EVENT", this->getName().c_str());
267 };
268 }
std::function< void(const WrappedResult &)> postCancelledEvent
std::function< void(const WrappedResult &)> postSuccessEvent
void postResultEvent(const WrappedResult &result)
std::function< void(const WrappedResult &)> postAbortedEvent
std::function< void(const Feedback &)> postFeedbackEvent
boost::intrusive_ptr< EventType > makeEvent(Args &&... args)

References smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getName(), smacc2::makeEvent(), smacc2::client_core_components::CpActionClient< ActionType >::postAbortedEvent, smacc2::client_core_components::CpActionClient< ActionType >::postCancelledEvent, smacc2::ISmaccComponent::postEvent(), smacc2::client_core_components::CpActionClient< ActionType >::postFeedbackEvent, smacc2::client_core_components::CpActionClient< ActionType >::postResultEvent(), and smacc2::client_core_components::CpActionClient< ActionType >::postSuccessEvent.

Here is the call graph for this function:

◆ onFeedback() [1/2]

template<typename ActionType >
void smacc2::client_core_components::CpActionClient< ActionType >::onFeedback ( typename GoalHandle::SharedPtr ,
const std::shared_ptr< const Feedback > feedback_msg )
inlineprivate

◆ onFeedback() [2/2]

template<typename ActionType >
template<typename T >
smacc2::SmaccSignalConnection smacc2::client_core_components::CpActionClient< ActionType >::onFeedback ( void(T::* callback )(const Feedback &),
T * object )
inline

◆ onInitialize()

template<typename ActionType >
void smacc2::client_core_components::CpActionClient< ActionType >::onInitialize ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccComponent.

Definition at line 221 of file cp_action_client.hpp.

222 {
223 if (!actionServerName)
224 {
225 RCLCPP_ERROR_STREAM(getLogger(), "[" << this->getName() << "] Action server name not set!");
226 return;
227 }
228
229 RCLCPP_INFO_STREAM(
230 getLogger(),
231 "[" << this->getName() << "] Initializing action client for: " << *actionServerName);
232
233 client_ = rclcpp_action::create_client<ActionType>(getNode(), *actionServerName);
234 RCLCPP_INFO_STREAM(
235 getLogger(),
236 "[" << this->getName() << "] DONE Initializing action client for: " << *actionServerName);
237
238 // Set up feedback callback
239 feedbackCallback_ = [this](auto goalHandle, auto feedback)
240 { this->onFeedback(goalHandle, feedback); };
241 }
smacc2::SmaccSignalConnection onFeedback(void(T::*callback)(const Feedback &), T *object)

References smacc2::client_core_components::CpActionClient< ActionType >::actionServerName, smacc2::client_core_components::CpActionClient< ActionType >::client_, smacc2::client_core_components::CpActionClient< ActionType >::feedbackCallback_, smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getName(), smacc2::ISmaccComponent::getNode(), and smacc2::client_core_components::CpActionClient< ActionType >::onFeedback().

Here is the call graph for this function:

◆ onResult()

template<typename ActionType >
void smacc2::client_core_components::CpActionClient< ActionType >::onResult ( const WrappedResult & result_msg)
inlineprivate

Definition at line 315 of file cp_action_client.hpp.

316 {
317 const auto & resultType = result_msg.code;
318
319 RCLCPP_INFO_STREAM(
320 getLogger(), "[" << this->getName() << "] Action result ["
321 << rclcpp_action::to_string(result_msg.goal_id) << "]: " << (int)resultType);
322
323 if (resultType == rclcpp_action::ResultCode::SUCCEEDED)
324 {
325 RCLCPP_INFO(getLogger(), "[%s] Action result: Success", this->getName().c_str());
326 onActionSucceeded_(result_msg);
327 postSuccessEvent(result_msg);
328 }
329 else if (resultType == rclcpp_action::ResultCode::ABORTED)
330 {
331 RCLCPP_INFO(getLogger(), "[%s] Action result: Aborted", this->getName().c_str());
332 onActionAborted_(result_msg);
333 postAbortedEvent(result_msg);
334 }
335 else if (resultType == rclcpp_action::ResultCode::CANCELED)
336 {
337 RCLCPP_INFO(getLogger(), "[%s] Action result: Cancelled", this->getName().c_str());
338 onActionCancelled_(result_msg);
339 postCancelledEvent(result_msg);
340 }
341 else
342 {
343 RCLCPP_WARN(
344 getLogger(), "[%s] Action result: Unhandled type: %d", this->getName().c_str(),
345 (int)resultType);
346 }
347 }
smacc2::SmaccSignal< void(const WrappedResult &)> onActionSucceeded_

References smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getName(), smacc2::client_core_components::CpActionClient< ActionType >::onActionAborted_, smacc2::client_core_components::CpActionClient< ActionType >::onActionCancelled_, smacc2::client_core_components::CpActionClient< ActionType >::onActionSucceeded_, smacc2::client_core_components::CpActionClient< ActionType >::postAbortedEvent, smacc2::client_core_components::CpActionClient< ActionType >::postCancelledEvent, and smacc2::client_core_components::CpActionClient< ActionType >::postSuccessEvent.

Referenced by smacc2::client_core_components::CpActionClient< ActionType >::sendGoal().

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

◆ onSucceeded()

template<typename ActionType >
template<typename T >
smacc2::SmaccSignalConnection smacc2::client_core_components::CpActionClient< ActionType >::onSucceeded ( void(T::* callback )(const WrappedResult &),
T * object )
inline

Definition at line 272 of file cp_action_client.hpp.

273 {
274 return this->getStateMachine()->createSignalConnection(onActionSucceeded_, callback, object);
275 }

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

Referenced by smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::onStateOrthogonalAllocation().

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

◆ postResultEvent()

template<typename ActionType >
template<typename EvType >
void smacc2::client_core_components::CpActionClient< ActionType >::postResultEvent ( const WrappedResult & result)
inlineprivate

Definition at line 350 of file cp_action_client.hpp.

351 {
352 auto ev = smacc2::makeEvent<EvType>();
353 ev->resultMessage = result;
354 RCLCPP_INFO(
355 getLogger(), "[%s] Posting event: %s", this->getName().c_str(),
356 smacc2::demangleSymbol(typeid(ev.get()).name()).c_str());
357 this->postEvent(ev);
358 }
std::string demangleSymbol()

References smacc2::introspection::demangleSymbol(), smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getName(), smacc2::makeEvent(), and smacc2::ISmaccComponent::postEvent().

Referenced by smacc2::client_core_components::CpActionClient< ActionType >::onComponentInitialization().

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

◆ sendGoal()

template<typename ActionType >
std::shared_future< typename GoalHandle::SharedPtr > smacc2::client_core_components::CpActionClient< ActionType >::sendGoal ( Goal & goal,
typename smacc2::SmaccSignal< void(const WrappedResult &)>::WeakPtr resultCallback = typename smacc2::SmaccSignal<void(const WrappedResult &)>::WeakPtr() )
inline

Definition at line 78 of file cp_action_client.hpp.

81 {
82 // actionMutex_ is never held across a rclcpp_action call: those take rclcpp_action's own
83 // mutexes, and holding ours across them was the first edge of the lock cycle (study, F-1).
84 std::shared_ptr<ActionClient> client;
85 FeedbackCallback feedbackCallback;
86 {
87 std::lock_guard<std::mutex> lock(actionMutex_);
88 client = client_;
89 feedbackCallback = feedbackCallback_;
90 }
91
92 if (client == nullptr)
93 {
94 RCLCPP_ERROR_STREAM(
95 getLogger(), "[" << this->getName()
96 << "] Cannot send goal: action client not initialized (was the "
97 "component created with an action server name?)");
98 return std::shared_future<typename GoalHandle::SharedPtr>();
99 }
100
101 SendGoalOptions options;
102
103 // Set up feedback callback
104 options.feedback_callback = feedbackCallback;
105
106 // Goal acceptance/rejection notification. Without this a rejected goal is
107 // silent: the result callback never fires and no signal is emitted.
108 options.goal_response_callback = [this](typename GoalHandle::SharedPtr goalHandle)
109 {
110 if (goalHandle != nullptr)
111 {
112 RCLCPP_INFO_STREAM(getLogger(), "[" << this->getName() << "] Goal accepted by server");
114 }
115 else
116 {
117 RCLCPP_ERROR_STREAM(getLogger(), "[" << this->getName() << "] Goal rejected by server");
119 }
120 };
121
122 // Set up result callback
123 // No actionMutex_ here: it guards nothing this lambda touches, and rclcpp_action runs it under
124 // the goal handle's mutex, which would close a lock cycle with sendGoal (study, F-1).
125 options.result_callback = [this, resultCallback](const WrappedResult & result)
126 {
127 RCLCPP_INFO_STREAM(
128 getLogger(), "[" << this->getName() << "] Action result callback, goal id: "
129 << rclcpp_action::to_string(result.goal_id));
130
131 auto resultCallbackPtr = resultCallback.lock();
132 if (resultCallbackPtr != nullptr)
133 {
134 RCLCPP_INFO_STREAM(getLogger(), "[" << this->getName() << "] Calling user result callback");
135 (*resultCallbackPtr)(result);
136 }
137 else
138 {
139 RCLCPP_INFO_STREAM(
140 getLogger(), "[" << this->getName() << "] Using default result handling");
141 this->onResult(result);
142 }
143 };
144
145 RCLCPP_INFO_STREAM(
146 getLogger(), "[" << this->getName() << "] Sending goal to action server: "
147 << static_cast<const void *>(client.get()));
148
149 auto goalFuture = client->async_send_goal(goal, options);
150 {
151 std::lock_guard<std::mutex> lock(actionMutex_);
152 lastRequest_ = goalFuture;
153 }
154
155 return goalFuture;
156 }
typename ActionClient::SendGoalOptions SendGoalOptions
void onResult(const WrappedResult &result_msg)

References smacc2::client_core_components::CpActionClient< ActionType >::actionMutex_, smacc2::client_core_components::CpActionClient< ActionType >::client_, smacc2::client_core_components::CpActionClient< ActionType >::feedbackCallback_, smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getName(), smacc2::client_core_components::CpActionClient< ActionType >::lastRequest_, smacc2::client_core_components::CpActionClient< ActionType >::onGoalAccepted_, smacc2::client_core_components::CpActionClient< ActionType >::onGoalRejected_, and smacc2::client_core_components::CpActionClient< ActionType >::onResult().

Referenced by smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::sendGoal().

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

◆ waitForServer()

template<typename ActionType >
void smacc2::client_core_components::CpActionClient< ActionType >::waitForServer ( )
inline

Definition at line 209 of file cp_action_client.hpp.

210 {
211 if (client_)
212 {
213 RCLCPP_INFO_STREAM(
214 getLogger(),
215 "[" << this->getName() << "] Waiting for action server: " << *actionServerName);
216 client_->wait_for_action_server();
217 }
218 }

References smacc2::client_core_components::CpActionClient< ActionType >::client_, smacc2::ISmaccComponent::getLogger(), and smacc2::ISmaccComponent::getName().

Here is the call graph for this function:

Member Data Documentation

◆ actionMutex_

◆ actionServerName

template<typename ActionType >
std::optional<std::string> smacc2::client_core_components::CpActionClient< ActionType >::actionServerName

◆ client_

◆ feedbackCallback_

◆ lastCancelResponse_

template<typename ActionType >
std::optional< std::shared_future<typename rclcpp_action::Client<ActionType>::CancelResponse::SharedPtr> > smacc2::client_core_components::CpActionClient< ActionType >::lastCancelResponse_
private

◆ lastRequest_

template<typename ActionType >
std::optional<std::shared_future<typename GoalHandle::SharedPtr> > smacc2::client_core_components::CpActionClient< ActionType >::lastRequest_
private

◆ onActionAborted_

template<typename ActionType >
smacc2::SmaccSignal<void(const WrappedResult &)> smacc2::client_core_components::CpActionClient< ActionType >::onActionAborted_

◆ onActionCancelled_

template<typename ActionType >
smacc2::SmaccSignal<void(const WrappedResult &)> smacc2::client_core_components::CpActionClient< ActionType >::onActionCancelled_

◆ onActionFeedback_

template<typename ActionType >
smacc2::SmaccSignal<void(const Feedback &)> smacc2::client_core_components::CpActionClient< ActionType >::onActionFeedback_

◆ onActionSucceeded_

template<typename ActionType >
smacc2::SmaccSignal<void(const WrappedResult &)> smacc2::client_core_components::CpActionClient< ActionType >::onActionSucceeded_

◆ onGoalAccepted_

template<typename ActionType >
smacc2::SmaccSignal<void()> smacc2::client_core_components::CpActionClient< ActionType >::onGoalAccepted_

◆ onGoalRejected_

template<typename ActionType >
smacc2::SmaccSignal<void()> smacc2::client_core_components::CpActionClient< ActionType >::onGoalRejected_

◆ postAbortedEvent

◆ postCancelledEvent

◆ postFeedbackEvent

◆ postSuccessEvent

◆ serverTimeout

template<typename ActionType >
std::optional<std::chrono::milliseconds> smacc2::client_core_components::CpActionClient< ActionType >::serverTimeout

Definition at line 54 of file cp_action_client.hpp.


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