6#ifndef PUBLISHER_HANDLER_H
7#define PUBLISHER_HANDLER_H
11#include <rclcpp/rclcpp.hpp>
12#include <rclcpp/node.hpp>
13#include <rclcpp/time_source.hpp>
20#include <mrs_lib/internal/rate_throttle.hpp>
25 struct PublisherHandlerOptions
27 PublisherHandlerOptions(
const rclcpp::Node::SharedPtr& node) : node(node)
31 PublisherHandlerOptions() =
default;
33 rclcpp::Node::SharedPtr node;
40 rclcpp::QoS qos = rclcpp::SystemDefaultsQoS();
48 template <
class TopicType>
77 void publish(
const TopicType& msg);
84 void publish(
const std::shared_ptr<TopicType>& msg);
98 void publish(
typename TopicType::ConstSharedPtr msg);
105 void publish(std::unique_ptr<TopicType> msg);
115 rclcpp::Node::SharedPtr node_;
117 std::shared_ptr<rclcpp::Publisher<TopicType>> publisher_;
119 std::mutex mutex_publisher_;
121 std::atomic<bool> publisher_initialized_;
123 std::string address_;
125 std::optional<internal::RateThrottle> throttle_;
130 bool throttleAccept(
void);
140 template <
class TopicType>
177 PublisherHandler(
const rclcpp::Node::SharedPtr& node,
const std::string& address);
192 void publish(
const TopicType& msg);
199 void publish(
const std::shared_ptr<TopicType>& msg);
213 void publish(
typename TopicType::ConstSharedPtr msg);
220 void publish(std::unique_ptr<TopicType> msg);
230 std::shared_ptr<PublisherHandler_impl<TopicType>> impl_;
237#ifndef PUBLISHER_HANDLER_HPP
238#include <mrs_lib/impl/publisher_handler.hpp>
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 destructor
Definition publisher_handler.h:61
PublisherHandler_impl(void)
default constructor
Definition publisher_handler.hpp:17
user wrapper of the publisher handler implementation
Definition publisher_handler.h:142
void publish(const TopicType &msg)
publish message
Definition publisher_handler.hpp:247
PublisherHandler & operator=(const PublisherHandler &other)
operator=
Definition publisher_handler.hpp:186
~PublisherHandler(void)
generic destructor
Definition publisher_handler.h:153
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
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