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

One-shot subscriber interface that receives a single message from a topic, then cleans up. More...

#include <subscriber_interface.hpp>

Inheritance diagram for moveit_pro::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_pro::behaviors::SubscriberInterface< MessageT >

One-shot subscriber interface that receives a single message from a topic, then cleans up.

Lifecycle:

  1. initialize() — creates the subscription and optionally waits for a publisher.
  2. syncGetNextMessage() — blocks until the subscription callback fires (or times out). Returns the message.
  3. On message receipt, the subscription is destroyed to avoid processing further messages.

Thread safety: initialize() and syncGetNextMessage() must be called synchronously from the same thread. halt() can be called from a separate thread (e.g., the Behavior Tree executor) to cancel a blocking wait.

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_pro::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_pro::behaviors::RclcppSubscriberInterface< MessageT >.

◆ halt()

Called to stop any long running processes.

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

◆ initialize()

template<typename MessageT >
virtual tl::expected< void, std::string > moveit_pro::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_pro::behaviors::RclcppSubscriberInterface< MessageT >.

◆ syncGetNextMessage()

template<typename MessageT >
virtual tl::expected< MessageT, std::string > moveit_pro::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_pro::behaviors::RclcppSubscriberInterface< MessageT >.


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