2#ifndef PUBLISHER_HANDLER_HPP
3#define PUBLISHER_HANDLER_HPP
16 template <
class TopicType>
25 template <
class TopicType>
32 std::scoped_lock lock(mutex_publisher_);
35 publisher_ = node_->create_publisher<TopicType>(address, options.qos);
36 RCLCPP_INFO(node_->get_logger(),
" Created publisher on topic '%s' -> '%s'", address.c_str(), publisher_->get_topic_name());
44 publisher_initialized_ =
true;
51 template <
class TopicType>
55 if (!publisher_initialized_)
61 std::scoped_lock lock(mutex_publisher_);
63 if (!throttleAccept())
68 publisher_->publish(msg);
76 template <
class TopicType>
80 if (!publisher_initialized_)
86 std::scoped_lock lock(mutex_publisher_);
88 if (!throttleAccept())
93 publisher_->publish(msg);
101 template <
class TopicType>
105 if (!publisher_initialized_)
111 std::scoped_lock lock(mutex_publisher_);
113 if (!throttleAccept())
118 publisher_->publish(msg);
126 template <
class TopicType>
129 if (!publisher_initialized_)
135 std::scoped_lock lock(mutex_publisher_);
137 if (!throttleAccept())
142 publisher_->publish(std::move(msg));
150 template <
class TopicType>
151 bool PublisherHandler_impl<TopicType>::throttleAccept(
void)
159 return throttle_->accept(node_->get_clock()->now());
166 template <
class TopicType>
171 std::scoped_lock lock(mutex_publisher_);
173 return publisher_->get_subscription_count();
185 template <
class TopicType>
196 this->impl_ = other.impl_;
206 template <
class TopicType>
212 this->impl_ = other.impl_;
220 template <
class TopicType>
228 impl_ = std::make_shared<PublisherHandler_impl<TopicType>>(opts, address);
235 template <
class TopicType>
239 impl_ = std::make_shared<PublisherHandler_impl<TopicType>>(options, address);
246 template <
class TopicType>
257 template <
class TopicType>
279 template <
class TopicType>
291 template <
class TopicType>
295 impl_->publish(std::move(msg));
302 template <
class TopicType>
306 return impl_->getNumSubscribers();
unsigned int getNumSubscribers(void)
get number of subscribers
Definition publisher_handler.hpp:167
void publish(const TopicType &msg)
publish message
Definition publisher_handler.hpp:52
PublisherHandler_impl(void)
default constructor
Definition publisher_handler.hpp:17
void publish(const TopicType &msg)
publish message
Definition publisher_handler.hpp:247
PublisherHandler & operator=(const PublisherHandler &other)
operator=
Definition publisher_handler.hpp:186
unsigned int getNumSubscribers(void)
get number of subscribers
Definition publisher_handler.hpp:303
PublisherHandler(void)
generic constructor
Definition publisher_handler.h:148
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:26
double throttle_rate
when > 0, the publisher output is limited to this rate in [Hz]
Definition publisher_handler.h:38