Ask Your Question
0

Subscribing multiple topics with different rate

asked 2019-02-18 08:17:25 -0500

pse18_10 gravatar image

Hey there,

I´m currently new at ROS but made yet all the beginner tutorials at the ROS homepage.

First I implemented a simple publisher and subscriber and it worked. Now I want to create something like the following:

  • Node A which publishes a string with rate(1) to topic “test_01” , variable var01
  • Node B which publishes an int with rate(1) to topic “test_02”, variable var02
  • Node C which publishes an int with rate(10) to topic “test_03” , variable var03

I want to have the following workflow: an node D which subscribes to all three nodes A-C and producing the following output on the screen:

cout << “%s %i %i” << var01 var02 var03 << endl;

So each time a message is published, the cout should performed with the actual variables. As I understood so far, CallbackQueues ( http://wiki.ros.org/roscpp/Overview/C... ) might be the right strategy, but after hours of trying without success I don´t have any idea how to implement the workflow…

Happy about every hint 😊

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2019-02-18 11:16:27 -0500

gvdhoorn gravatar image

This seems like something that would not require separate CallbackQueues, but can be solved with "global variables" or message_filters (more specifically: Cache.

If you want to keep it simple: in every callback, first store the incoming msg into a global variable (or any variable that exists in a scope other than the local callback/function scope), then print your log message. Do this for all callbacks.

Any time any of the callbacks receives a message, the log message will be printed with the "last" received value of the other subscriptions. You might want to see whether you'd have to lock any of the variables to avoid reading (printing) stale data, but that would be an optimisation (almost).

As to Cache: if your messages have a header: store each incoming msg in a Cache, lookup corresponding (or latest messages for the other subscriptions), then print the log message.

edit flag offensive delete link more

Comments

I made it with global variables, thanks a lot!

pse18_10 gravatar imagepse18_10 ( 2019-02-20 03:03:57 -0500 )edit

Good to hear you got it to work: now improve on it by not using global variables :)

gvdhoorn gravatar imagegvdhoorn ( 2019-02-20 03:07:34 -0500 )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

Stats

Asked: 2019-02-18 08:17:25 -0500

Seen: 50 times

Last updated: Feb 18