ROS 2 rclcpp + rcl - humble
humble
ROS 2 C++ Client Library with ROS Client Library
|
Classes | |
struct | FutureAndRequestId |
A convenient Client::Future and request id pair. More... | |
struct | SharedFutureAndRequestId |
A convenient Client::SharedFuture and request id pair. More... | |
struct | SharedFutureWithRequestAndRequestId |
A convenient Client::SharedFutureWithRequest and request id pair. More... | |
Public Member Functions | |
Client (rclcpp::node_interfaces::NodeBaseInterface *node_base, rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph, const std::string &service_name, rcl_client_options_t &client_options) | |
Default constructor. More... | |
bool | take_response (typename ServiceT::Response &response_out, rmw_request_id_t &request_header_out) |
Take the next response for this client. More... | |
std::shared_ptr< void > | create_response () override |
Create a shared pointer with the response type. More... | |
std::shared_ptr< rmw_request_id_t > | create_request_header () override |
Create a shared pointer with a rmw_request_id_t. More... | |
void | handle_response (std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > response) override |
Handle a server response. More... | |
FutureAndRequestId | async_send_request (SharedRequest request) |
Send a request to the service server. More... | |
template<typename CallbackT , typename std::enable_if< rclcpp::function_traits::same_arguments< CallbackT, CallbackType >::value >::type * = nullptr> | |
SharedFutureAndRequestId | async_send_request (SharedRequest request, CallbackT &&cb) |
Send a request to the service server and schedule a callback in the executor. More... | |
template<typename CallbackT , typename std::enable_if< rclcpp::function_traits::same_arguments< CallbackT, CallbackWithRequestType >::value >::type * = nullptr> | |
SharedFutureWithRequestAndRequestId | async_send_request (SharedRequest request, CallbackT &&cb) |
Send a request to the service server and schedule a callback in the executor. More... | |
bool | remove_pending_request (int64_t request_id) |
Cleanup a pending request. More... | |
bool | remove_pending_request (const FutureAndRequestId &future) |
Cleanup a pending request. More... | |
bool | remove_pending_request (const SharedFutureAndRequestId &future) |
Cleanup a pending request. More... | |
bool | remove_pending_request (const SharedFutureWithRequestAndRequestId &future) |
Cleanup a pending request. More... | |
size_t | prune_pending_requests () |
Clean all pending requests. More... | |
template<typename AllocatorT = std::allocator<int64_t>> | |
size_t | prune_requests_older_than (std::chrono::time_point< std::chrono::system_clock > time_point, std::vector< int64_t, AllocatorT > *pruned_requests=nullptr) |
Clean all pending requests older than a time_point. More... | |
![]() | |
RCLCPP_PUBLIC | ClientBase (rclcpp::node_interfaces::NodeBaseInterface *node_base, rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph) |
RCLCPP_PUBLIC bool | take_type_erased_response (void *response_out, rmw_request_id_t &request_header_out) |
Take the next response for this client as a type erased pointer. More... | |
RCLCPP_PUBLIC const char * | get_service_name () const |
Return the name of the service. More... | |
RCLCPP_PUBLIC std::shared_ptr< rcl_client_t > | get_client_handle () |
Return the rcl_client_t client handle in a std::shared_ptr. More... | |
RCLCPP_PUBLIC std::shared_ptr< const rcl_client_t > | get_client_handle () const |
Return the rcl_client_t client handle in a std::shared_ptr. More... | |
RCLCPP_PUBLIC bool | service_is_ready () const |
Return if the service is ready. More... | |
template<typename RepT = int64_t, typename RatioT = std::milli> | |
bool | wait_for_service (std::chrono::duration< RepT, RatioT > timeout=std::chrono::duration< RepT, RatioT >(-1)) |
Wait for a service to be ready. More... | |
RCLCPP_PUBLIC bool | exchange_in_use_by_wait_set_state (bool in_use_state) |
Exchange the "in use by wait set" state for this client. More... | |
RCLCPP_PUBLIC rclcpp::QoS | get_request_publisher_actual_qos () const |
Get the actual request publsher QoS settings, after the defaults have been determined. More... | |
RCLCPP_PUBLIC rclcpp::QoS | get_response_subscription_actual_qos () const |
Get the actual response subscription QoS settings, after the defaults have been determined. More... | |
void | set_on_new_response_callback (std::function< void(size_t)> callback) |
Set a callback to be called when each new response is received. More... | |
void | clear_on_new_response_callback () |
Unset the callback registered for new responses, if any. | |
Protected Member Functions | |
int64_t | async_send_request_impl (const Request &request, CallbackInfoVariant value) |
std::optional< CallbackInfoVariant > | get_and_erase_pending_request (int64_t request_number) |
![]() | |
RCLCPP_PUBLIC bool | wait_for_service_nanoseconds (std::chrono::nanoseconds timeout) |
RCLCPP_PUBLIC rcl_node_t * | get_rcl_node_handle () |
RCLCPP_PUBLIC const rcl_node_t * | get_rcl_node_handle () const |
RCLCPP_PUBLIC void | set_on_new_response_callback (rcl_event_callback_t callback, const void *user_data) |
Protected Attributes | |
std::unordered_map< int64_t, std::pair< std::chrono::time_point< std::chrono::system_clock >, CallbackInfoVariant > > | pending_requests_ |
std::mutex | pending_requests_mutex_ |
![]() | |
rclcpp::node_interfaces::NodeGraphInterface::WeakPtr | node_graph_ |
std::shared_ptr< rcl_node_t > | node_handle_ |
std::shared_ptr< rclcpp::Context > | context_ |
rclcpp::Logger | node_logger_ |
std::shared_ptr< rcl_client_t > | client_handle_ |
std::atomic< bool > | in_use_by_wait_set_ {false} |
std::recursive_mutex | callback_mutex_ |
std::function< void(size_t)> | on_new_response_callback_ {nullptr} |
Definition at line 371 of file client.hpp.
|
inline |
Default constructor.
The constructor for a Client is almost never called directly. Instead, clients should be instantiated through the function rclcpp::create_client().
[in] | node_base | NodeBaseInterface pointer that is used in part of the setup. |
[in] | node_graph | The node graph interface of the corresponding node. |
[in] | service_name | Name of the topic to publish to. |
[in] | client_options | options for the subscription. |
Definition at line 464 of file client.hpp.
References rclcpp::expand_topic_or_service_name(), rclcpp::ClientBase::get_client_handle(), rcl_client_init(), rcl_node_get_name(), rcl_node_get_namespace(), RCL_RET_OK, and RCL_RET_SERVICE_NAME_INVALID.
|
inline |
Send a request to the service server.
This method returns a FutureAndRequestId
instance that can be passed to Executor::spin_until_future_complete() to wait until it has been completed.
If the future never completes, e.g. the call to Executor::spin_until_future_complete() times out, Client::remove_pending_request() must be called to clean the client internal state. Not doing so will make the Client
instance to use more memory each time a response is not received from the service server.
[in] | request | request to be send. |
Definition at line 608 of file client.hpp.
|
inline |
Send a request to the service server and schedule a callback in the executor.
Similar to the previous overload, but a callback will automatically be called when a response is received.
If the callback is never called, because we never got a reply for the service server, remove_pending_request() has to be called with the returned request id or prune_pending_requests(). Not doing so will make the Client
instance use more memory each time a response is not received from the service server. In this case, it's convenient to setup a timer to cleanup the pending requests. See for example the examples_rclcpp_async_client
package in https://github.com/ros2/examples.
[in] | request | request to be send. |
[in] | cb | callback that will be called when we get a response for this request. |
Definition at line 643 of file client.hpp.
|
inline |
Send a request to the service server and schedule a callback in the executor.
Similar to the previous method, but you can get both the request and response in the callback.
[in] | request | request to be send. |
[in] | cb | callback that will be called when we get a response for this request. |
Definition at line 674 of file client.hpp.
|
inlineoverridevirtual |
Create a shared pointer with a rmw_request_id_t.
Implements rclcpp::ClientBase.
Definition at line 533 of file client.hpp.
|
inlineoverridevirtual |
Create a shared pointer with the response type.
Implements rclcpp::ClientBase.
Definition at line 523 of file client.hpp.
|
inlineoverridevirtual |
Handle a server response.
[in] | request_header | used to check if the secuence number is valid |
[in] | response | message with the server response |
Implements rclcpp::ClientBase.
Definition at line 546 of file client.hpp.
|
inline |
Clean all pending requests.
Definition at line 747 of file client.hpp.
|
inline |
Clean all pending requests older than a time_point.
[in] | time_point | Requests that were sent before this point are going to be removed. |
[in,out] | pruned_requests | Removed requests id will be pushed to the vector if a pointer is provided. |
Definition at line 764 of file client.hpp.
|
inline |
Cleanup a pending request.
Convenient overload, same as:
Client::remove_pending_request(this, future.request_id)
.
Definition at line 713 of file client.hpp.
References rclcpp::Client< ServiceT >::remove_pending_request().
|
inline |
Cleanup a pending request.
Convenient overload, same as:
Client::remove_pending_request(this, future.request_id)
.
Definition at line 725 of file client.hpp.
References rclcpp::Client< ServiceT >::remove_pending_request().
|
inline |
Cleanup a pending request.
Convenient overload, same as:
Client::remove_pending_request(this, future.request_id)
.
Definition at line 737 of file client.hpp.
References rclcpp::Client< ServiceT >::remove_pending_request().
|
inline |
Cleanup a pending request.
This notifies the client that we have waited long enough for a response from the server to come, we have given up and we are not waiting for a response anymore.
Not calling this will make the client start using more memory for each request that never got a reply from the server.
[in] | request_id | request id returned by async_send_request(). |
Definition at line 700 of file client.hpp.
Referenced by rclcpp::Client< ServiceT >::remove_pending_request().
|
inline |
Take the next response for this client.
[out] | response_out | The reference to a Service Response into which the middleware will copy the response being taken. |
[out] | request_header_out | The request header to be filled by the middleware when taking, and which can be used to associte the response to a specific request. |
rclcpp::exceptions::RCLError | based exceptions if the underlying rcl function fail. |
Definition at line 513 of file client.hpp.
References rclcpp::ClientBase::take_type_erased_response().