nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Friends | List of all members
rclcpp_action::Client< A > Class Template Reference

#include <client.hpp>

Classes

struct  GoalAccept
 
struct  SendGoalOptions
 

Public Types

using FeedbackType = typename A::Feedback
 
using GoalType = typename A::Goal
 
using ResultType = typename A::Result
 

Public Member Functions

bool action_server_is_ready () const
 
::rclcpp::Result cancel_goal (const ::rclcpp_action::GoalUUID &goal_id)
 cancel_goal taking a GoalUUID value (phase-417 W4.b).
 
::rclcpp::Result cancel_goal (const uint8_t goal_id[16])
 
 Client ()
 
 Client (Client &&other)
 
::rclcpp::Stream< FeedbackType > & feedback_stream ()
 
const ::rclcpp::Stream< FeedbackType > & feedback_stream () const
 
const char * get_action_name () const
 
::rclcpp::Result get_result (const ::rclcpp_action::GoalUUID &goal_id, ResultType &result)
 get_result taking a GoalUUID value (phase-417 W4.b).
 
::rclcpp::Result get_result (const uint8_t goal_id[16], ResultType &result)
 
::rclcpp::Result get_result_async (const ::rclcpp_action::GoalUUID &goal_id)
 get_result_async taking a GoalUUID value (phase-417 W4.b).
 
::rclcpp::Result get_result_async (const uint8_t goal_id[16])
 
::rclcpp::Future< ResultType > get_result_future (const ::rclcpp_action::GoalUUID &goal_id)
 get_result_future taking a GoalUUID value (phase-417 W4.b).
 
::rclcpp::Future< ResultType > get_result_future (const uint8_t goal_id[16])
 
template<size_t Cap>
::rclcpp::Future< ResultType, Cap > get_result_future_sized (const uint8_t goal_id[16])
 
template<size_t Cap>
::rclcpp::Result get_result_sized (const uint8_t goal_id[16], ResultType &result)
 
bool is_valid () const
 Check if the action client is initialized and valid.
 
Client & operator= (Client &&other)
 
void poll ()
 
::rclcpp::Result send_goal (const GoalType &goal, ::rclcpp_action::GoalUUID &goal_id)
 
::rclcpp::Result send_goal (const GoalType &goal, uint8_t goal_id[16])
 
::rclcpp::Result send_goal_async (const GoalType &goal, ::rclcpp_action::GoalUUID &goal_id)
 
::rclcpp::Result send_goal_async (const GoalType &goal, uint8_t goal_id[16])
 
::rclcpp::Future< GoalAccept > send_goal_future (const GoalType &goal)
 
::rclcpp::Result set_callbacks (const SendGoalOptions &options)
 
::rclcpp::Result try_recv_cancel_response (::rclcpp_action::CancelReturnCode &out)
 
::rclcpp::Result try_recv_feedback (FeedbackType &feedback)
 
template<size_t Cap>
::rclcpp::Result try_recv_feedback_sized (FeedbackType &feedback)
 
template<typename T = void>
::rclcpp::Result wait_for_action_server ()
 REFUSED — wait_for_action_server() with no budget.
 
::rclcpp::Result wait_for_action_server (uint32_t timeout_ms)
 
 ~Client ()
 

Friends

class ::rclcpp::Node
 

Detailed Description

template<typename A>
class rclcpp_action::Client< A >

Typed action client for a ROS 2 action.

Mirrors upstream's rclcpp_action::Client<A>. The action type A must provide nested Goal, Result, and Feedback types with TYPE_NAME, TYPE_HASH, SERIALIZED_SIZE_MAX, ffi_serialize(), and ffi_deserialize().

Usage:

RCLCPP_TRY(node.create_action_client(client, "/fibonacci"));
typename decltype(client)::GoalType goal;
goal.order = 10;
uint8_t goal_id[16];
typename decltype(client)::ResultType result;
RCLCPP_TRY(client.get_result(goal_id, result));
Definition client.hpp:95
::rclcpp::Result send_goal(const GoalType &goal, uint8_t goal_id[16])
Definition client.hpp:202
typename A::Result ResultType
Definition client.hpp:98
Client()
Definition client.hpp:592
::rclcpp::Result get_result(const uint8_t goal_id[16], ResultType &result)
Definition client.hpp:228
typename A::Goal GoalType
Definition client.hpp:97
#define RCLCPP_TRY(expr)
Definition result.hpp:258

Member Typedef Documentation

◆ FeedbackType

template<typename A >
using rclcpp_action::Client< A >::FeedbackType = typename A::Feedback

◆ GoalType

