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)
 
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])
 
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_feedback (FeedbackType &feedback)
 
 ~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));
typename A::Result ResultType
Definition action_client.hpp:70
typename A::Goal GoalType
Definition action_client.hpp:69
Definition future.hpp:40
#define NROS_TRY(expr)
Definition result.hpp:90

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

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

Usage (non-blocking):

Result r = client.feedback_stream().try_next(fb);
if (r.ok()) { ... }
Definition result.hpp:52

◆ 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));
Result wait(void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
Definition future.hpp:84
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.

◆ 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 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.

◆ 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:77
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_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.

Friends And Related Symbol Documentation

◆ Node

template<typename A >
friend class Node
friend

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