15 #ifndef RCLCPP__PARAMETER_CLIENT_HPP_
16 #define RCLCPP__PARAMETER_CLIENT_HPP_
25 #include "rcl_interfaces/msg/parameter.hpp"
26 #include "rcl_interfaces/msg/parameter_event.hpp"
27 #include "rcl_interfaces/msg/parameter_value.hpp"
28 #include "rcl_interfaces/srv/describe_parameters.hpp"
29 #include "rcl_interfaces/srv/get_parameter_types.hpp"
30 #include "rcl_interfaces/srv/get_parameters.hpp"
31 #include "rcl_interfaces/srv/list_parameters.hpp"
32 #include "rcl_interfaces/srv/set_parameters.hpp"
33 #include "rcl_interfaces/srv/set_parameters_atomically.hpp"
34 #include "rcl_yaml_param_parser/parser.h"
35 #include "rclcpp/exceptions.hpp"
36 #include "rclcpp/executors.hpp"
37 #include "rclcpp/create_subscription.hpp"
38 #include "rclcpp/macros.hpp"
39 #include "rclcpp/node.hpp"
40 #include "rclcpp/parameter.hpp"
41 #include "rclcpp/parameter_map.hpp"
42 #include "rclcpp/qos.hpp"
43 #include "rclcpp/type_support_decl.hpp"
44 #include "rclcpp/visibility_control.hpp"
66 [[deprecated(
"use rclcpp::QoS instead of rmw_qos_profile_t")]]
69 const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface,
70 const rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface,
71 const rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface,
72 const rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface,
73 const std::string & remote_node_name,
74 const rmw_qos_profile_t & qos_profile,
75 rclcpp::CallbackGroup::SharedPtr group =
nullptr)
78 node_topics_interface,
80 node_services_interface,
98 const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface,
99 const rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface,
100 const rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface,
101 const rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface,
102 const std::string & remote_node_name =
"",
104 rclcpp::CallbackGroup::SharedPtr group =
nullptr);
114 template<
typename NodeT>
115 [[deprecated(
"use rclcpp::QoS instead of rmw_qos_profile_t")]]
117 const std::shared_ptr<NodeT> node,
118 const std::string & remote_node_name,
119 const rmw_qos_profile_t & qos_profile,
120 rclcpp::CallbackGroup::SharedPtr group =
nullptr)
122 node->get_node_base_interface(),
123 node->get_node_topics_interface(),
124 node->get_node_graph_interface(),
125 node->get_node_services_interface(),
137 template<
typename NodeT>
139 const std::shared_ptr<NodeT> node,
140 const std::string & remote_node_name =
"",
142 rclcpp::CallbackGroup::SharedPtr group =
nullptr)
144 node->get_node_base_interface(),
145 node->get_node_topics_interface(),
146 node->get_node_graph_interface(),
147 node->get_node_services_interface(),
161 template<
typename NodeT>
162 [[deprecated(
"use rclcpp::QoS instead of rmw_qos_profile_t")]]
165 const std::string & remote_node_name,
166 const rmw_qos_profile_t & qos_profile,
167 rclcpp::CallbackGroup::SharedPtr group =
nullptr)
169 node->get_node_base_interface(),
170 node->get_node_topics_interface(),
171 node->get_node_graph_interface(),
172 node->get_node_services_interface(),
184 template<
typename NodeT>
187 const std::string & remote_node_name =
"",
189 rclcpp::CallbackGroup::SharedPtr group =
nullptr)
191 node->get_node_base_interface(),
192 node->get_node_topics_interface(),
193 node->get_node_graph_interface(),
194 node->get_node_services_interface(),
201 std::shared_future<std::vector<rclcpp::Parameter>>
203 const std::vector<std::string> & names,
205 void(std::shared_future<std::vector<rclcpp::Parameter>>)
206 > callback =
nullptr);
209 std::shared_future<std::vector<rcl_interfaces::msg::ParameterDescriptor>>
211 const std::vector<std::string> & names,
213 void(std::shared_future<std::vector<rcl_interfaces::msg::ParameterDescriptor>>)
214 > callback =
nullptr);
217 std::shared_future<std::vector<rclcpp::ParameterType>>
219 const std::vector<std::string> & names,
221 void(std::shared_future<std::vector<rclcpp::ParameterType>>)
222 > callback =
nullptr);
225 std::shared_future<std::vector<rcl_interfaces::msg::SetParametersResult>>
227 const std::vector<rclcpp::Parameter> & parameters,
229 void(std::shared_future<std::vector<rcl_interfaces::msg::SetParametersResult>>)
230 > callback =
nullptr);
233 std::shared_future<rcl_interfaces::msg::SetParametersResult>
234 set_parameters_atomically(
235 const std::vector<rclcpp::Parameter> & parameters,
237 void(std::shared_future<rcl_interfaces::msg::SetParametersResult>)
238 > callback =
nullptr);
248 std::shared_future<std::vector<rcl_interfaces::msg::SetParametersResult>>
250 const std::vector<std::string> & parameters_names);
260 std::shared_future<std::vector<rcl_interfaces::msg::SetParametersResult>>
262 const std::string & yaml_filename);
276 std::shared_future<std::vector<rcl_interfaces::msg::SetParametersResult>>
280 std::shared_future<rcl_interfaces::msg::ListParametersResult>
282 const std::vector<std::string> & prefixes,
285 void(std::shared_future<rcl_interfaces::msg::ListParametersResult>)
286 > callback =
nullptr);
290 typename AllocatorT = std::allocator<void>>
293 CallbackT && callback,
299 return this->on_parameter_event(
300 this->node_topics_interface_,
314 typename AllocatorT = std::allocator<void>>
318 CallbackT && callback,
324 return rclcpp::create_subscription<rcl_interfaces::msg::ParameterEvent>(
328 std::forward<CallbackT>(callback),
352 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
355 std::chrono::duration<RepT, RatioT> timeout = std::chrono::duration<RepT, RatioT>(-1))
357 return wait_for_service_nanoseconds(
358 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
365 wait_for_service_nanoseconds(std::chrono::nanoseconds timeout);
368 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface_;
371 get_parameter_types_client_;
374 set_parameters_atomically_client_;
377 describe_parameters_client_;
378 std::string remote_node_name_;
386 template<
typename NodeT>
387 [[deprecated(
"use rclcpp::QoS instead of rmw_qos_profile_t")]]
389 std::shared_ptr<NodeT> node,
390 const std::string & remote_node_name,
391 const rmw_qos_profile_t & qos_profile)
393 std::make_shared<rclcpp::executors::SingleThreadedExecutor>(),
399 template<
typename NodeT>
401 std::shared_ptr<NodeT> node,
402 const std::string & remote_node_name =
"",
405 std::make_shared<rclcpp::executors::SingleThreadedExecutor>(),
411 template<
typename NodeT>
412 [[deprecated(
"use rclcpp::QoS instead of rmw_qos_profile_t")]]
414 rclcpp::Executor::SharedPtr executor,
415 std::shared_ptr<NodeT> node,
416 const std::string & remote_node_name,
417 const rmw_qos_profile_t & qos_profile)
420 node->get_node_base_interface(),
421 node->get_node_topics_interface(),
422 node->get_node_graph_interface(),
423 node->get_node_services_interface(),
428 template<
typename NodeT>
430 rclcpp::Executor::SharedPtr executor,
431 std::shared_ptr<NodeT> node,
432 const std::string & remote_node_name =
"",
436 node->get_node_base_interface(),
437 node->get_node_topics_interface(),
438 node->get_node_graph_interface(),
439 node->get_node_services_interface(),
444 template<
typename NodeT>
445 [[deprecated(
"use rclcpp::QoS instead of rmw_qos_profile_t")]]
448 const std::string & remote_node_name,
449 const rmw_qos_profile_t & qos_profile)
451 std::make_shared<rclcpp::executors::SingleThreadedExecutor>(),
457 template<
typename NodeT>
460 const std::string & remote_node_name =
"",
463 std::make_shared<rclcpp::executors::SingleThreadedExecutor>(),
469 template<
typename NodeT>
470 [[deprecated(
"use rclcpp::QoS instead of rmw_qos_profile_t")]]
472 rclcpp::Executor::SharedPtr executor,
474 const std::string & remote_node_name,
475 const rmw_qos_profile_t & qos_profile)
478 node->get_node_base_interface(),
479 node->get_node_topics_interface(),
480 node->get_node_graph_interface(),
481 node->get_node_services_interface(),
486 template<
typename NodeT>
488 rclcpp::Executor::SharedPtr executor,
490 const std::string & remote_node_name =
"",
494 node->get_node_base_interface(),
495 node->get_node_topics_interface(),
496 node->get_node_graph_interface(),
497 node->get_node_services_interface(),
502 [[deprecated(
"use rclcpp::QoS instead of rmw_qos_profile_t")]]
505 rclcpp::Executor::SharedPtr executor,
506 const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface,
507 const rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface,
508 const rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface,
509 const rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface,
510 const std::string & remote_node_name,
511 const rmw_qos_profile_t & qos_profile)
512 : executor_(executor), node_base_interface_(node_base_interface)
514 async_parameters_client_ =
515 std::make_shared<AsyncParametersClient>(
517 node_topics_interface,
518 node_graph_interface,
519 node_services_interface,
526 rclcpp::Executor::SharedPtr executor,
527 const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface,
528 const rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface,
529 const rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface,
530 const rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface,
531 const std::string & remote_node_name =
"",
533 : executor_(executor), node_base_interface_(node_base_interface)
535 async_parameters_client_ =
536 std::make_shared<AsyncParametersClient>(
538 node_topics_interface,
539 node_graph_interface,
540 node_services_interface,
545 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
546 std::vector<rclcpp::Parameter>
548 const std::vector<std::string> & parameter_names,
549 std::chrono::duration<RepT, RatioT> timeout = std::chrono::duration<RepT, RatioT>(-1))
551 return get_parameters(
553 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
559 has_parameter(
const std::string & parameter_name);
564 const std::string & parameter_name, std::function<T()> parameter_not_found_handler)
566 std::vector<std::string> names;
567 names.push_back(parameter_name);
568 auto vars = get_parameters(names);
569 if ((vars.size() != 1) || (vars[0].get_type() == rclcpp::ParameterType::PARAMETER_NOT_SET)) {
570 return parameter_not_found_handler();
572 return static_cast<T
>(vars[0].get_value<T>());
578 get_parameter(
const std::string & parameter_name,
const T & default_value)
580 return get_parameter_impl(
582 std::function<T()>([&default_value]() -> T {
return default_value;}));
587 get_parameter(
const std::string & parameter_name)
589 return get_parameter_impl(
592 [¶meter_name]() -> T
594 throw std::runtime_error(
"Parameter '" + parameter_name +
"' is not set");
599 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
600 std::vector<rcl_interfaces::msg::ParameterDescriptor>
602 const std::vector<std::string> & parameter_names,
603 std::chrono::duration<RepT, RatioT> timeout = std::chrono::duration<RepT, RatioT>(-1))
605 return describe_parameters(
607 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
611 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
612 std::vector<rclcpp::ParameterType>
614 const std::vector<std::string> & parameter_names,
615 std::chrono::duration<RepT, RatioT> timeout = std::chrono::duration<RepT, RatioT>(-1))
617 return get_parameter_types(
619 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
623 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
624 std::vector<rcl_interfaces::msg::SetParametersResult>
626 const std::vector<rclcpp::Parameter> & parameters,
627 std::chrono::duration<RepT, RatioT> timeout = std::chrono::duration<RepT, RatioT>(-1))
629 return set_parameters(
631 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
635 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
636 rcl_interfaces::msg::SetParametersResult
637 set_parameters_atomically(
638 const std::vector<rclcpp::Parameter> & parameters,
639 std::chrono::duration<RepT, RatioT> timeout = std::chrono::duration<RepT, RatioT>(-1))
641 return set_parameters_atomically(
643 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
655 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
656 std::vector<rcl_interfaces::msg::SetParametersResult>
658 const std::vector<std::string> & parameters_names,
659 std::chrono::duration<RepT, RatioT> timeout = std::chrono::duration<RepT, RatioT>(-1))
663 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
675 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
676 std::vector<rcl_interfaces::msg::SetParametersResult>
678 const std::string & yaml_filename,
679 std::chrono::duration<RepT, RatioT> timeout = std::chrono::duration<RepT, RatioT>(-1))
683 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
687 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
688 rcl_interfaces::msg::ListParametersResult
690 const std::vector<std::string> & parameter_prefixes,
692 std::chrono::duration<RepT, RatioT> timeout = std::chrono::duration<RepT, RatioT>(-1))
694 return list_parameters(
697 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
701 template<
typename CallbackT>
703 on_parameter_event(CallbackT && callback)
705 return async_parameters_client_->on_parameter_event(
706 std::forward<CallbackT>(callback));
720 CallbackT && callback)
722 return AsyncParametersClient::on_parameter_event(
724 std::forward<CallbackT>(callback));
729 service_is_ready()
const
731 return async_parameters_client_->service_is_ready();
734 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
737 std::chrono::duration<RepT, RatioT> timeout = std::chrono::duration<RepT, RatioT>(-1))
739 return async_parameters_client_->wait_for_service(timeout);
744 std::vector<rclcpp::Parameter>
746 const std::vector<std::string> & parameter_names,
747 std::chrono::nanoseconds timeout);
750 std::vector<rcl_interfaces::msg::ParameterDescriptor>
752 const std::vector<std::string> & parameter_names,
753 std::chrono::nanoseconds timeout);
756 std::vector<rclcpp::ParameterType>
758 const std::vector<std::string> & parameter_names,
759 std::chrono::nanoseconds timeout);
762 std::vector<rcl_interfaces::msg::SetParametersResult>
764 const std::vector<rclcpp::Parameter> & parameters,
765 std::chrono::nanoseconds timeout);
768 std::vector<rcl_interfaces::msg::SetParametersResult>
770 const std::vector<std::string> & parameters_names,
771 std::chrono::nanoseconds timeout);
774 std::vector<rcl_interfaces::msg::SetParametersResult>
776 const std::string & yaml_filename,
777 std::chrono::nanoseconds timeout);
780 rcl_interfaces::msg::SetParametersResult
781 set_parameters_atomically(
782 const std::vector<rclcpp::Parameter> & parameters,
783 std::chrono::nanoseconds timeout);
786 rcl_interfaces::msg::ListParametersResult
788 const std::vector<std::string> & parameter_prefixes,
790 std::chrono::nanoseconds timeout);
793 rclcpp::Executor::SharedPtr executor_;
794 const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface_;
795 AsyncParametersClient::SharedPtr async_parameters_client_;
AsyncParametersClient(NodeT *node, const std::string &remote_node_name, const rmw_qos_profile_t &qos_profile, rclcpp::CallbackGroup::SharedPtr group=nullptr)
Constructor.
RCLCPP_PUBLIC std::shared_future< std::vector< rcl_interfaces::msg::SetParametersResult > > load_parameters(const std::string &yaml_filename)
Load parameters from yaml file.
static rclcpp::Subscription< rcl_interfaces::msg::ParameterEvent >::SharedPtr on_parameter_event(NodeT &&node, CallbackT &&callback, const rclcpp::QoS &qos=rclcpp::ParameterEventsQoS(), const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &options=(rclcpp::SubscriptionOptionsWithAllocator< AllocatorT >()))
RCLCPP_PUBLIC AsyncParametersClient(const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface, const rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface, const rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface, const rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface, const std::string &remote_node_name, const rmw_qos_profile_t &qos_profile, rclcpp::CallbackGroup::SharedPtr group=nullptr)
Create an async parameters client.
AsyncParametersClient(const std::shared_ptr< NodeT > node, const std::string &remote_node_name="", const rclcpp::QoS &qos_profile=rclcpp::ParametersQoS(), rclcpp::CallbackGroup::SharedPtr group=nullptr)
bool wait_for_service(std::chrono::duration< RepT, RatioT > timeout=std::chrono::duration< RepT, RatioT >(-1))
Wait for the services to be ready.
AsyncParametersClient(const std::shared_ptr< NodeT > node, const std::string &remote_node_name, const rmw_qos_profile_t &qos_profile, rclcpp::CallbackGroup::SharedPtr group=nullptr)
Constructor.
RCLCPP_PUBLIC bool service_is_ready() const
Return if the parameter services are ready.
RCLCPP_PUBLIC std::shared_future< std::vector< rcl_interfaces::msg::SetParametersResult > > delete_parameters(const std::vector< std::string > ¶meters_names)
Delete several parameters at once.
AsyncParametersClient(NodeT *node, const std::string &remote_node_name="", const rclcpp::QoS &qos_profile=rclcpp::ParametersQoS(), rclcpp::CallbackGroup::SharedPtr group=nullptr)
Encapsulation of Quality of Service settings.
Subscription implementation, templated on the type of message this subscription receives.
std::vector< rcl_interfaces::msg::SetParametersResult > delete_parameters(const std::vector< std::string > ¶meters_names, std::chrono::duration< RepT, RatioT > timeout=std::chrono::duration< RepT, RatioT >(-1))
Delete several parameters at once.
std::vector< rcl_interfaces::msg::SetParametersResult > load_parameters(const std::string &yaml_filename, std::chrono::duration< RepT, RatioT > timeout=std::chrono::duration< RepT, RatioT >(-1))
Load parameters from yaml file.
static rclcpp::Subscription< rcl_interfaces::msg::ParameterEvent >::SharedPtr on_parameter_event(NodeT &&node, CallbackT &&callback)
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
std::unordered_map< std::string, std::vector< Parameter > > ParameterMap
A map of fully qualified node names to a list of parameters.
QoS initialization values, cannot be created directly, use KeepAll or KeepLast instead.
static QoSInitialization from_rmw(const rmw_qos_profile_t &rmw_qos)
Create a QoSInitialization from an existing rmw_qos_profile_t, using its history and depth.
Structure containing optional configuration for Subscriptions.