diff --git a/rclcpp/include/rclcpp/node_interfaces/node_parameters.hpp b/rclcpp/include/rclcpp/node_interfaces/node_parameters.hpp index ca4ada9..31bbb44 100644 --- a/rclcpp/include/rclcpp/node_interfaces/node_parameters.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/node_parameters.hpp @@ -54,7 +54,9 @@ public: const node_interfaces::NodeClockInterface::SharedPtr node_clock, const std::vector & initial_parameters, bool use_intra_process, - bool start_parameter_services); + bool start_parameter_services, + bool start_parameter_event_publisher, + const rmw_qos_profile_t & parameter_event_qos_profile); RCLCPP_PUBLIC virtual diff --git a/rclcpp/include/rclcpp/node_options.hpp b/rclcpp/include/rclcpp/node_options.hpp index dc72b40..0087985 100644 --- a/rclcpp/include/rclcpp/node_options.hpp +++ b/rclcpp/include/rclcpp/node_options.hpp @@ -42,6 +42,8 @@ public: * - use_global_arguments = true * - use_intra_process_comms = false * - start_parameter_services = true + * - start_parameter_event_publisher = true + * - parameter_event_qos_profile = rmw_qos_profile_parameter_events * - allocator = rcl_get_default_allocator() * * \param[in] allocator allocator to use in construction of NodeOptions. @@ -90,6 +92,9 @@ public: /// Set the arguments, return this for parameter idiom. /** + * These arguments are used to extract remappings used by the node and other + * settings. + * * This will cause the internal rcl_node_options_t struct to be invalidated. */ RCLCPP_PUBLIC @@ -106,6 +111,11 @@ public: initial_parameters() const; /// Set the initial parameters, return this for parameter idiom. + /** + * These initial parameter values are used to change the initial value + * of declared parameters within the node, overriding hard coded default + * values if necessary. + */ RCLCPP_PUBLIC NodeOptions & initial_parameters(const std::vector & initial_parameters); @@ -126,6 +136,10 @@ public: /// Set the use_global_arguments flag, return this for parameter idiom. /** + * If true this will cause the node's behavior to be influenced by "global" + * arguments, i.e. arguments not targeted at specific nodes, as well as the + * arguments targeted at the current node. + * * This will cause the internal rcl_node_options_t struct to be invalidated. */ RCLCPP_PUBLIC @@ -138,6 +152,15 @@ public: use_intra_process_comms() const; /// Set the use_intra_process_comms flag, return this for parameter idiom. + /** + * If true, messages on topics which are published and subscribed to within + * this context will go through a special intra-process communication code + * code path which can avoid serialization and deserialization, unnecessary + * copies, and achieve lower latencies in some cases. + * + * Defaults to false for now, as there are still some cases where it is not + * desirable. + */ RCLCPP_PUBLIC NodeOptions & use_intra_process_comms(const bool & use_intra_process_comms); @@ -148,10 +171,48 @@ public: start_parameter_services() const; /// Set the start_parameter_services flag, return this for parameter idiom. + /** + * If true, ROS services are created to allow external nodes to list, get, + * and request to set parameters of this node. + * + * If false, parameters will still work locally, but will not be accessible + * remotely. + * + * \sa start_parameter_event_publisher() + */ RCLCPP_PUBLIC NodeOptions & start_parameter_services(const bool & start_parameter_services); + /// Return a reference to the start_parameter_event_publisher flag. + RCLCPP_PUBLIC + const bool & + start_parameter_event_publisher() const; + + /// Set the start_parameter_event_publisher flag, return this for parameter idiom. + /** + * If true, a publisher is created on which an event message is published + * each time a parameter's state changes. + * This is used for recording and introspection, but is configurable + * separately from the other parameter services. + */ + RCLCPP_PUBLIC + NodeOptions & + start_parameter_event_publisher(const bool & start_parameter_event_publisher); + + /// Return a reference to the parameter_event_qos_profile QoS. + RCLCPP_PUBLIC + const rmw_qos_profile_t & + parameter_event_qos_profile() const; + + /// Set the parameter_event_qos_profile QoS, return this for parameter idiom. + /** + * The QoS settings to be used for the parameter event publisher, if enabled. + */ + RCLCPP_PUBLIC + NodeOptions & + parameter_event_qos_profile(const rmw_qos_profile_t & parameter_event_qos_profile); + /// Return the rcl_allocator_t to be used. RCLCPP_PUBLIC const rcl_allocator_t & @@ -191,6 +252,10 @@ private: bool start_parameter_services_ {true}; + bool start_parameter_event_publisher_ {true}; + + rmw_qos_profile_t parameter_event_qos_profile_ {rmw_qos_profile_parameter_events}; + rcl_allocator_t allocator_ {rcl_get_default_allocator()}; }; diff --git a/rclcpp/src/rclcpp/node.cpp b/rclcpp/src/rclcpp/node.cpp index 6fc846d..431376c 100644 --- a/rclcpp/src/rclcpp/node.cpp +++ b/rclcpp/src/rclcpp/node.cpp @@ -70,7 +70,9 @@ Node::Node( node_clock_, options.initial_parameters(), options.use_intra_process_comms(), - options.start_parameter_services() + options.start_parameter_services(), + options.start_parameter_event_publisher(), + options.parameter_event_qos_profile() )), node_time_source_(new rclcpp::node_interfaces::NodeTimeSource( node_base_, diff --git a/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp b/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp index a893009..37588b2 100644 --- a/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp +++ b/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp @@ -39,8 +39,10 @@ NodeParameters::NodeParameters( const rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock, const std::vector & initial_parameters, bool use_intra_process, - bool start_parameter_services) -: node_clock_(node_clock) + bool start_parameter_services, + bool start_parameter_event_publisher, + const rmw_qos_profile_t & parameter_event_qos_profile) +: events_publisher_(nullptr), node_clock_(node_clock) { using MessageT = rcl_interfaces::msg::ParameterEvent; using PublisherT = rclcpp::Publisher; @@ -52,12 +54,14 @@ NodeParameters::NodeParameters( parameter_service_ = std::make_shared(node_base, node_services, this); } - events_publisher_ = rclcpp::create_publisher( - node_topics.get(), - "parameter_events", - rmw_qos_profile_parameter_events, - use_intra_process, - allocator); + if (start_parameter_event_publisher) { + events_publisher_ = rclcpp::create_publisher( + node_topics.get(), + "parameter_events", + parameter_event_qos_profile, + use_intra_process, + allocator); + } // Get the node options const rcl_node_t * node = node_base->get_rcl_node_handle(); @@ -232,8 +236,12 @@ NodeParameters::set_parameters_atomically( } std::swap(tmp_map, parameters_); - parameter_event->stamp = node_clock_->get_clock()->now(); - events_publisher_->publish(parameter_event); + + // events_publisher_ may be nullptr if it was disabled in constructor + if (nullptr != events_publisher_) { + parameter_event->stamp = node_clock_->get_clock()->now(); + events_publisher_->publish(parameter_event); + } return result; } diff --git a/rclcpp/src/rclcpp/node_options.cpp b/rclcpp/src/rclcpp/node_options.cpp index ada0cb3..570cf10 100644 --- a/rclcpp/src/rclcpp/node_options.cpp +++ b/rclcpp/src/rclcpp/node_options.cpp @@ -192,6 +192,32 @@ NodeOptions::start_parameter_services(const bool & start_parameter_services) return *this; } +const bool & +NodeOptions::start_parameter_event_publisher() const +{ + return this->start_parameter_event_publisher_; +} + +NodeOptions & +NodeOptions::start_parameter_event_publisher(const bool & start_parameter_event_publisher) +{ + this->start_parameter_event_publisher_ = start_parameter_event_publisher; + return *this; +} + +const rmw_qos_profile_t & +NodeOptions::parameter_event_qos_profile() const +{ + return this->parameter_event_qos_profile_; +} + +NodeOptions & +NodeOptions::parameter_event_qos_profile(const rmw_qos_profile_t & parameter_event_qos_profile) +{ + this->parameter_event_qos_profile_ = parameter_event_qos_profile; + return *this; +} + const rcl_allocator_t & NodeOptions::allocator() const { diff --git a/rclcpp_lifecycle/src/lifecycle_node.cpp b/rclcpp_lifecycle/src/lifecycle_node.cpp index a91fe35..95c1470 100644 --- a/rclcpp_lifecycle/src/lifecycle_node.cpp +++ b/rclcpp_lifecycle/src/lifecycle_node.cpp @@ -77,7 +77,9 @@ LifecycleNode::LifecycleNode( node_clock_, options.initial_parameters(), options.use_intra_process_comms(), - options.start_parameter_services() + options.start_parameter_services(), + options.start_parameter_event_publisher(), + options.parameter_event_qos_profile() )), node_waitables_(new rclcpp::node_interfaces::NodeWaitables(node_base_.get())), use_intra_process_comms_(options.use_intra_process_comms()),