ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

subscribe to two topics of int and sensormsg types

asked 2016-11-27 00:02:39 -0600

anadgopi1994 gravatar image

I want to subscribe to topics that are of types int and sensor_msg .I want only one call back function to proces these two messages together .Please give an example code for this:

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-11-27 04:21:59 -0600

gvdhoorn gravatar image

If both messages have headers, then look into the Time Synchronizers in the message_filters package.

That would allow you to handle (time synchronised) pairs of incoming msgs in a single callback.

edit flag offensive delete link more


I tried the code in time synchronizer which subscribe to two sensor_msg data types that is working.But when i tried to subcribe to two Int8 msg of type std_msgs A lot errors are showing.

anadgopi1994 gravatar image anadgopi1994  ( 2016-11-27 08:40:44 -0600 )edit

Well, both msgs need to have a header. Int8 doesn't have a header, so that could explain the errors.

Any synchronisation strategy will need some piece of information with which it can determine which msgs 'belong together'. The stamp is one way of doing that. Without it, it won't work.

gvdhoorn gravatar image gvdhoorn  ( 2016-11-27 10:09:58 -0600 )edit

Could you please mention that you've posted those 'errors' to another question in the future? Thanks.

gvdhoorn gravatar image gvdhoorn  ( 2016-11-27 10:13:51 -0600 )edit

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


Asked: 2016-11-27 00:02:39 -0600

Seen: 250 times

Last updated: Nov 27 '16