ROS 2 rclcpp + rcl - kilted
kilted
ROS 2 C++ Client Library with ROS Client Library
|
Classes | |
struct | FutureAndRequestId |
A convenient GenericClient::Future and request id pair. More... | |
struct | SharedFutureAndRequestId |
A convenient GenericClient::SharedFuture and request id pair. More... | |
Public Member Functions | |
GenericClient (rclcpp::node_interfaces::NodeBaseInterface *node_base, rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph, const std::string &service_name, const std::string &service_type, rcl_client_options_t &client_options) | |
RCLCPP_PUBLIC SharedResponse | create_response () override |
RCLCPP_PUBLIC std::shared_ptr< rmw_request_id_t > | create_request_header () override |
RCLCPP_PUBLIC void | handle_response (std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > response) override |
RCLCPP_PUBLIC FutureAndRequestId | async_send_request (const Request 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 (const Request request, CallbackT &&cb) |
Send a request to the service server and schedule a callback in the executor. 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 size_t | prune_pending_requests () |
Clean all pending requests. More... | |
RCLCPP_PUBLIC bool | remove_pending_request (int64_t request_id) |
Cleanup a pending request. More... | |
RCLCPP_PUBLIC bool | remove_pending_request (const FutureAndRequestId &future) |
Cleanup a pending request. More... | |
RCLCPP_PUBLIC bool | remove_pending_request (const SharedFutureAndRequestId &future) |
Cleanup a pending request. More... | |
RCLCPP_PUBLIC bool | take_response (Response response_out, rmw_request_id_t &request_header_out) |
Take the next response for this client. 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 Types | |
using | CallbackTypeValueVariant = std::tuple< CallbackType, SharedFuture, Promise > |
using | CallbackInfoVariant = std::variant< std::promise< SharedResponse >, CallbackTypeValueVariant > |
Protected Member Functions | |
RCLCPP_PUBLIC 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::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::recursive_mutex | callback_mutex_ |
std::function< void(size_t)> | on_new_response_callback_ {nullptr} |
std::shared_ptr< rcl_client_t > | client_handle_ |
std::atomic< bool > | in_use_by_wait_set_ {false} |
Definition at line 36 of file generic_client.hpp.
GenericClient::FutureAndRequestId rclcpp::GenericClient::async_send_request | ( | const Request | request | ) |
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, GenericClient::remove_pending_request() must be called to clean the client internal state. Not doing so will make the GenericClient
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 167 of file generic_client.cpp.
|
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 GenericClient
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.
[in] | request | request to be send. |
[in] | cb | callback that will be called when we get a response for this request. |
Definition at line 175 of file generic_client.hpp.
size_t rclcpp::GenericClient::prune_pending_requests | ( | ) |
Clean all pending requests.
Definition at line 123 of file generic_client.cpp.
|
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 197 of file generic_client.hpp.
bool rclcpp::GenericClient::remove_pending_request | ( | const FutureAndRequestId & | future | ) |
Cleanup a pending request.
Convenient overload, same as:
GenericClient::remove_pending_request(this, future.request_id)
.
Definition at line 139 of file generic_client.cpp.
bool rclcpp::GenericClient::remove_pending_request | ( | const SharedFutureAndRequestId & | future | ) |
Cleanup a pending request.
Convenient overload, same as:
GenericClient::remove_pending_request(this, future.request_id)
.
Definition at line 145 of file generic_client.cpp.
bool rclcpp::GenericClient::remove_pending_request | ( | int64_t | request_id | ) |
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 132 of file generic_client.cpp.
|
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 associate the response to a specific request. |
rclcpp::exceptions::RCLError | based exceptions if the underlying rcl function fail. |
Definition at line 269 of file generic_client.hpp.
References rclcpp::ClientBase::take_type_erased_response().