template<typename A >
using rclcpp_action::Client< A >::GoalType = typename A::Goal

◆ ResultType

template<typename A >
using rclcpp_action::Client< A >::ResultType = typename A::Result

Constructor & Destructor Documentation

◆ ~Client()

template<typename A >
rclcpp_action::Client< A >::~Client ( )
inline

Destructor — RELEASES the arena entry (issue 1496).

The ActionClientCore with its three service clients and its feedback subscription lives in an ActionClientRawArenaEntry in the executor arena, whose callback context is storage_. nros_cpp_action_client_destroy (which needs no extra argument: CppActionClient keeps its own executor pointer and entry index) drops that entry in place — the entities are destroyed, so no late reply can read this storage — frees its callback slot and returns its arena bytes for reuse, so a create/destroy loop does not exhaust the executor.

◆ Client() [1/2]

template<typename A >
rclcpp_action::Client< A >::Client ( Client< A > &&  other)
inline

◆ Client() [2/2]

template<typename A >
rclcpp_action::Client< A >::Client ( )
inline

Default constructor — creates an uninitialized action client. Use Node::create_action_client() to initialize.

Member Function Documentation

◆ action_server_is_ready()

template<typename A >
bool rclcpp_action::Client< A >::action_server_is_ready ( ) const
inline

Is an action server for this action visible right now? — phase-417 W4.b.

rclcpp_action::ClientBase::action_server_is_ready, the NON-BLOCKING half of wait_for_action_server. C has had rclc_action_client_action_server_is_ready and Rust ActionClient::action_server_is_ready since phase-338; C++ had neither, so the only way to ask here was to block (ledger row cpp:Client::action_server_is_ready, a C++-only gap rather than a decision).

Spins nothing, so unlike wait_for_action_server it is legal inside a callback. Its answer is a SNAPSHOT: false means "not visible yet", never "will not appear".

◆ cancel_goal() [1/2]

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::cancel_goal ( const ::rclcpp_action::GoalUUID &  goal_id)
inline

cancel_goal taking a GoalUUID value (phase-417 W4.b).

◆ cancel_goal() [2/2]

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::cancel_goal ( const uint8_t  goal_id[16])
inline

Cancel a goal (non-blocking) — issue 0796.

Sends the action_msgs/srv/CancelGoal request and returns; read the RPC outcome with try_recv_cancel_response() once the executor has spun. Mirrors C's rclc_action_cancel_goal and Rust's ActionClient::cancel_goal — rclcpp_action's async_cancel_goal returns a future, which RFC-0021 has no runtime to await.

Until this existed, a C++ application written against the CALLBACK tier could start a goal and had no way to stop it: cancel was only on the L1 PollingActionClient::send_cancel_request.

Parameters
goal_id16-byte goal UUID from send_goal() / send_goal_async().
Returns
Result indicating the request was sent.

◆ feedback_stream() [1/2]

template<typename A >
::rclcpp::Stream< FeedbackType > & rclcpp_action::Client< A >::feedback_stream ( )
inline

Get a reference to the action client's feedback stream.

The stream yields FeedbackType values across all currently-active goals for this client — feedback is not goal-scoped at this layer. Callers that need per-goal separation should use the callback API (set_callbacks(SendGoalOptions{ .feedback = … })), which delivers (goal_id, bytes, len, ctx) via an executor-driven trampoline.

Usage (blocking):

