MoveIt Pro API
Core Behaviors for MoveIt Pro
Loading...
Searching...
No Matches
moveit_studio::behaviors::SubscriberInterface< MessageT > Class Template Referenceabstract

Interface for subscribers that can block while waiting for a message to be received on a topic. More...

#include <subscriber_interface.hpp>

Inheritance diagram for moveit_studio::behaviors::SubscriberInterface< MessageT >:

Public Member Functions

virtual ~SubscriberInterface ()=default
 
virtual tl::expected< void, std::string > initialize (const std::string &topic_name, const std::chrono::duration< double > &wait_for_message_timeout, const std::chrono::duration< double > &wait_for_publisher_timeout, bool bypass_qos_negotiation=false)=0
 Initialize the subscriber interface.
 
virtual std::future< tl::expected< MessageT, std::string > > getNextMessage ()=0
 Get a future for the next message through the subscriber interface.
 
virtual tl::expected< MessageT, std::string > syncGetNextMessage ()=0
 Get the next message through the subscriber interface (blocking).
 
virtual void halt ()=0
 Called to stop any long running processes.
 

Detailed Description

template<typename MessageT>
class moveit_studio::behaviors::SubscriberInterface< MessageT >

Interface for subscribers that can block while waiting for a message to be received on a topic.

This interface is designed to be thread-compatible: initialize() and syncGetNextMessage() must be called synchronously, however halt() can be called from a separate thread. This interface can be easily mocked for testing to avoid needing to spin ROS nodes in tests.

Template Parameters
MessageTROS message type used to specialize this interface.

Constructor & Destructor Documentation

◆ ~SubscriberInterface()

Member Function Documentation

◆ getNextMessage()

template<typename MessageT >
virtual std::future< tl::expected< MessageT, std::string > > moveit_studio::behaviors::SubscriberInterface< MessageT >::getNextMessage ( )
pure virtual

Get a future for the next message through the subscriber interface.

Returns
A future that will contain the message when it's received, or an error result if the message could not be received.

Implemented in moveit_studio::behaviors::RclcppSubscriberInterface< MessageT >.

◆ halt()

Called to stop any long running processes.

Implemented in moveit_studio::behaviors::RclcppSubscriberInterface< MessageT >.

◆ initialize()

template<typename MessageT >
virtual tl::expected< void, std::string > moveit_studio::behaviors::SubscriberInterface< MessageT >::initialize ( const std::string &  topic_name,
const std::chrono::duration< double > &  wait_for_message_timeout,
const std::chrono::duration< double > &  wait_for_publisher_timeout,
bool  bypass_qos_negotiation = false 
)
pure virtual

Initialize the subscriber interface.

Parameters
topic_nameName of the topic to use in the subscriber interface.
wait_for_message_timeoutMessage timeout duration to use in the subscriber interface.
wait_for_publisher_timeoutPublisher timeout duration to use in the subscriber interface.
bypass_qos_negotiationIf true, use default QoS instead of negotiating with publisher.
Returns
Void if the subscriber interface was initialized successfully, or an error result if it could not be initialized successfully.

Implemented in moveit_studio::behaviors::RclcppSubscriberInterface< MessageT >.

◆ syncGetNextMessage()

template<typename MessageT >
virtual tl::expected< MessageT, std::string > moveit_studio::behaviors::SubscriberInterface< MessageT >::syncGetNextMessage ( )
pure virtual

Get the next message through the subscriber interface (blocking).

Returns
The message, if it was successfully received, or an error result if the message could not be received.

Implemented in moveit_studio::behaviors::RclcppSubscriberInterface< MessageT >.


The documentation for this class was generated from the following file: