1#ifndef MRS_LIB_SUBSCRIBER_HPP_
2#define MRS_LIB_SUBSCRIBER_HPP_
10#include <rclcpp/callback_group.hpp>
11#include <rclcpp/node_interfaces/node_base_interface.hpp>
12#include <rclcpp/node_interfaces/node_clock_interface.hpp>
13#include <rclcpp/node_interfaces/node_interfaces.hpp>
14#include <rclcpp/node_interfaces/node_logging_interface.hpp>
15#include <rclcpp/node_interfaces/node_parameters_interface.hpp>
16#include <rclcpp/node_interfaces/node_timers_interface.hpp>
17#include <rclcpp/node_interfaces/node_topics_interface.hpp>
19#include "mrs_lib/timeout_manager.hpp"
31 rclcpp::node_interfaces::NodeInterfaces<rclcpp::node_interfaces::NodeBaseInterface, rclcpp::node_interfaces::NodeTimersInterface,
32 rclcpp::node_interfaces::NodeClockInterface, rclcpp::node_interfaces::NodeLoggingInterface,
33 rclcpp::node_interfaces::NodeParametersInterface, rclcpp::node_interfaces::NodeTopicsInterface>;
44 rclcpp::QoS
qos = rclcpp::SystemDefaultsQoS();
61 std::function<void(std::string_view topic_name, rclcpp::Time last_msg)>
timeout_callback = {};
76 template <
typename MessageType>
123 [[nodiscard]] std::optional<std::shared_ptr<const MessageType>>
get_message();
137 [[nodiscard]] std::optional<std::shared_ptr<const MessageType>>
get_new_message();
146 [[nodiscard]] std::optional<std::shared_ptr<const MessageType>>
peek_message()
const;
160 [[nodiscard]] std::optional<std::shared_ptr<const MessageType>>
peek_new_message()
const;
197#ifndef MRS_LIB_SUBSCRIBER_IMPL_HPP_
198#include "mrs_lib/subscriber.impl.hpp"
Base template for CoroCallback.
Definition callback.hpp:166
Owning pointer wrapper with move only value semantics. Usefull for implementing the pointer to implem...
Definition pimpl.hpp:39
Subscriber(const SubscriberOptions &options, std::string_view topic_name, MessageCallback callback)
Construct a Subscriber with the specified callback.
Definition subscriber.impl.hpp:252
uint32_t get_publisher_count() const
Returns number of publishers registered at the topic.
Definition subscriber.impl.hpp:312
std::optional< std::shared_ptr< const MessageType > > get_new_message()
Get the latest new message, if there is one.
Definition subscriber.impl.hpp:276
std::string get_unresolved_topic_name() const
Returns the unresolved name of the topic handled by this Subscriber.
Definition subscriber.impl.hpp:306
std::optional< std::shared_ptr< const MessageType > > peek_new_message() const
Get the latest new message, if there is one.
Definition subscriber.impl.hpp:288
std::optional< std::shared_ptr< const MessageType > > peek_message() const
Get the latest received message, if there is one.
Definition subscriber.impl.hpp:282
std::function< void(std::shared_ptr< const MessageType >)> MessageCallback
Type of the accepted callback.
Definition subscriber.hpp:84
CoroCallback< void(std::shared_ptr< const MessageType >)> MessageCoroCallback
Type of the accepted coroutine callback.
Definition subscriber.hpp:87
std::optional< std::shared_ptr< const MessageType > > get_message()
Get the latest received message, if there is one.
Definition subscriber.impl.hpp:270
rclcpp::Time get_last_message_time() const
Returns time of the last received message on the topic, handled by this Subscriber.
Definition subscriber.impl.hpp:294
std::string get_topic_name() const
Returns the resolved (full) name of the topic handled by this Subscriber.
Definition subscriber.impl.hpp:300
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::NodeBaseInterface, rclcpp::node_interfaces::NodeTimersInterface, rclcpp::node_interfaces::NodeClockInterface, rclcpp::node_interfaces::NodeLoggingInterface, rclcpp::node_interfaces::NodeParametersInterface, rclcpp::node_interfaces::NodeTopicsInterface > SubscriberNodeInterfaces
ROS node interfaces required by the Subscriber.
Definition subscriber.hpp:30
Tag for explicitly marking Subscriber that has no callback.
Definition subscriber.hpp:68
Options for configuring the Subscriber.
Definition subscriber.hpp:39
SubscriberNodeInterfaces node_interfaces
ROS node interfaces used by the subscriber.
Definition subscriber.hpp:41
std::optional< std::chrono::nanoseconds > no_message_timeout
Time after which timeout callback is called if no message is received.
Definition subscriber.hpp:49
std::function< void(std::string_view topic_name, rclcpp::Time last_msg)> timeout_callback
Timeout manager used for the no message timeout.
Definition subscriber.hpp:61
std::shared_ptr< rclcpp::CallbackGroup > callback_group
ROS callback group used by the subscriber callbacks.
Definition subscriber.hpp:46
std::shared_ptr< mrs_lib::TimeoutManager2 > timeout_manager
Timeout manager used for the no message timeout.
Definition subscriber.hpp:55
rclcpp::QoS qos
QOS settings for the subscriber.
Definition subscriber.hpp:44