Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion image_transport/include/image_transport/image_transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ Subscriber create_subscription(
const std::string & base_topic,
const Subscriber::Callback & callback,
const std::string & transport,
rmw_qos_profile_t custom_qos = rmw_qos_profile_default);
rmw_qos_profile_t custom_qos = rmw_qos_profile_default,
SubscriptionOptionsWithVoidAllocator options = SubscriptionOptionsWithVoidAllocator());
Comment thread
audrow marked this conversation as resolved.
Outdated

/*!
* \brief Advertise a camera, free function version.
Expand Down
4 changes: 4 additions & 0 deletions image_transport/include/image_transport/loader_fwds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#ifndef IMAGE_TRANSPORT__LOADER_FWDS_HPP_
#define IMAGE_TRANSPORT__LOADER_FWDS_HPP_

#include <rclcpp/rclcpp.hpp>

// Forward-declare some classes most users shouldn't care about so that
// image_transport.hpp doesn't bring them in.

Expand All @@ -46,6 +48,8 @@ namespace image_transport {
class PublisherPlugin;
class SubscriberPlugin;

using SubscriptionOptionsWithVoidAllocator = rclcpp::SubscriptionOptionsWithAllocator<std::allocator<void>>;
Comment thread
audrow marked this conversation as resolved.
Outdated

typedef pluginlib::ClassLoader<PublisherPlugin> PubLoader;
typedef std::shared_ptr<PubLoader> PubLoaderPtr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include <rclcpp/subscription.hpp>

#include "image_transport/loader_fwds.hpp"
#include "image_transport/subscriber_plugin.hpp"
#include "image_transport/visibility_control.hpp"

Expand Down Expand Up @@ -116,7 +117,8 @@ class SimpleSubscriberPlugin : public SubscriberPlugin
rclcpp::Node * node,
const std::string & base_topic,
const Callback & callback,
rmw_qos_profile_t custom_qos)
rmw_qos_profile_t custom_qos,
SubscriptionOptionsWithVoidAllocator options)
{
impl_ = std::make_unique<Impl>();
// Push each group of transport-specific parameters into a separate sub-namespace
Expand All @@ -126,7 +128,7 @@ class SimpleSubscriberPlugin : public SubscriberPlugin
impl_->sub_ = node->create_subscription<M>(getTopicToSubscribe(base_topic), qos,
[this, callback](const typename std::shared_ptr<const M> msg){
internalCallback(msg, callback);
});
}, options);
}

private:
Expand Down
3 changes: 2 additions & 1 deletion image_transport/include/image_transport/subscriber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class Subscriber
const Callback & callback,
SubLoaderPtr loader,
const std::string & transport,
rmw_qos_profile_t custom_qos = rmw_qos_profile_default);
rmw_qos_profile_t custom_qos = rmw_qos_profile_default,
SubscriptionOptionsWithVoidAllocator options = SubscriptionOptionsWithVoidAllocator());

/**
* \brief Returns the base image topic.
Expand Down
6 changes: 4 additions & 2 deletions image_transport/include/image_transport/subscriber_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <sensor_msgs/msg/image.hpp>
#include <message_filters/simple_filter.h>

#include "image_transport/loader_fwds.hpp"
#include "image_transport/image_transport.hpp"
#include "image_transport/visibility_control.hpp"

Expand Down Expand Up @@ -115,12 +116,13 @@ class SubscriberFilter : public message_filters::SimpleFilter<sensor_msgs::msg::
rclcpp::Node * node,
const std::string & base_topic,
const std::string & transport,
rmw_qos_profile_t custom_qos = rmw_qos_profile_default)
rmw_qos_profile_t custom_qos = rmw_qos_profile_default,
SubscriptionOptionsWithVoidAllocator options = SubscriptionOptionsWithVoidAllocator())
{
unsubscribe();
sub_ =
image_transport::create_subscription(node, base_topic,
std::bind(&SubscriberFilter::cb, this, std::placeholders::_1), transport, custom_qos);
std::bind(&SubscriberFilter::cb, this, std::placeholders::_1), transport, custom_qos, options);
}

/**
Expand Down
19 changes: 12 additions & 7 deletions image_transport/include/image_transport/subscriber_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <rclcpp/node.hpp>
#include <sensor_msgs/msg/image.hpp>

#include "image_transport/loader_fwds.hpp"
#include "image_transport/visibility_control.hpp"

namespace image_transport
Expand Down Expand Up @@ -70,9 +71,10 @@ class IMAGE_TRANSPORT_PUBLIC SubscriberPlugin
void subscribe(
rclcpp::Node * node, const std::string & base_topic,
const Callback & callback,
rmw_qos_profile_t custom_qos = rmw_qos_profile_default)
rmw_qos_profile_t custom_qos = rmw_qos_profile_default,
SubscriptionOptionsWithVoidAllocator options = SubscriptionOptionsWithVoidAllocator())
{
return subscribeImpl(node, base_topic, callback, custom_qos);
return subscribeImpl(node, base_topic, callback, custom_qos, options);
}

/**
Expand All @@ -81,11 +83,12 @@ class IMAGE_TRANSPORT_PUBLIC SubscriberPlugin
void subscribe(
rclcpp::Node * node, const std::string & base_topic,
void (*fp)(const sensor_msgs::msg::Image::ConstSharedPtr &),
rmw_qos_profile_t custom_qos = rmw_qos_profile_default)
rmw_qos_profile_t custom_qos = rmw_qos_profile_default,
SubscriptionOptionsWithVoidAllocator options = SubscriptionOptionsWithVoidAllocator())
{
return subscribe(node, base_topic,
std::function<void(const sensor_msgs::msg::Image::ConstSharedPtr &)>(fp),
custom_qos);
custom_qos, options);
}

/**
Expand All @@ -95,10 +98,11 @@ class IMAGE_TRANSPORT_PUBLIC SubscriberPlugin
void subscribe(
rclcpp::Node * node, const std::string & base_topic,
void (T::* fp)(const sensor_msgs::msg::Image::ConstSharedPtr &), T * obj,
rmw_qos_profile_t custom_qos = rmw_qos_profile_default)
rmw_qos_profile_t custom_qos = rmw_qos_profile_default,
SubscriptionOptionsWithVoidAllocator options = SubscriptionOptionsWithVoidAllocator())
{
return subscribe(node, base_topic,
std::bind(fp, obj, std::placeholders::_1), custom_qos);
std::bind(fp, obj, std::placeholders::_1), custom_qos, options);
}

/**
Expand Down Expand Up @@ -146,7 +150,8 @@ class IMAGE_TRANSPORT_PUBLIC SubscriberPlugin
virtual void subscribeImpl(
rclcpp::Node * node, const std::string & base_topic,
const Callback & callback,
rmw_qos_profile_t custom_qos = rmw_qos_profile_default) = 0;
rmw_qos_profile_t custom_qos = rmw_qos_profile_default,
SubscriptionOptionsWithVoidAllocator options = SubscriptionOptionsWithVoidAllocator()) = 0;
Comment thread
audrow marked this conversation as resolved.
Outdated
};

} // namespace image_transport
Expand Down
5 changes: 3 additions & 2 deletions image_transport/src/image_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ Subscriber create_subscription(
const std::string & base_topic,
const Subscriber::Callback & callback,
const std::string & transport,
rmw_qos_profile_t custom_qos)
rmw_qos_profile_t custom_qos,
SubscriptionOptionsWithVoidAllocator options)
{
return Subscriber(node, base_topic, callback, kImpl->sub_loader_, transport, custom_qos);
return Subscriber(node, base_topic, callback, kImpl->sub_loader_, transport, custom_qos, options);
}

CameraPublisher create_camera_publisher(
Expand Down
5 changes: 3 additions & 2 deletions image_transport/src/subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ Subscriber::Subscriber(
const Callback & callback,
SubLoaderPtr loader,
const std::string & transport,
rmw_qos_profile_t custom_qos)
rmw_qos_profile_t custom_qos,
SubscriptionOptionsWithVoidAllocator options)
: impl_(std::make_shared<Impl>(node, loader))
{
// Load the plugin for the chosen transport.
Expand Down Expand Up @@ -125,7 +126,7 @@ Subscriber::Subscriber(

// Tell plugin to subscribe.
RCLCPP_DEBUG(impl_->logger_, "Subscribing to: %s\n", base_topic.c_str());
impl_->subscriber_->subscribe(node, base_topic, callback, custom_qos);
impl_->subscriber_->subscribe(node, base_topic, callback, custom_qos, options);
}

std::string Subscriber::getTopic() const
Expand Down
5 changes: 4 additions & 1 deletion image_transport/test/test_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ TEST_F(TestPublisher, construction_and_destruction) {
std::function<void(const sensor_msgs::msg::Image::ConstSharedPtr & msg)> fcn =
[](const auto & msg) {(void)msg;};

auto sub = image_transport::create_subscription(node_.get(), "camera/image", fcn, "raw");
auto qos_profile = rmw_qos_profile_default;
auto options = rclcpp::SubscriptionOptionsWithAllocator<std::allocator<void>>();
auto sub = image_transport::create_subscription(
node_.get(), "camera/image", fcn, "raw", qos_profile, options);
Comment thread
audrow marked this conversation as resolved.
Outdated

rclcpp::executors::SingleThreadedExecutor executor;
executor.spin_node_some(node_);
Expand Down