ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

how can I implement efficient intra-process communication with message filters

asked 2019-06-10 04:00:27 -0500

xhuan28 gravatar image

I once tried out the tutorial of intra process communication which impressed me that it can improve communication performance with zero-copy. Afterwards, I tried to adopt this best practice in my application, but I met an issue. I need to synchronize messages from two topics with message filters. As mentioned in the tutorial, we have to use std::unique_ptrs to implement zero-copy.

This is because we’re publishing and subscribing with std::unique_ptrs which allow ownership of a message to be moved around the system safely. You can also publish and subscribe with const & and std::shared_ptr, but zero-copy will not occur in that case.

However, the callback of message filters only accept std::shared_ptr as its parameters. Does it mean we cannot take benefits from zero-copy if we use message filters, unless some code changes need to be done from message filter side?

edit retag flag offensive close merge delete


Cross posting your question in multiple locations ( is against the etiquette:

Dirk Thomas gravatar image Dirk Thomas  ( 2019-06-10 11:24:46 -0500 )edit

Sorry, I didn't realize this is against the etiquette of ROS community. However, I think it is more suitable to ask this question here than the github of message filters, so I close that one in github. Could you please reopen this one? Thanks.

xhuan28 gravatar image xhuan28  ( 2019-06-10 20:50:26 -0500 )edit

Actually, I would like to know whether it is a limitation to implement zero-copy with message filters currently and is it feasible to expose a new API from message filters to break the limitation.

xhuan28 gravatar image xhuan28  ( 2019-06-10 20:59:08 -0500 )edit

I've re-opened this as the GH issue has been closed, but please keep the etiquette in mind @xhuan28.

I didn't realize this is against the etiquette of ROS community.

nt accepting cross-posting support requests is not necessarily something specific to the ROS community: it leads to split discussions and wasted effort on the part of the people responding to your questions. That would not be a good thing in any community.

gvdhoorn gravatar image gvdhoorn  ( 2019-06-11 02:20:21 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2021-08-31 23:06:40 -0500

pionex gravatar image

I have not fully tested this (for bugs or performance), but I believe I have a working solution. In the Subscriber class of message_filters (subscriber.h), I have added a subscribezc method (below) that is exactly the same as the standard method but subscribes using a unique_ptr. I am getting the same pointer address for the message as it moves through the nodes (all running in a component container). I just did another test using the regular subscribe function, however and had the same result. I'm using Foxy on Ubuntu 20.04 installed from APT and I'm not sure if ROS was updated to use zero copy even in cases where not subscribed to a unique_ptr.

  void subscribezc(rclcpp::Node * node, const std::string& topic, const rmw_qos_profile_t qos = rmw_qos_profile_default)

    if (!topic.empty())
      topic_ = topic;
      rclcpp::QoS rclcpp_qos(rclcpp::QoSInitialization::from_rmw(qos));
      rclcpp_qos.get_rmw_qos_profile() = qos;
      qos_ = qos;
      sub_ = node->create_subscription<M>(topic, rclcpp_qos,
               [this, node](std::unique_ptr<M> msg) {
                 RCLCPP_INFO(node->get_logger(), "Got UP Callback %x", msg.get());

      node_raw_ = node;
edit flag offensive delete link more

Question Tools



Asked: 2019-06-10 04:00:27 -0500

Seen: 578 times

Last updated: Aug 31 '21