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/subscription_traits.hpp"
70 #include "rclcpp/time.hpp"
71 #include "rclcpp/timer.hpp"
72 #include "rclcpp/visibility_control.hpp"
78 class Node :
public std::enable_shared_from_this<Node>
81 RCLCPP_SMART_PTR_DEFINITIONS(
Node)
91 const std::string & node_name,
103 const std::string & node_name,
104 const std::string & namespace_,
147 rclcpp::CallbackGroup::SharedPtr
149 rclcpp::CallbackGroupType group_type,
150 bool automatically_add_to_executor_with_node =
true);
193 typename AllocatorT = std::allocator<void>,
195 std::shared_ptr<PublisherT>
197 const std::string & topic_name,
215 typename AllocatorT = std::allocator<void>,
217 typename MessageMemoryStrategyT =
typename SubscriptionT::MessageMemoryStrategyType
219 std::shared_ptr<SubscriptionT>
221 const std::string & topic_name,
223 CallbackT && callback,
226 typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = (
227 MessageMemoryStrategyT::create_default()
238 template<
typename DurationRepT =
int64_t,
typename DurationT = std::milli,
typename CallbackT>
241 std::chrono::duration<DurationRepT, DurationT> period,
243 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr,
244 bool autostart =
true);
252 template<
typename DurationRepT =
int64_t,
typename DurationT = std::milli,
typename CallbackT>
255 std::chrono::duration<DurationRepT, DurationT> period,
257 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr);
266 template<
typename ServiceT>
269 const std::string & service_name,
271 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr);
281 template<
typename ServiceT,
typename CallbackT>
284 const std::string & service_name,
285 CallbackT && callback,
287 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr);
298 rclcpp::GenericClient::SharedPtr
300 const std::string & service_name,
301 const std::string & service_type,
303 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr);
314 template<
typename CallbackT>
315 typename rclcpp::GenericService::SharedPtr
317 const std::string & service_name,
318 const std::string & service_type,
319 CallbackT && callback,
321 const rclcpp::CallbackGroup::SharedPtr & group =
nullptr);
336 template<
typename AllocatorT = std::allocator<
void>>
338 const std::string & topic_name,
339 const std::string & topic_type,
363 typename AllocatorT = std::allocator<void>>
365 const std::string & topic_name,
366 const std::string & topic_type,
368 CallbackT && callback,
429 const std::string & name,
431 const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
432 rcl_interfaces::msg::ParameterDescriptor(),
433 bool ignore_override =
false);
454 const std::string & name,
455 rclcpp::ParameterType type,
456 const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
457 rcl_interfaces::msg::ParameterDescriptor{},
458 bool ignore_override =
false);
481 template<
typename ParameterT>
484 const std::string & name,
485 const ParameterT & default_value,
486 const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
487 rcl_interfaces::msg::ParameterDescriptor(),
488 bool ignore_override =
false);
494 template<
typename ParameterT>
497 const std::string & name,
498 const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
499 rcl_interfaces::msg::ParameterDescriptor(),
500 bool ignore_override =
false);
549 template<
typename ParameterT>
550 std::vector<ParameterT>
552 const std::string & namespace_,
553 const std::map<std::string, ParameterT> & parameters,
554 bool ignore_overrides =
false);
563 template<
typename ParameterT>
564 std::vector<ParameterT>
566 const std::string & namespace_,
569 std::pair<ParameterT, rcl_interfaces::msg::ParameterDescriptor>
571 bool ignore_overrides =
false);
641 rcl_interfaces::msg::SetParametersResult
693 std::vector<rcl_interfaces::msg::SetParametersResult>
694 set_parameters(
const std::vector<rclcpp::Parameter> & parameters);
741 rcl_interfaces::msg::SetParametersResult
800 template<
typename ParameterT>
802 get_parameter(
const std::string & name, ParameterT & parameter)
const;
819 template<
typename ParameterT>
822 const std::string & name,
823 ParameterT & parameter,
824 const ParameterT & alternative_value)
const;
838 template<
typename ParameterT>
841 const std::string & name,
842 const ParameterT & alternative_value)
const;
865 std::vector<rclcpp::Parameter>
905 template<
typename ParameterT>
908 const std::string & prefix,
909 std::map<std::string, ParameterT> & values)
const;
929 rcl_interfaces::msg::ParameterDescriptor
952 std::vector<rcl_interfaces::msg::ParameterDescriptor>
989 rcl_interfaces::msg::ListParametersResult
990 list_parameters(
const std::vector<std::string> & prefixes, uint64_t depth)
const;
994 using PreSetParametersCallbackType =
995 rclcpp::node_interfaces::NodeParametersInterface::PreSetParametersCallbackType;
999 using OnSetParametersCallbackType =
1000 rclcpp::node_interfaces::NodeParametersInterface::OnSetParametersCallbackType;
1004 using PostSetParametersCallbackType =
1005 rclcpp::node_interfaces::NodeParametersInterface::PostSetParametersCallbackType;
1065 PreSetParametersCallbackHandle::SharedPtr
1139 OnSetParametersCallbackHandle::SharedPtr
1200 PostSetParametersCallbackHandle::SharedPtr
1260 std::vector<std::string>
1269 std::map<std::string, std::vector<std::string>>
1278 std::map<std::string, std::vector<std::string>>
1292 std::map<std::string, std::vector<std::string>>
1294 const std::string & node_name,
1295 const std::string & namespace_)
const;
1360 std::vector<rclcpp::TopicEndpointInfo>
1386 std::vector<rclcpp::TopicEndpointInfo>
1416 std::vector<rclcpp::ServiceEndpointInfo>
1446 std::vector<rclcpp::ServiceEndpointInfo>
1455 rclcpp::Event::SharedPtr
1472 const rclcpp::Event::SharedPtr & event,
1473 std::chrono::nanoseconds timeout);
1480 rclcpp::Clock::SharedPtr
1488 rclcpp::Clock::ConstSharedPtr
1501 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
1506 rclcpp::node_interfaces::NodeClockInterface::SharedPtr
1511 rclcpp::node_interfaces::NodeGraphInterface::SharedPtr
1516 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr
1521 rclcpp::node_interfaces::NodeTimersInterface::SharedPtr
1526 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr
1531 rclcpp::node_interfaces::NodeServicesInterface::SharedPtr
1536 rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr
1541 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr
1546 rclcpp::node_interfaces::NodeTimeSourceInterface::SharedPtr
1551 rclcpp::node_interfaces::NodeTypeDescriptionsInterface::SharedPtr
1657 rclcpp::Node::SharedPtr
1676 const std::string & sub_namespace);
1679 RCLCPP_DISABLE_COPY(
Node)
1681 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_;
1682 rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_;
1683 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_;
1684 rclcpp::node_interfaces::NodeTimersInterface::SharedPtr node_timers_;
1685 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_;
1686 rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_;
1687 rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock_;
1688 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters_;
1689 rclcpp::node_interfaces::NodeTimeSourceInterface::SharedPtr node_time_source_;
1690 rclcpp::node_interfaces::NodeTypeDescriptionsInterface::SharedPtr node_type_descriptions_;
1691 rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr node_waitables_;
1694 const std::string sub_namespace_;
1695 const std::string effective_namespace_;
1701 std::shared_ptr<NodeImpl> hidden_impl_{
nullptr};
1706 #ifndef RCLCPP__NODE_IMPL_HPP_
1708 #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.