2#ifndef PUBLISHER_HANDLER_HPP
3#define PUBLISHER_HANDLER_HPP
16template <
class TopicType>
19 last_time_published_ = rclcpp::Time(0, 0, node_->get_clock()->get_clock_type());
26template <
class TopicType>
31 last_time_published_ = node_->get_clock()->now();
34 std::scoped_lock lock(mutex_publisher_);
37 publisher_ = node_->create_publisher<TopicType>(address, options.qos);
42 this->throttle_ =
true;
45 publisher_initialized_ =
true;
52template <
class TopicType>
55 if (!publisher_initialized_) {
60 std::scoped_lock lock(mutex_publisher_);
62 rclcpp::Time now = node_->get_clock()->now();
64 if (throttle_min_dt_ > 0) {
66 double passed = (now - last_time_published_).seconds();
68 if (passed < throttle_min_dt_) {
73 publisher_->publish(msg);
75 last_time_published_ = now;
83template <
class TopicType>
86 if (!publisher_initialized_) {
91 std::scoped_lock lock(mutex_publisher_);
93 rclcpp::Time now = node_->get_clock()->now();
95 if (throttle_min_dt_ > 0) {
97 double passed = (now - last_time_published_).seconds();
99 if (passed < throttle_min_dt_) {
104 publisher_->publish(msg);
106 last_time_published_ = now;
114template <
class TopicType>
117 if (!publisher_initialized_) {
122 std::scoped_lock lock(mutex_publisher_);
124 rclcpp::Time now = node_->get_clock()->now();
126 if (throttle_min_dt_ > 0) {
128 double passed = (now - last_time_published_).seconds();
130 if (passed < throttle_min_dt_) {
135 publisher_->publish(msg);
137 last_time_published_ = now;
145template <
class TopicType>
149 std::scoped_lock lock(mutex_publisher_);
151 return publisher_.getNumSubscribers();
163template <
class TopicType>
166 if (
this == &other) {
171 this->impl_ = other.impl_;
181template <
class TopicType>
185 this->impl_ = other.impl_;
193template <
class TopicType>
200 impl_ = std::make_shared<PublisherHandler_impl<TopicType>>(opts, address);
207template <
class TopicType>
210 impl_ = std::make_shared<PublisherHandler_impl<TopicType>>(options, address);
217template <
class TopicType>
227template <
class TopicType>
247template <
class TopicType>
257template <
class TopicType>
260 return impl_->getNumSubscribers();
unsigned int getNumSubscribers(void)
get number of subscribers
Definition publisher_handler.hpp:146
void publish(const TopicType &msg)
publish message
Definition publisher_handler.hpp:53
PublisherHandler_impl(void)
default constructor
Definition publisher_handler.hpp:17
user wrapper of the publisher handler implementation
Definition publisher_handler.h:127
void publish(const TopicType &msg)
publish message
Definition publisher_handler.hpp:218
PublisherHandler & operator=(const PublisherHandler &other)
operator=
Definition publisher_handler.hpp:164
unsigned int getNumSubscribers(void)
get number of subscribers
Definition publisher_handler.hpp:258
PublisherHandler(void)
generic constructor
Definition publisher_handler.h:133
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition attitude_converter.h:24
Defines PublisherHandler and related convenience classes for upgrading the ROS publisher.
Definition publisher_handler.h:23
double throttle_rate
when > 0, the publisher output is limited to this rate in [Hz]
Definition publisher_handler.h:34