Template Class ImageSubscriber

Inheritance Relationships

Base Types

Class Documentation

template<template<typename> class Translate = RosMessageSharedPtr>
class ImageSubscriber : public fkie_message_filters::SubscriberBase, public fkie_message_filters::Source<RosMessageSharedPtr<sensor_msgs::msg::Image>::FilterType>

Subscribe to a ROS image topic as data provider.

This is a specialized subscriber that uses image_transport to subscribe to a ROS image topic. All messages which are received on the subscribed topic will be passed to the connected sinks for further processing. For maximum flexibility, you can choose how to pass the received messages:

Unlike regular ROS subscribers, this class can be associated with a publisher instance. In that case, the subscriber will delay subscription until the publisher is actively used and will unsubscribe (and stop passing data) as soon as the publisher becomes idle. This is a convenient method to save processing power if the filter pipeline is used only intermittently.

Public Types

using Output = IO<Outputs...>

Grouped output types.

This type can be used to define sinks with matching types.

Public Functions

inline ImageSubscriber() noexcept

Constructs an empty subscriber.

You need to call set_subscribe_options() and either subscribe() or subscribe_on_demand() to actually subscribe to a ROS topic.

Does not throw any exceptions.

template<class NodeT>
FKIE_MF_BEGIN_ABI_NAMESPACE ImageSubscriber(NodeT &&node, const std::string &base_topic, const rclcpp::QoS &qos, const std::optional<image_transport::TransportHints> &transport_hints, const rclcpp::SubscriptionOptions &options)
template<class NodeT>
ImageSubscriber(NodeT &&node, const std::string &base_topic, const rclcpp::QoS &qos = rclcpp::QoS(rclcpp::KeepLast(10), rmw_qos_profile_default), const std::optional<image_transport::TransportHints> &transport_hints = std::nullopt, const rclcpp::SubscriptionOptions &options = rclcpp::SubscriptionOptions())

Constructor that subscribes to the given ROS image topic.

This constructor calls set_subscribe_options() and subscribe() for you.

  • node a node instance to handle the subscription

  • base_topic name of the ROS image topic, subject to remapping

  • qos the ROS quality of service specification

  • transport_hints transport hints for the ROS image_transport framework

  • options ROS subscription options

Does not throw any exceptions, but will propagate exceptions from the ROS middleware layer.

Connection connect_to_sink(Sink<Outputs...> &dst) noexcept

Connect this source to a sink.

Can be called multiple times to connect multiple sinks; in that case, the sinks receive data in the same order as they have been connected. This function does basically the same thing as Sink::connect_to_source(), only from the opposite point of view.

  • dst the sink that is to be connected

Does not throw any exceptions.

Returns:

a connection object that can be used to monitor or sever the created connection

virtual void disconnect() noexcept override

Disconnect from all connected sinks.

The source implementation calls disconnect_from_all_sinks().

Does not throw any exceptions.

void disconnect_from_all_sinks() noexcept

Disconnect from all connected sinks.

Severs the connection to all sinks, turning the send() method into a no-op.

Does not throw any exceptions.

inline virtual void reset() noexcept

Reset filter state.

For stateful filters, this method resets the internal state as if the filter had just been created. Existing connections to sources and sinks are unaffected.

The default implementation does nothing.

Does not throw any exceptions.

template<class NodeT>
void set_subscribe_options(NodeT &&node, const std::string &base_topic, const rclcpp::QoS &qos = rclcpp::QoS(rclcpp::KeepLast(10), rmw_qos_profile_default), const std::optional<image_transport::TransportHints> &transport_hints = std::nullopt, const rclcpp::SubscriptionOptions &options = rclcpp::SubscriptionOptions())

Configure ROS topic that is to be subscribed.

All arguments are passed to the ROS client library; see the ROS documentation for further information. Calling this method will automatically unsubscribe any previously subscribed ROS topic.

  • node a node instance to handle the subscription

  • base_topic name of the ROS image topic, subject to remapping

  • qos the ROS quality of service specification

  • transport_hints transport hints for the ROS image_transport framework

  • options ROS subscription options

Does not throw any exceptions, but will propagate exceptions from the ROS middleware layer.

virtual void subscribe()

Subscribe to the configured ROS topic.

This method does nothing if no ROS topic was configured or if the subscriber is subscribed already. Cancels the effect of subscribe_on_demand(), i.e. the subscriber will remain subscribed permanently.

Propagates exceptions raised by the implementation of the abstract class methods.

template<class NodeT>
void subscribe(NodeT &&node, const std::string &base_topic, const rclcpp::QoS &qos = rclcpp::QoS(rclcpp::KeepLast(10), rmw_qos_profile_default), const std::optional<image_transport::TransportHints> &transport_hints = std::nullopt, const rclcpp::SubscriptionOptions &options = rclcpp::SubscriptionOptions())

Convenience function to subscribe to a ROS topic.

This function is equivalent to calling set_subscribe_options() and then subscribe().

  • node a node instance to handle the subscription

  • base_topic name of the ROS image topic, subject to remapping

  • qos the ROS quality of service specification

  • transport_hints transport hints for the ROS image_transport framework

  • options ROS subscription options

Does not throw any exceptions, but will propagate exceptions from the ROS middleware layer.

virtual void subscribe_on_demand(PublisherBase &pub)

Subscribe to the configured ROS topic whenever the given publisher is active.

This method does nothing if no ROS topic was configured. Otherwise, it will immediately subscribe or unsubscribe depending on the publisher’s current state. If the publisher becomes active or inactive, the subscriber’s state will update accordingly.

  • pub publisher

Propagates exceptions raised by the implementation of the abstract class methods.

virtual std::string topic() const noexcept override

Return the subscribed topic name.

Depends on the implementation.

virtual void unsubscribe()

Unsubscribe from the configured ROS topic.

You can call subscribe() afterwards to re-subscribe to the ROS topic. This method does nothing if the subscriber is not subscribed to any ROS topic. Cancels the effect of subscribe_on_demand(), i.e. the subscriber will remain unsubscribed permanently.

Propagates exceptions raised by the implementation of the abstract class methods.

Public Static Attributes

static std::size_t NUM_OUTPUTS

Number of output arguments.

Protected Functions

virtual bool is_configured() const noexcept override

Check if the ROS subscriber is properly configured.

Does not throw any exceptions.

Add self to the list of subscribers which are controlled by a publisher.

A subscriber can be linked with one publisher only. Any previously linked publisher is unlinked first.

  • pub publisher

Propagates exceptions raised by the implementation of the abstract class methods.

void send(helpers::argument_t<Outputs>... out)

Pass data to all connected sinks.

  • out data

Does not throw any exceptions, but will propagate uncaught exceptions from filter callbacks.

virtual void subscribe_impl() override

Create a ROS subscriber.

Does not throw any exceptions.

Remove self from the list of subscribers which are controlled by a publisher.

This will not affect the current subscription state. It will only prevent further updates from the previously linked publisher.

Does not throw any exceptions.

virtual void unsubscribe_impl() override

Shut the ROS subscriber down.

Does not throw any exceptions.