Set Parameter Event Publisher settings #591 (#614)

* Add ability to disable Parameter Event Publisher and change its QoS settings

Signed-off-by: RARvolt <rarvolt@gmail.com>

* address review comments

Signed-off-by: William Woodall <william@osrfoundation.org>

* use NodeOptions struct

Signed-off-by: William Woodall <william@osrfoundation.org>

* remove vestigial doc strings and improve docs

Signed-off-by: William Woodall <william@osrfoundation.org>

* fix lifecycle node constructor

Signed-off-by: William Woodall <william@osrfoundation.org>
This commit is contained in:
rarvolt 2019-02-07 08:04:53 +01:00 committed by William Woodall
parent 0f9098e9b6
commit 4046563de6
6 changed files with 118 additions and 13 deletions

View file

@ -54,7 +54,9 @@ public:
const node_interfaces::NodeClockInterface::SharedPtr node_clock,
const std::vector<Parameter> & 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

View file

@ -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<rclcpp::Parameter> & 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()};
};

View file

@ -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_,

View file

@ -39,8 +39,10 @@ NodeParameters::NodeParameters(
const rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock,
const std::vector<rclcpp::Parameter> & 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<MessageT>;
@ -52,12 +54,14 @@ NodeParameters::NodeParameters(
parameter_service_ = std::make_shared<ParameterService>(node_base, node_services, this);
}
if (start_parameter_event_publisher) {
events_publisher_ = rclcpp::create_publisher<MessageT, AllocatorT, PublisherT>(
node_topics.get(),
"parameter_events",
rmw_qos_profile_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_);
// 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;
}

View file

@ -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
{

View file

@ -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()),