RCLCPP_TRY(client.feedback_stream().wait_next(executor.handle(), 500, fb));
Result wait_next(void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
Definition stream.hpp:97
::rclcpp::Stream< FeedbackType > & feedback_stream()
Definition client.hpp:391
typename A::Feedback FeedbackType
Definition client.hpp:99

Usage (non-blocking):

if (r.ok()) { ... }
Result try_next(T &out)
Definition stream.hpp:72

◆ feedback_stream() [2/2]

template<typename A >
const ::rclcpp::Stream< FeedbackType > & rclcpp_action::Client< A >::feedback_stream ( ) const
inline

◆ get_action_name()

template<typename A >
const char * rclcpp_action::Client< A >::get_action_name ( ) const
inline

Read back the action name this client was created on — phase-417 W4.b.

The client half of "four surfaces, one accessor" (ledger row c:action_client_get_action_name); see rclcpp_action::Server<A>::get_action_name for why the 256-byte copy is where it is. Returns "" (never NULL) on an uninitialised client.

◆ get_result() [1/2]

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::get_result ( const ::rclcpp_action::GoalUUID &  goal_id,
ResultType &  result 
)
inline

get_result taking a GoalUUID value (phase-417 W4.b).

◆ get_result() [2/2]

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::get_result ( const uint8_t  goal_id[16],
ResultType &  result 
)
inline

Get the result for a goal (blocking with timeout).

Sends a get_result request and spins the executor until a reply arrives or timeout (Phase 82 compliant – drives the executor).

Parameters
goal_id16-byte goal UUID from send_goal().
resultOutput result struct (filled on success).
Returns
Result indicating success, timeout, or failure.

◆ get_result_async() [1/2]

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::get_result_async ( const ::rclcpp_action::GoalUUID &  goal_id)
inline

get_result_async taking a GoalUUID value (phase-417 W4.b).

◆ get_result_async() [2/2]

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::get_result_async ( const uint8_t  goal_id[16])
inline

Request the result for a goal asynchronously (non-blocking).

Returns immediately after sending the get_result request. The result arrives via the result callback during poll().

Parameters
goal_id16-byte goal UUID from send_goal_async().
Returns
Result indicating success or failure.

◆ get_result_future() [1/2]

template<typename A >
::rclcpp::Future< ResultType > rclcpp_action::Client< A >::get_result_future ( const ::rclcpp_action::GoalUUID &  goal_id)
inline

get_result_future taking a GoalUUID value (phase-417 W4.b).

◆ get_result_future() [2/2]

template<typename A >
::rclcpp::Future< ResultType > rclcpp_action::Client< A >::get_result_future ( const uint8_t  goal_id[16])
inline

Request a goal result and return a Future for the result.

Sends the get_result request asynchronously and returns a Future that resolves when the result arrives. Poll the future (or call wait()) to retrieve the deserialized result.

Usage:

auto fut = client.get_result_future(goal_id);
ResultType result;
RCLCPP_TRY(fut.wait(executor.handle(), 10000, result));
::rclcpp::Future< ResultType > get_result_future(const uint8_t goal_id[16])
Definition client.hpp:313
Parameters
goal_id16-byte goal UUID from send_goal() or GoalAccept.
Returns
Future that resolves to ResultType. Returns a consumed (empty) future on send failure.

◆ get_result_future_sized()

template<typename A >
template<size_t Cap>
::rclcpp::Future< ResultType, Cap > rclcpp_action::Client< A >::get_result_future_sized ( const uint8_t  goal_id[16])
inline

get_result_future with the RESULT buffer sized by the caller.

A Future<T> holds its receive buffer as a member, so the capacity is a class template argument: this returns Future<ResultType, Cap> (issue 0964).

◆ get_result_sized()

template<typename A >
template<size_t Cap>
::rclcpp::Result rclcpp_action::Client< A >::get_result_sized ( const uint8_t  goal_id[16],
ResultType &  result 
)
inline

get_result with the receive buffer sized by the CALLER. See Subscription::try_recv_sized (issue 0964).

◆ is_valid()

template<typename A >
bool rclcpp_action::Client< A >::is_valid ( ) const
inline

Check if the action client is initialized and valid.

◆ operator=()

template<typename A >
Client & rclcpp_action::Client< A >::operator= ( Client< A > &&  other)
inline

◆ poll()

template<typename A >
void rclcpp_action::Client< A >::poll ( )
inline

Poll for pending async replies (non-blocking).

Checks for goal acceptance, feedback, and result replies. Invokes the corresponding callbacks registered via set_callbacks(). Call this in the spin loop after spin_once().

◆ send_goal() [1/2]

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::send_goal ( const GoalType &  goal,
::rclcpp_action::GoalUUID &  goal_id 
)
inline

send_goal writing the generated id into a GoalUUID value (phase-417 W4.b) — the shape you can put in a map.

◆ send_goal() [2/2]

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::send_goal ( const GoalType &  goal,
uint8_t  goal_id[16] 
)
inline

Send a goal and receive the generated goal UUID (blocking).

Internally spins the executor until the server accepts or rejects the goal (Phase 82 compliant – drives the executor).

Upstream's async_send_goal returns a std::shared_future of a goal handle. This one blocks and reports through Result plus an out-param goal id: no future and no goal handle (RFC-0021: no async runtime, no allocator). The future-shaped spelling is send_goal_future, over rclcpp::Future.

Parameters
goalGoal to send.
goal_idOutput 16-byte goal UUID (filled on success).
Returns
Result indicating success or failure.

◆ send_goal_async() [1/2]

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::send_goal_async ( const GoalType &  goal,
::rclcpp_action::GoalUUID &  goal_id 
)
inline

send_goal_async writing the generated id into a GoalUUID value (phase-417 W4.b).

◆ send_goal_async() [2/2]

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::send_goal_async ( const GoalType &  goal,
uint8_t  goal_id[16] 
)
inline

Send a goal asynchronously (non-blocking).

Returns immediately after sending the goal request. The goal UUID is filled on success. Responses arrive via callbacks registered with the executor (see SendGoalOptions and Node::create_action_client).

Parameters
goalGoal to send.
goal_idOutput 16-byte goal UUID (filled on success).
Returns
Result indicating success or failure.

◆ send_goal_future()

template<typename A >
::rclcpp::Future< GoalAccept > rclcpp_action::Client< A >::send_goal_future ( const GoalType &  goal)
inline

Send a goal and return a Future for the acceptance response.

Returns immediately after sending the goal request. Poll the returned future (or call wait()) to get the GoalAccept result.

Usage:

RCLCPP_TRY(fut.wait(executor.handle(), 5000, accept));
if (accept.accepted) { /* use accept.goal_id *&zwj;/ }
::rclcpp::Future< GoalAccept > send_goal_future(const GoalType &goal)
Definition client.hpp:277
Definition client.hpp:105
Parameters
goalGoal to send.
Returns
Future that resolves to GoalAccept. Returns a consumed (empty) future on serialization or send failure.

◆ set_callbacks()

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::set_callbacks ( const SendGoalOptions &  options)
inline

Register async callbacks for goal response, feedback, and result.

Binds the callbacks to the CLIENT, not to one goal: rclcpp passes a SendGoalOptions to each async_send_goal, while here they are installed once and serve every goal this client sends (RFC-0041: callbacks bind to the entity). The pointers are read when a reply is DISPATCHED, so install them before the spin that delivers the reply — before or after send_goal_async both work.

Parameters
optionsCallback pointers and context.
Returns
Result::success() on success, ErrorCode::NotInitialized if the client is not initialized, or the FFI error code.

◆ try_recv_cancel_response()

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::try_recv_cancel_response ( ::rclcpp_action::CancelReturnCode &  out)
inline

Try to read the reply to a cancel_goal() (non-blocking).

Parameters
outReceives the RPC return code on success.
Returns
Result::success() when a reply was consumed; ErrorCode::TryAgain when none has arrived yet.

◆ try_recv_feedback()

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::try_recv_feedback ( FeedbackType &  feedback)
inline

Try to receive feedback (non-blocking).

Parameters
feedbackOutput feedback struct (filled on success).
Returns
Result::success() if feedback was received and deserialized; ErrorCode::TryAgain if no feedback is available right now; ErrorCode::NotInitialized if the client is not initialized; ErrorCode::Error if deserialization failed; otherwise the FFI error code.

◆ try_recv_feedback_sized()

template<typename A >
template<size_t Cap>
::rclcpp::Result rclcpp_action::Client< A >::try_recv_feedback_sized ( FeedbackType &  feedback)
inline

try_recv_feedback with the receive buffer sized by the CALLER. See Subscription::try_recv_sized (issue 0964).

◆ wait_for_action_server() [1/2]

template<typename A >
template<typename T = void>
::rclcpp::Result rclcpp_action::Client< A >::wait_for_action_server ( )
inline

REFUSED — wait_for_action_server() with no budget.

◆ wait_for_action_server() [2/2]

template<typename A >
::rclcpp::Result rclcpp_action::Client< A >::wait_for_action_server ( uint32_t  timeout_ms)
inline

phase-338 W8 — block until the action server is discoverable.

Mirrors rclcpp_action::Client::wait_for_action_server. Probes the send_goal queryable, which is the load-bearing entity for the first send_goal(). Prefer this over retrying send_goal() on timeout: it waits for the real condition and re-probes, so a server that comes up after the wait starts is still seen.

Spins the executor while probing — not for use inside a callback. Returns Unsupported at once when the backend cannot know whether a server is up (XRCE — issue 1686); a caller that may send blind proceeds.

The budget is REQUIRED — phase-417 stage 3, the same defect and the same fix as Client::wait_for_service; they were found together and are corrected together, under one message. Upstream's rclcpp_action::Client::wait_for_action_server(timeout = -1) waits forever; this used to substitute 5000 ms for an argument-free call, silently. RFC-0021 is why the unbounded form does not exist here, and NROS_RCLCPP_REFUSE_UNBOUNDED_WAIT is what a ported caller now reads.

Takes uint32_t MILLISECONDS, not a std::chrono::duration, and returns Result (timeout vs. not-initialised by code), not bool.

Friends And Related Symbol Documentation

◆ ::rclcpp::Node

template<typename A >
friend class ::rclcpp::Node
friend

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