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>
21#include <mrs_lib/internal/rate_throttle.hpp>
26 struct PublisherHandlerOptions
28 PublisherHandlerOptions(
const rclcpp::Node::SharedPtr& node) : node(node)
32 PublisherHandlerOptions() =
default;
34 rclcpp::Node::SharedPtr node;
41 rclcpp::QoS qos = rclcpp::SystemDefaultsQoS();
49 template <
class TopicType>
78 void publish(
const TopicType& msg);
85 void publish(
const std::shared_ptr<TopicType>& msg);
99 void publish(
typename TopicType::ConstSharedPtr msg);
106 void publish(std::unique_ptr<TopicType> msg);
123 rclcpp::Node::SharedPtr node_;
125 std::shared_ptr<rclcpp::Publisher<TopicType>> publisher_;
127 mutable std::mutex mutex_publisher_;
129 std::atomic<bool> publisher_initialized_;
131 std::string address_;
133 std::optional<internal::RateThrottle> throttle_;
138 bool throttleAccept(
void);
148 template <
class TopicType>
185 PublisherHandler(
const rclcpp::Node::SharedPtr& node,
const std::string& address);
200 void publish(
const TopicType& msg);
207 void publish(
const std::shared_ptr<TopicType>& msg);
221 void publish(
typename TopicType::ConstSharedPtr msg);
228 void publish(std::unique_ptr<TopicType> msg);
245 std::shared_ptr<PublisherHandler_impl<TopicType>> impl_;
252#ifndef PUBLISHER_HANDLER_HPP
253#include <mrs_lib/impl/publisher_handler.hpp>
void publish(const TopicType &msg)
publish message
Definition publisher_handler.hpp:52
~PublisherHandler_impl(void)
default destructor
Definition publisher_handler.h:62
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
user wrapper of the publisher handler implementation
Definition publisher_handler.h:150
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 destructor
Definition publisher_handler.h:161
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
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