mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
publisher.hpp
1#ifndef MRS_LIB_PUBLISHER_HPP_
2#define MRS_LIB_PUBLISHER_HPP_
3
4
5#include <chrono>
6#include <memory>
7#include <optional>
8#include <string>
9#include <string_view>
10
11#include <rclcpp/node_interfaces/node_clock_interface.hpp>
12#include <rclcpp/node_interfaces/node_interfaces.hpp>
13#include <rclcpp/node_interfaces/node_logging_interface.hpp>
14#include <rclcpp/node_interfaces/node_topics_interface.hpp>
15
17
18
19namespace mrs_lib
20{
21
26 rclcpp::node_interfaces::NodeInterfaces<rclcpp::node_interfaces::NodeTopicsInterface, rclcpp::node_interfaces::NodeClockInterface,
27 rclcpp::node_interfaces::NodeLoggingInterface>;
28
29
31 {
35 rclcpp::QoS qos = rclcpp::SystemDefaultsQoS();
36
38 std::optional<std::chrono::nanoseconds> throttle_duration = std::nullopt;
39 };
40
46 template <class MessageType>
48 {
49 private:
50 class Impl;
51
52 public:
59 Publisher(const PublisherOptions& options, std::string_view topic_name);
60
66 void publish(const MessageType& msg);
67
73 void publish(std::unique_ptr<MessageType> msg);
74
80 [[nodiscard]] std::string get_topic_name() const;
81
87 [[nodiscard]] std::string get_unresolved_topic_name() const;
88
94 [[nodiscard]] size_t get_subscriber_count() const;
95
96 private:
97 Pimpl<Impl> impl_;
98 };
99
100} // namespace mrs_lib
101
102#ifndef MRS_LIB_PUBLISHER_IMPL_HPP_
103#include "mrs_lib/publisher.impl.hpp"
104#endif
105
106#endif // MRS_LIB_PUBLISHER_HPP_
Owning pointer wrapper with move only value semantics. Usefull for implementing the pointer to implem...
Definition pimpl.hpp:39
void publish(const MessageType &msg)
Publish a message.
Definition publisher.impl.hpp:123
std::string get_unresolved_topic_name() const
Returns the unresolved name of the topic handled by this publisher.
Definition publisher.impl.hpp:141
std::string get_topic_name() const
Returns the resolved (full) name of the topic handled by this publisher.
Definition publisher.impl.hpp:135
size_t get_subscriber_count() const
Get number of subscribers on the published topic.
Definition publisher.impl.hpp:147
Publisher(const PublisherOptions &options, std::string_view topic_name)
construct a publisher using the specified options.
Definition publisher.impl.hpp:118
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition attitude_converter.h:24
rclcpp::node_interfaces::NodeInterfaces< rclcpp::node_interfaces::NodeTopicsInterface, rclcpp::node_interfaces::NodeClockInterface, rclcpp::node_interfaces::NodeLoggingInterface > PublisherNodeInterfaces
ROS node interfaces required by the Publisher.
Definition publisher.hpp:25
Definition publisher.hpp:31
rclcpp::QoS qos
QOS settings for the publisher.
Definition publisher.hpp:35
PublisherNodeInterfaces node_interfaces
ROS node interfaces used by the publisher.
Definition publisher.hpp:33
std::optional< std::chrono::nanoseconds > throttle_duration
If set, the publisher drops messages so that the average output rate does not exceed 1/throttle_durat...
Definition publisher.hpp:38