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);
45 this->throttle_ =
true;
48 publisher_initialized_ =
true;
55 template <
class TopicType>
59 if (!publisher_initialized_)
65 std::scoped_lock lock(mutex_publisher_);
67 rclcpp::Time now = node_->get_clock()->now();
69 if (throttle_min_dt_ > 0)
72 double passed = (now - last_time_published_).seconds();
74 if (passed < throttle_min_dt_)
80 publisher_->publish(msg);
82 last_time_published_ = now;
90 template <
class TopicType>
94 if (!publisher_initialized_)
100 std::scoped_lock lock(mutex_publisher_);
102 rclcpp::Time now = node_->get_clock()->now();
104 if (throttle_min_dt_ > 0)
107 double passed = (now - last_time_published_).seconds();
109 if (passed < throttle_min_dt_)
115 publisher_->publish(msg);
117 last_time_published_ = now;
125 template <
class TopicType>
129 if (!publisher_initialized_)
135 std::scoped_lock lock(mutex_publisher_);
137 rclcpp::Time now = node_->get_clock()->now();
139 if (throttle_min_dt_ > 0)
142 double passed = (now - last_time_published_).seconds();
144 if (passed < throttle_min_dt_)
150 publisher_->publish(msg);
152 last_time_published_ = now;
160 template <
class TopicType>
165 std::scoped_lock lock(mutex_publisher_);
167 return publisher_->get_subscription_count();
179 template <
class TopicType>
190 this->impl_ = other.impl_;
200 template <
class TopicType>
206 this->impl_ = other.impl_;
214 template <
class TopicType>
222 impl_ = std::make_shared<PublisherHandler_impl<TopicType>>(opts, address);
229 template <
class TopicType>
233 impl_ = std::make_shared<PublisherHandler_impl<TopicType>>(options, address);
240 template <
class TopicType>
251 template <
class TopicType>
272 template <
class TopicType>
283 template <
class TopicType>
287 return impl_->getNumSubscribers();
unsigned int getNumSubscribers(void)
get number of subscribers
Definition publisher_handler.hpp:161
void publish(const TopicType &msg)
publish message
Definition publisher_handler.hpp:56
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:241
PublisherHandler & operator=(const PublisherHandler &other)
operator=
Definition publisher_handler.hpp:180
unsigned int getNumSubscribers(void)
get number of subscribers
Definition publisher_handler.hpp:284
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