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();
181 template <
class TopicType>
185 std::scoped_lock lock(mutex_publisher_);
187 return publisher_->get_topic_name();
198 template <
class TopicType>
209 this->impl_ = other.impl_;
219 template <
class TopicType>
225 this->impl_ = other.impl_;
233 template <
class TopicType>
241 impl_ = std::make_shared<PublisherHandler_impl<TopicType>>(opts, address);
248 template <
class TopicType>
252 impl_ = std::make_shared<PublisherHandler_impl<TopicType>>(options, address);
259 template <
class TopicType>
272 template <
class TopicType>
296 template <
class TopicType>
310 template <
class TopicType>
316 impl_->publish(std::move(msg));
323 template <
class TopicType>
329 return impl_->getNumSubscribers();
336 template <
class TopicType>
342 return impl_->topicName();
void publish(const TopicType &msg)
publish message
Definition publisher_handler.hpp:52
unsigned int getNumSubscribers(void) const
get number of subscribers
Definition publisher_handler.hpp:167
std::string topicName(void) const
get the resolved name of the topic
Definition publisher_handler.hpp:182
PublisherHandler_impl(void)
default constructor
Definition publisher_handler.hpp:17
void publish(const TopicType &msg)
publish message
Definition publisher_handler.hpp:260
PublisherHandler & operator=(const PublisherHandler &other)
operator=
Definition publisher_handler.hpp:199
std::string topicName(void) const
get the resolved name of the topic
Definition publisher_handler.hpp:337
unsigned int getNumSubscribers(void) const
get number of subscribers
Definition publisher_handler.hpp:324
PublisherHandler(void)
generic constructor
Definition publisher_handler.h:156
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:27
double throttle_rate
when > 0, the publisher output is limited to this rate in [Hz]
Definition publisher_handler.h:39