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

Implementation of the subscriber interface using rclcpp subscription. More...

#include <subscriber_interface.hpp>

Inheritance diagram for moveit_studio::behaviors::RclcppSubscriberInterface< MessageT >:
Collaboration diagram for moveit_studio::behaviors::RclcppSubscriberInterface< MessageT >:

Public Member Functions

 RclcppSubscriberInterface (const std::shared_ptr< BehaviorContext > &shared_resources)
 
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) override
 Initializes the rclcpp subscriber interface to listen on the provided topic.
 
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, std::optional< std::function< void()> > on_haltable, bool bypass_qos_negotiation=false)
 An overloaded form of initialize with an additional callback parameter that is called when the current task can be halted.
 
std::future< tl::expected< MessageT, std::string > > getNextMessage () override
 Get a future for the next message on the topic.
 
tl::expected< MessageT, std::string > syncGetNextMessage () override
 Block until a message is received on the topic.
 
void halt () override
 Stops any publisher or message checking.
 
- Public Member Functions inherited from moveit_studio::behaviors::SubscriberInterface< MessageT >
virtual ~SubscriberInterface ()=default
 

Detailed Description

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

Implementation of the subscriber interface using rclcpp subscription.

Template Parameters
MessageTROS message type used to specialize this implementation.

Constructor & Destructor Documentation

◆ RclcppSubscriberInterface()

template<typename MessageT >
moveit_studio::behaviors::RclcppSubscriberInterface< MessageT >::RclcppSubscriberInterface ( const std::shared_ptr< BehaviorContext > &  shared_resources)
explicit

Member Function Documentation

◆ getNextMessage()

template<typename MessageT >
std::future< tl::expected< MessageT, std::string > > moveit_studio::behaviors::RclcppSubscriberInterface< MessageT >::getNextMessage ( )
overridevirtual

Get a future for the next message on the topic.

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

Implements moveit_studio::behaviors::SubscriberInterface< MessageT >.

◆ halt()

Stops any publisher or message checking.

Implements moveit_studio::behaviors::SubscriberInterface< MessageT >.

◆ initialize() [1/2]

template<typename MessageT >
tl::expected< void, std::string > moveit_studio::behaviors::RclcppSubscriberInterface< 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 
)
overridevirtual

Initializes the rclcpp subscriber interface to listen on the provided topic.

By default, this blocks for a brief duration until a publisher is available on the topic. If no publisher appears before the timeout, returns an error result.

When bypass_qos_negotiation is false (default), after the publisher appears, get its current QoS settings, and set the subscriber's QoS settings to have the same reliability setting as the publisher. This ensures that the subscriber QoS always matches the publisher in situations where the same behavior may need to get messages from different sources which use different QoS settings (for example, retrieving images from a simulated camera publisher vs. a real-hardware camera driver).

When bypass_qos_negotiation is true, use default QoS settings without waiting for or negotiating with a publisher. This is useful for transient topics or situations where the publisher's presence cannot be waited for.

Parameters
topic_nameThe topic name to use when creating the subscriber.
wait_for_message_timeoutThe timeout duration to use when waiting for a message to be received on the topic.
wait_for_publisher_timeoutThe timeout duration to use when waiting for a publisher to advertise on the topic. Ignored if bypass_qos_negotiation is true.
bypass_qos_negotiationIf true, use default QoS instead of negotiating with publisher.
Returns
Void if the subscriber interface was initialized successfully. Returns an error result if no publisher appeared on the topic or the subscriber could not be created.

Implements moveit_studio::behaviors::SubscriberInterface< MessageT >.

◆ initialize() [2/2]

template<typename MessageT >
tl::expected< void, std::string > moveit_studio::behaviors::RclcppSubscriberInterface< 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,
std::optional< std::function< void()> >  on_haltable,
bool  bypass_qos_negotiation = false 
)

An overloaded form of initialize with an additional callback parameter that is called when the current task can be halted.

Parameters
topic_nameThe topic name to use when creating the subscriber.
wait_for_message_timeoutThe timeout duration to use when waiting for a message to be received on the topic.
wait_for_publisher_timeoutThe timeout duration to use when waiting for a publisher to advertise on the topic. Ignored if bypass_qos_negotiation is true.
on_haltableOptional callback that is called when the current task can be halted.
bypass_qos_negotiationIf true, use default QoS instead of negotiating with publisher.

◆ syncGetNextMessage()

template<typename MessageT >
tl::expected< MessageT, std::string > moveit_studio::behaviors::RclcppSubscriberInterface< MessageT >::syncGetNextMessage ( )
overridevirtual

Block until a message is received on the topic.

Returns
If the message was received, returns the message. Returns an error result if the timeout duration was exceeded before a message was received.

Implements moveit_studio::behaviors::SubscriberInterface< MessageT >.


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