2#ifndef PUBLISHER_HANDLER_HPP
3#define PUBLISHER_HANDLER_HPP
16 template <
class TopicType>
20 last_time_published_ = rclcpp::Time(0, 0, node_->get_clock()->get_clock_type());
27 template <
class TopicType>
33 last_time_published_ = node_->get_clock()->now();
36 std::scoped_lock lock(mutex_publisher_);
39 publisher_ = node_->create_publisher<TopicType>(address, options.qos);
40 RCLCPP_INFO(node_->get_logger(),
" Created publisher on topic '%s' -> '%s'", address.c_str(), publisher_->get_topic_name());
46 this->throttle_ =
true;
49 publisher_initialized_ =
true;
56 template <
class TopicType>
60 if (!publisher_initialized_)
66 std::scoped_lock lock(mutex_publisher_);
68 rclcpp::Time now = node_->get_clock()->now();
70 if (throttle_min_dt_ > 0)
73 double passed = (now - last_time_published_).seconds();
75 if (passed < throttle_min_dt_)
81 publisher_->publish(msg);
83 last_time_published_ = now;
91 template <
class TopicType>
95 if (!publisher_initialized_)
101 std::scoped_lock lock(mutex_publisher_);
103 rclcpp::Time now = node_->get_clock()->now();
105 if (throttle_min_dt_ > 0)
108 double passed = (now - last_time_published_).seconds();
110 if (passed < throttle_min_dt_)
116 publisher_->publish(msg);
118 last_time_published_ = now;
126 template <
class TopicType>
130 if (!publisher_initialized_)
136 std::scoped_lock lock(mutex_publisher_);
138 rclcpp::Time now = node_->get_clock()->now();
140 if (throttle_min_dt_ > 0)
143 double passed = (now - last_time_published_).seconds();
145 if (passed < throttle_min_dt_)
151 publisher_->publish(msg);
153 last_time_published_ = now;
161 template <
class TopicType>
166 std::scoped_lock lock(mutex_publisher_);
168 return publisher_->get_subscription_count();
180 template <
class TopicType>
191 this->impl_ = other.impl_;
201 template <
class TopicType>
207 this->impl_ = other.impl_;
215 template <
class TopicType>
223 impl_ = std::make_shared<PublisherHandler_impl<TopicType>>(opts, address);
230 template <
class TopicType>
234 impl_ = std::make_shared<PublisherHandler_impl<TopicType>>(options, address);
241 template <
class TopicType>
252 template <
class TopicType>
273 template <
class TopicType>
284 template <
class TopicType>
288 return impl_->getNumSubscribers();
unsigned int getNumSubscribers(void)
get number of subscribers
Definition publisher_handler.hpp:162
void publish(const TopicType &msg)
publish message
Definition publisher_handler.hpp:57
PublisherHandler_impl(void)
default constructor
Definition publisher_handler.hpp:17
user wrapper of the publisher handler implementation
Definition publisher_handler.h:130
void publish(const TopicType &msg)
publish message
Definition publisher_handler.hpp:242
PublisherHandler & operator=(const PublisherHandler &other)
operator=
Definition publisher_handler.hpp:181
unsigned int getNumSubscribers(void)
get number of subscribers
Definition publisher_handler.hpp:285
PublisherHandler(void)
generic constructor
Definition publisher_handler.h:136
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:35