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

Multiple publishers, one subscriber

asked 2018-08-02 16:51:11 -0600

rbsb gravatar image

updated 2018-08-03 03:46:04 -0600

Mehdi. gravatar image

Hello everyone. I'm trying to make a node that listens to a camera topic (sensor_msgs/Image) and also to a topic that publishes a custom message. The custom message contains a pair of integers (x,y) that specify a pixel for every frame of the video footage (1 pair per message/frame). I want to use the information the node gets from the custom message topic (the integer) in combination with the information from the camera topic (the sensor_msgs/Image message), so I can colour the pixel using OpenCV (but let's not deal with this right now). I've figured out how to set up 2 different subscribers, each one with its own callback. However, I'm having trouble figuring out how to combine the information from both topics and where I should put the pub.publish(...) line. Also, how can I match each camera frame with the correspondant custom message for that frame? Should I use the timestamps or the seq numbers?

ps1: I'm very new to ROS and robotics in general. ps2: The 2 input topics are in the same rosbag.

edit retag flag offensive close merge delete



Can you share with us what you've tried (i.e., code)? It's usually easier to give some help or guidance if we can see what's been done vs a description of it..

jayess gravatar image jayess  ( 2018-08-02 18:07:01 -0600 )edit

This reads like a duplicate of #q299135 (at least, that's just a recent one, there have been many questions posted about this sort of thing).

@rbsb: can you please check whether that Q&A clears things up?

gvdhoorn gravatar image gvdhoorn  ( 2018-08-03 02:41:36 -0600 )edit

May I also suggest a topic change? The question seems to be really about how to use information from two different subscribers at the same time, and then publish the result. The current title does not seem to reflect that.

gvdhoorn gravatar image gvdhoorn  ( 2018-08-03 02:46:57 -0600 )edit

Threads are your friends, two subscribers setting class variables and their timestamps, and a class function with a while loop running as a separate thread. For your simple use case it wouldn't hurt much if you don't consider variable mutex etc.

Mehdi. gravatar image Mehdi.  ( 2018-08-03 03:47:45 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-08-03 03:44:40 -0600

pavel92 gravatar image

Take a loot at message_filters. You can synchronizes incoming channels by the timestamps using the TimeSynchronizer filter and output in the form of a single callback that takes the same number of channels.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-08-02 16:51:11 -0600

Seen: 2,416 times

Last updated: Aug 03 '18