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
nros::ActionClient< A > Class Template Reference

#include <action_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

 ActionClient ()
 
 ActionClient (ActionClient &&other)
 
Result cancel_goal (const uint8_t goal_id[16])
 
Stream< FeedbackType > & feedback_stream ()
 
const Stream< FeedbackType > & feedback_stream () const
 
Result get_result (const uint8_t goal_id[16], ResultType &result)
 
Result get_result_async (const uint8_t goal_id[16])
 
Future< ResultTypeget_result_future (const uint8_t goal_id[16])
 
template<size_t Cap>
Future< ResultType, Capget_result_future_sized (const uint8_t goal_id[16])
 
template<size_t Cap>
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.
 
ActionClientoperator= (ActionClient &&other)
 
void poll ()
 
Result send_goal (const GoalType &goal, uint8_t goal_id[16])
 
Result send_goal_async (const GoalType &goal, uint8_t goal_id[16])
 
Future< GoalAcceptsend_goal_future (const GoalType &goal)
 
Result set_callbacks (const SendGoalOptions &options)
 
Result try_recv_cancel_response (CancelReturnCode &out)
 
Result try_recv_feedback (FeedbackType &feedback)
 
template<size_t Cap>
Result try_recv_feedback_sized (FeedbackType &feedback)
 
Result wait_for_action_server (uint32_t timeout_ms=5000)
 
 ~ActionClient ()
 Destructor — releases action client resources.
 

Friends

class Node
 

Detailed Description

template<typename A>
class nros::ActionClient< A >

Typed action client for a ROS 2 action.

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

NROS_TRY(node.create_action_client(client, "/fibonacci"));
typename decltype(client)::GoalType goal;
goal.order = 10;
uint8_t goal_id[16];
NROS_TRY(client.send_goal(goal, goal_id));
typename decltype(client)::ResultType result;
NROS_TRY(client.get_result(goal_id, result));
Definition action_client.hpp:73
typename A::Result ResultType
Definition action_client.hpp:76
typename A::Goal GoalType
Definition action_client.hpp:75
Result get_result_sized(const uint8_t goal_id[16], ResultType &result)
Definition action_client.hpp:151
#define NROS_TRY(expr)
Definition result.hpp:128

Member Typedef Documentation

◆ FeedbackType

template<typename A >
using nros::ActionClient< A >::FeedbackType = typename A::Feedback

◆ GoalType

template<typename A >
using nros::ActionClient< A >::GoalType = typename A::Goal

◆ ResultType

template<typename A >
using nros::ActionClient< A >::ResultType = typename A::Result

Constructor & Destructor Documentation

◆ ~ActionClient()

template<typename A >
nros::ActionClient< A >::~ActionClient ( )
inline

Destructor — releases action client resources.

◆ ActionClient() [1/2]

template<typename A >
nros::ActionClient< A >::ActionClient ( ActionClient< A > &&  other)
inline

◆ ActionClient() [2/2]

template<typename A >
nros::ActionClient< A >::ActionClient ( )
inline

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

Member Function Documentation

◆ cancel_goal()

template<typename A >
Result nros::ActionClient< 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 nros_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 >
Stream< FeedbackType > & nros::ActionClient< 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):

NROS_TRY(client.feedback_stream().wait_next(executor.handle(), 500, fb));
typename A::Feedback FeedbackType
Definition action_client.hpp:77

Usage (non-blocking):

Result r = client.feedback_stream().try_next(fb);
if (r.ok()) { ... }
Definition result.hpp:90
bool ok() const
Returns true if the operation succeeded.
Definition result.hpp:100

◆ feedback_stream() [2/2]

template<typename A >
const Stream< FeedbackType > & nros::ActionClient< A >::feedback_stream ( ) const
inline

◆ get_result()

template<typename A >
Result nros::ActionClient< 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()

template<typename A >
Result nros::ActionClient< 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()

template<typename A >
Future< ResultType > nros::ActionClient< 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;
NROS_TRY(fut.wait(executor.handle(), 10000, result));
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>
Future< ResultType, Cap > nros::ActionClient< 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>
Result nros::ActionClient< 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 nros::ActionClient< A >::is_valid ( ) const
inline

Check if the action client is initialized and valid.

◆ operator=()

template<typename A >
ActionClient & nros::ActionClient< A >::operator= ( ActionClient< A > &&  other)
inline

◆ poll()

template<typename A >
void nros::ActionClient< 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()

template<typename A >
Result nros::ActionClient< A >::send_goal ( const GoalType goal,
uint8_t  goal_id[16] 
)
inline

◆ send_goal_async()

template<typename A >
Result nros::ActionClient< 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 >
Future< GoalAccept > nros::ActionClient< 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:

auto fut = client.send_goal_future(goal);
NROS_TRY(fut.wait(executor.handle(), 5000, accept));
if (accept.accepted) { /* use accept.goal_id *&zwj;/ }
Definition action_client.hpp:83
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 >
Result nros::ActionClient< A >::set_callbacks ( const SendGoalOptions options)
inline

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

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 >
Result nros::ActionClient< A >::try_recv_cancel_response ( 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 >
Result nros::ActionClient< 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>
Result nros::ActionClient< 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()

template<typename A >
Result nros::ActionClient< A >::wait_for_action_server ( uint32_t  timeout_ms = 5000)
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).

Parameters
goalGoal to send.
goal_idOutput 16-byte goal UUID (filled on success).
Returns
Result indicating success or failure. 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.

Friends And Related Symbol Documentation

◆ Node

template<typename A >
friend class Node
friend

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