Ask Your Question
0

Multiple publishers, one subscriber

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

rbsb gravatar image

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

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

Comments

1

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 imagejayess ( 2018-08-02 18:07:01 -0500 )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 imagegvdhoorn ( 2018-08-03 02:41:36 -0500 )edit
2

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 imagegvdhoorn ( 2018-08-03 02:46:57 -0500 )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 imageMehdi. ( 2018-08-03 03:47:45 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 404 times

Last updated: Aug 03 '18