15 #ifndef RCLCPP__NODE_HPP_
16 #define RCLCPP__NODE_HPP_
19 #include <condition_variable>
29 #include "rcutils/macros.h"
31 #include "rcl/error_handling.h"
34 #include "rcl_interfaces/msg/list_parameters_result.hpp"
35 #include "rcl_interfaces/msg/parameter_descriptor.hpp"
36 #include "rcl_interfaces/msg/set_parameters_result.hpp"
38 #include "rclcpp/callback_group.hpp"
39 #include "rclcpp/client.hpp"
40 #include "rclcpp/clock.hpp"
41 #include "rclcpp/context.hpp"
42 #include "rclcpp/event.hpp"
43 #include "rclcpp/generic_client.hpp"
44 #include "rclcpp/generic_publisher.hpp"
45 #include "rclcpp/generic_service.hpp"
46 #include "rclcpp/generic_subscription.hpp"
47 #include "rclcpp/logger.hpp"
48 #include "rclcpp/macros.hpp"
49 #include "rclcpp/message_memory_strategy.hpp"
50 #include "rclcpp/node_interfaces/node_base_interface.hpp"
51 #include "rclcpp/node_interfaces/node_clock_interface.hpp"
52 #include "rclcpp/node_interfaces/node_graph_interface.hpp"
53 #include "rclcpp/node_interfaces/node_logging_interface.hpp"
54 #include "rclcpp/node_interfaces/node_parameters_interface.hpp"
55 #include "rclcpp/node_interfaces/node_services_interface.hpp"
56 #include "rclcpp/node_interfaces/node_time_source_interface.hpp"
57 #include "rclcpp/node_interfaces/node_timers_interface.hpp"
58 #include "rclcpp/node_interfaces/node_topics_interface.hpp"
59 #include "rclcpp/node_interfaces/node_type_descriptions_interface.hpp"
60 #include "rclcpp/node_interfaces/node_waitables_interface.hpp"
61 #include "rclcpp/node_options.hpp"
62 #include "rclcpp/parameter.hpp"
63 #include "rclcpp/publisher.hpp"
64 #include "rclcpp/publisher_options.hpp"
65 #include "rclcpp/qos.hpp"
66 #include "rclcpp/service.hpp"
67 #include "rclcpp/subscription.hpp"
68 #include "rclcpp/subscription_options.hpp"
69 #include "rclcpp/time.hpp"
70 #include "rclcpp/timer.hpp"
71 #include "rclcpp/visibility_control.hpp"
77 class Node :
public std::enable_shared_from_this<Node>
80 RCLCPP_SMART_PTR_DEFINITIONS(
Node)
90 const std::string & node_name,
102 const std::string & node_name,
103 const std::string & namespace_,
146 rclcpp::CallbackGroup::SharedPtr
148 rclcpp::CallbackGroupType group_type,
149 bool automatically_add_to_executor_with_node =
true);
192 typename AllocatorT = std::allocator<void>,
194 std::shared_ptr<PublisherT>
196 const std::string & topic_name,
214 typename AllocatorT = std::allocator<void>,
216 typename MessageMemoryStrategyT =
typename SubscriptionT::MessageMemoryStrategyType
218 std::shared_ptr<SubscriptionT>
220 const std::string & topic_name,
222 CallbackT && callback,
225 typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = (
226 MessageMemoryStrategyT::create_default()
237 template<
typename DurationRepT =
int64_t,
typename DurationT = std::milli,
typename CallbackT>
240 std::chrono::duration<DurationRepT, DurationT> period,
242 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr,
243 bool autostart =
true);
251 template<
typename DurationRepT =
int64_t,
typename DurationT = std::milli,
typename CallbackT>
254 std::chrono::duration<DurationRepT, DurationT> period,
256 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr);
265 template<
typename ServiceT>
268 const std::string & service_name,
270 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr);
280 template<
typename ServiceT,
typename CallbackT>
283 const std::string & service_name,
284 CallbackT && callback,
286 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr);
297 rclcpp::GenericClient::SharedPtr
299 const std::string & service_name,
300 const std::string & service_type,
302 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr);
313 template<
typename CallbackT>
314 typename rclcpp::GenericService::SharedPtr
316 const std::string & service_name,
317 const std::string & service_type,
318 CallbackT && callback,
320 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr);
335 template<
typename AllocatorT = std::allocator<
void>>
337 const std::string & topic_name,
338 const std::string & topic_type,
362 typename AllocatorT = std::allocator<void>>
364 const std::string & topic_name,
365 const std::string & topic_type,
367 CallbackT && callback,
428 const std::string & name,
430 const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
431 rcl_interfaces::msg::ParameterDescriptor(),
432 bool ignore_override =
false);
453 const std::string & name,
454 rclcpp::ParameterType type,
455 const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
456 rcl_interfaces::msg::ParameterDescriptor{},
457 bool ignore_override =
false);
480 template<
typename ParameterT>
483 const std::string & name,
484 const ParameterT & default_value,
485 const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
486 rcl_interfaces::msg::ParameterDescriptor(),
487 bool ignore_override =
false);
493 template<
typename ParameterT>
496 const std::string & name,
497 const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
498 rcl_interfaces::msg::ParameterDescriptor(),
499 bool ignore_override =
false);
548 template<
typename ParameterT>
549 std::vector<ParameterT>
551 const std::string & namespace_,
552 const std::map<std::string, ParameterT> & parameters,
553 bool ignore_overrides =
false);
562 template<
typename ParameterT>
563 std::vector<ParameterT>
565 const std::string & namespace_,
568 std::pair<ParameterT, rcl_interfaces::msg::ParameterDescriptor>
570 bool ignore_overrides =
false);
640 rcl_interfaces::msg::SetParametersResult
692 std::vector<rcl_interfaces::msg::SetParametersResult>
693 set_parameters(
const std::vector<rclcpp::Parameter> & parameters);
740 rcl_interfaces::msg::SetParametersResult
799 template<
typename ParameterT>
801 get_parameter(
const std::string & name, ParameterT & parameter)
const;
818 template<
typename ParameterT>
821 const std::string & name,
822 ParameterT & parameter,
823 const ParameterT & alternative_value)
const;
837 template<
typename ParameterT>
840 const std::string & name,
841 const ParameterT & alternative_value)
const;
864 std::vector<rclcpp::Parameter>
904 template<
typename ParameterT>
907 const std::string & prefix,
908 std::map<std::string, ParameterT> & values)
const;
928 rcl_interfaces::msg::ParameterDescriptor
951 std::vector<rcl_interfaces::msg::ParameterDescriptor>
988 rcl_interfaces::msg::ListParametersResult
989 list_parameters(
const std::vector<std::string> & prefixes, uint64_t depth)
const;
993 using PreSetParametersCallbackType =
994 rclcpp::node_interfaces::NodeParametersInterface::PreSetParametersCallbackType;
998 using OnSetParametersCallbackType =
999 rclcpp::node_interfaces::NodeParametersInterface::OnSetParametersCallbackType;
1003 using PostSetParametersCallbackType =
1004 rclcpp::node_interfaces::NodeParametersInterface::PostSetParametersCallbackType;
1064 PreSetParametersCallbackHandle::SharedPtr
1138 OnSetParametersCallbackHandle::SharedPtr
1199 PostSetParametersCallbackHandle::SharedPtr
1259 std::vector<std::string>
1268 std::map<std::string, std::vector<std::string>>
1277 std::map<std::string, std::vector<std::string>>
1291 std::map<std::string, std::vector<std::string>>
1293 const std::string & node_name,
1294 const std::string & namespace_)
const;
1359 std::vector<rclcpp::TopicEndpointInfo>
1385 std::vector<rclcpp::TopicEndpointInfo>
1415 std::vector<rclcpp::ServiceEndpointInfo>
1445 std::vector<rclcpp::ServiceEndpointInfo>
1454 rclcpp::Event::SharedPtr
1471 const rclcpp::Event::SharedPtr & event,
1472 std::chrono::nanoseconds timeout);
1479 rclcpp::Clock::SharedPtr
1487 rclcpp::Clock::ConstSharedPtr
1500 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
1505 rclcpp::node_interfaces::NodeClockInterface::SharedPtr
1510 rclcpp::node_interfaces::NodeGraphInterface::SharedPtr
1515 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr
1520 rclcpp::node_interfaces::NodeTimersInterface::SharedPtr
1525 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr
1530 rclcpp::node_interfaces::NodeServicesInterface::SharedPtr
1535 rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr
1540 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr
1545 rclcpp::node_interfaces::NodeTimeSourceInterface::SharedPtr
1550 rclcpp::node_interfaces::NodeTypeDescriptionsInterface::SharedPtr
1656 rclcpp::Node::SharedPtr
1675 const std::string & sub_namespace);
1678 RCLCPP_DISABLE_COPY(
Node)
1680 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_;
1681 rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_;
1682 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_;
1683 rclcpp::node_interfaces::NodeTimersInterface::SharedPtr node_timers_;
1684 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_;
1685 rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_;
1686 rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock_;
1687 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters_;
1688 rclcpp::node_interfaces::NodeTimeSourceInterface::SharedPtr node_time_source_;
1689 rclcpp::node_interfaces::NodeTypeDescriptionsInterface::SharedPtr node_type_descriptions_;
1690 rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr node_waitables_;
1693 const std::string sub_namespace_;
1694 const std::string effective_namespace_;
1700 std::shared_ptr<NodeImpl> hidden_impl_{
nullptr};
1705 #ifndef RCLCPP__NODE_IMPL_HPP_
1707 #include "node_impl.hpp"
Generic timer. Periodically executes a user-specified callback.
Encapsulation of options for node initialization.
Node is the single point of entry for creating publishers and subscribers.
RCLCPP_PUBLIC rclcpp::Logger get_logger() const
Get the logger of the node.
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr get_node_waitables_interface()
Return the Node's internal NodeWaitablesInterface implementation.
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr get_node_topics_interface()
Return the Node's internal NodeTopicsInterface implementation.
RCLCPP_PUBLIC std::vector< rclcpp::ServiceEndpointInfo > get_clients_info_by_service(const std::string &service_name, bool no_mangle=false) const
Return the service endpoint information about clients on a given service.
RCLCPP_PUBLIC std::vector< rclcpp::Parameter > get_parameters(const std::vector< std::string > &names) const
Return the parameters by the given parameter names.
RCLCPP_PUBLIC RCUTILS_WARN_UNUSED OnSetParametersCallbackHandle::SharedPtr add_on_set_parameters_callback(OnSetParametersCallbackType callback)
Add a callback to validate parameters before they are set.
RCLCPP_PUBLIC bool has_parameter(const std::string &name) const
Return true if a given parameter is declared.
RCLCPP_PUBLIC rclcpp::Node::SharedPtr create_sub_node(const std::string &sub_namespace)
Create a sub-node, which will extend the namespace of all entities created with it.
RCLCPP_PUBLIC rcl_interfaces::msg::SetParametersResult set_parameter(const rclcpp::Parameter ¶meter)
Set a single parameter.
RCLCPP_PUBLIC rclcpp::Clock::SharedPtr get_clock()
Get a clock as a non-const shared pointer which is managed by the node.
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeTimersInterface::SharedPtr get_node_timers_interface()
Return the Node's internal NodeTimersInterface implementation.
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeParametersInterface::SharedPtr get_node_parameters_interface()
Return the Node's internal NodeParametersInterface implementation.
RCLCPP_PUBLIC std::vector< rclcpp::TopicEndpointInfo > get_publishers_info_by_topic(const std::string &topic_name, bool no_mangle=false) const
Return the topic endpoint information about publishers on a given topic.
rclcpp::GenericService::SharedPtr create_generic_service(const std::string &service_name, const std::string &service_type, CallbackT &&callback, const rclcpp::QoS &qos=rclcpp::ServicesQoS(), const rclcpp::CallbackGroup::SharedPtr &group=nullptr)
Create and return a GenericService.
RCLCPP_PUBLIC const rclcpp::ParameterValue & declare_parameter(const std::string &name, const rclcpp::ParameterValue &default_value, const rcl_interfaces::msg::ParameterDescriptor ¶meter_descriptor=rcl_interfaces::msg::ParameterDescriptor(), bool ignore_override=false)
Declare and initialize a parameter, return the effective value.
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr get_node_logging_interface()
Return the Node's internal NodeLoggingInterface implementation.
bool get_parameter_or(const std::string &name, ParameterT ¶meter, const ParameterT &alternative_value) const
Get the parameter value, or the "alternative_value" if not set, and assign it to "parameter".
RCLCPP_PUBLIC const std::string & get_effective_namespace() const
Return the effective namespace that is used when creating entities.
RCLCPP_PUBLIC size_t count_publishers(const std::string &topic_name) const
Return the number of publishers created for a given topic.
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_service_names_and_types() const
Return a map of existing service names to list of service types.
RCLCPP_PUBLIC size_t count_subscribers(const std::string &topic_name) const
Return the number of subscribers created for a given topic.
std::vector< ParameterT > declare_parameters(const std::string &namespace_, const std::map< std::string, ParameterT > ¶meters, bool ignore_overrides=false)
Declare and initialize several parameters with the same namespace and type.
RCLCPP_PUBLIC std::vector< rcl_interfaces::msg::ParameterDescriptor > describe_parameters(const std::vector< std::string > &names) const
Return a vector of parameter descriptors, one for each of the given names.
RCLCPP_PUBLIC Time now() const
Returns current time from the node clock.
RCLCPP_PUBLIC rclcpp::Event::SharedPtr get_graph_event()
Return a graph event, which will be set anytime a graph change occurs.
RCLCPP_PUBLIC void for_each_callback_group(const node_interfaces::NodeBaseInterface::CallbackGroupFunction &func)
Iterate over the callback groups in the node, calling the given function on each valid one.
RCLCPP_PUBLIC rcl_interfaces::msg::ParameterDescriptor describe_parameter(const std::string &name) const
Return the parameter descriptor for the given parameter name.
RCLCPP_PUBLIC std::vector< rclcpp::ServiceEndpointInfo > get_servers_info_by_service(const std::string &service_name, bool no_mangle=false) const
Return the service endpoint information about servers on a given service.
RCLCPP_PUBLIC void remove_on_set_parameters_callback(const OnSetParametersCallbackHandle *const handler)
Remove a callback registered with add_on_set_parameters_callback.
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_topic_names_and_types() const
Return a map of existing topic names to list of topic types.
RCLCPP_PUBLIC rclcpp::Parameter get_parameter(const std::string &name) const
Return the parameter by the given name.
RCLCPP_PUBLIC Node(const std::string &node_name, const NodeOptions &options=NodeOptions())
Create a new node with the specified name.
RCLCPP_PUBLIC size_t count_services(const std::string &service_name) const
Return the number of services created for a given service.
rclcpp::GenericTimer< CallbackT >::SharedPtr create_timer(std::chrono::duration< DurationRepT, DurationT > period, CallbackT callback, const rclcpp::CallbackGroup::SharedPtr &group=nullptr)
Create a timer that uses the node clock to drive the callback.
RCLCPP_PUBLIC const rclcpp::NodeOptions & get_node_options() const
Return the NodeOptions used when creating this node.
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_base_interface()
Return the Node's internal NodeBaseInterface implementation.
RCLCPP_PUBLIC rcl_interfaces::msg::SetParametersResult set_parameters_atomically(const std::vector< rclcpp::Parameter > ¶meters)
Set one or more parameters, all at once.
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeClockInterface::SharedPtr get_node_clock_interface()
Return the Node's internal NodeClockInterface implementation.
RCLCPP_PUBLIC void remove_pre_set_parameters_callback(const PreSetParametersCallbackHandle *const handler)
Remove a callback registered with add_pre_set_parameters_callback.
RCLCPP_PUBLIC const char * get_name() const
Get the name of the node.
RCLCPP_PUBLIC std::vector< rcl_interfaces::msg::SetParametersResult > set_parameters(const std::vector< rclcpp::Parameter > ¶meters)
Set one or more parameters, one at a time.
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeTypeDescriptionsInterface::SharedPtr get_node_type_descriptions_interface()
Return the Node's internal NodeTypeDescriptionsInterface implementation.
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeServicesInterface::SharedPtr get_node_services_interface()
Return the Node's internal NodeServicesInterface implementation.
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_service_names_and_types_by_node(const std::string &node_name, const std::string &namespace_) const
Return a map of existing service names to list of service types for a specific node.
RCLCPP_PUBLIC void undeclare_parameter(const std::string &name)
Undeclare a previously declared parameter.
RCLCPP_PUBLIC std::vector< uint8_t > get_parameter_types(const std::vector< std::string > &names) const
Return a vector of parameter types, one for each of the given names.
RCLCPP_PUBLIC std::vector< rclcpp::TopicEndpointInfo > get_subscriptions_info_by_topic(const std::string &topic_name, bool no_mangle=false) const
Return the topic endpoint information about subscriptions on a given topic.
std::shared_ptr< rclcpp::GenericSubscription > create_generic_subscription(const std::string &topic_name, const std::string &topic_type, const rclcpp::QoS &qos, CallbackT &&callback, const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &options=(rclcpp::SubscriptionOptionsWithAllocator< AllocatorT >()))
Create and return a GenericSubscription.
RCLCPP_PUBLIC rclcpp::CallbackGroup::SharedPtr create_callback_group(rclcpp::CallbackGroupType group_type, bool automatically_add_to_executor_with_node=true)
Create and return a callback group.
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeTimeSourceInterface::SharedPtr get_node_time_source_interface()
Return the Node's internal NodeTimeSourceInterface implementation.
RCLCPP_PUBLIC RCUTILS_WARN_UNUSED PreSetParametersCallbackHandle::SharedPtr add_pre_set_parameters_callback(PreSetParametersCallbackType callback)
Add a callback that gets triggered before parameters are validated.
RCLCPP_PUBLIC rcl_interfaces::msg::ListParametersResult list_parameters(const std::vector< std::string > &prefixes, uint64_t depth) const
Return a list of parameters with any of the given prefixes, up to the given depth.
std::shared_ptr< SubscriptionT > create_subscription(const std::string &topic_name, const rclcpp::QoS &qos, CallbackT &&callback, const SubscriptionOptionsWithAllocator< AllocatorT > &options=SubscriptionOptionsWithAllocator< AllocatorT >(), typename MessageMemoryStrategyT::SharedPtr msg_mem_strat=(MessageMemoryStrategyT::create_default()))
Create and return a Subscription.
RCLCPP_PUBLIC size_t count_clients(const std::string &service_name) const
Return the number of clients created for a given service.
std::shared_ptr< PublisherT > create_publisher(const std::string &topic_name, const rclcpp::QoS &qos, const PublisherOptionsWithAllocator< AllocatorT > &options=PublisherOptionsWithAllocator< AllocatorT >())
Create and return a Publisher.
rclcpp::WallTimer< CallbackT >::SharedPtr create_wall_timer(std::chrono::duration< DurationRepT, DurationT > period, CallbackT callback, const rclcpp::CallbackGroup::SharedPtr &group=nullptr, bool autostart=true)
Create a wall timer that uses the wall clock to drive the callback.
RCLCPP_PUBLIC const char * get_fully_qualified_name() const
Get the fully-qualified name of the node.
RCLCPP_PUBLIC const std::string & get_sub_namespace() const
Return the sub-namespace, if this is a sub-node, otherwise an empty string.
RCLCPP_PUBLIC std::vector< std::string > get_node_names() const
Get the fully-qualified names of all available nodes.
rclcpp::Client< ServiceT >::SharedPtr create_client(const std::string &service_name, const rclcpp::QoS &qos=rclcpp::ServicesQoS(), const rclcpp::CallbackGroup::SharedPtr &group=nullptr)
Create and return a Client.
RCLCPP_PUBLIC void wait_for_graph_change(const rclcpp::Event::SharedPtr &event, std::chrono::nanoseconds timeout)
Wait for a graph event to occur by waiting on an Event to become set.
RCLCPP_PUBLIC const char * get_namespace() const
Get the namespace of the node.
RCLCPP_PUBLIC RCUTILS_WARN_UNUSED PostSetParametersCallbackHandle::SharedPtr add_post_set_parameters_callback(PostSetParametersCallbackType callback)
Add a callback that gets triggered after parameters are set successfully.
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeGraphInterface::SharedPtr get_node_graph_interface()
Return the Node's internal NodeGraphInterface implementation.
RCLCPP_PUBLIC void remove_post_set_parameters_callback(const PostSetParametersCallbackHandle *const handler)
Remove a callback registered with add_post_set_parameters_callback.
std::shared_ptr< rclcpp::GenericPublisher > create_generic_publisher(const std::string &topic_name, const std::string &topic_type, const rclcpp::QoS &qos, const rclcpp::PublisherOptionsWithAllocator< AllocatorT > &options=(rclcpp::PublisherOptionsWithAllocator< AllocatorT >()))
Create and return a GenericPublisher.
RCLCPP_PUBLIC rclcpp::GenericClient::SharedPtr create_generic_client(const std::string &service_name, const std::string &service_type, const rclcpp::QoS &qos=rclcpp::ServicesQoS(), const rclcpp::CallbackGroup::SharedPtr &group=nullptr)
Create and return a GenericClient.
rclcpp::Service< ServiceT >::SharedPtr create_service(const std::string &service_name, CallbackT &&callback, const rclcpp::QoS &qos=rclcpp::ServicesQoS(), const rclcpp::CallbackGroup::SharedPtr &group=nullptr)
Create and return a Service.
Store the type and value of a parameter.
Structure to store an arbitrary parameter with templated get/set methods.
A publisher publishes messages of any type to a topic.
Encapsulation of Quality of Service settings.
Subscription implementation, templated on the type of message this subscription receives.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Structure containing optional configuration for Publishers.
Structure containing optional configuration for Subscriptions.