Ask Your Question
0

re-publishing data from multiple topics

asked 2013-04-13 16:19:01 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I've written a node which takes data from node A via a topic, which uses custom messages, does some manipulation with it, then publishes it to another topic. However the node also listens to a topic from node B, which is not always active. I'm not sure how I go about getting the node to use data from node B when it is active, but using node A otherwise?

I've tried a few different ways and come across different issues. Firstly I was thinking of somehow being able to switch to listen to the higher priority topic B, when the node is initiated.

I also tried to play with some if statements in the callback, but realised the callback can only deal with 1 set of custom messages at once.

Note: this is using python

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-04-15 17:19:09 -0500

joq gravatar image

A crude solution:

  • Keep track of when you last received a message from node B.

  • When a message arrives from node A, ignore it if the last node B message was more recent than some timeout threshold. Otherwise, handle it normally.

edit flag offensive delete link more

Comments

+1 from me. Using some kind of timeout is the only solution i can think of for this problem. You may also read this answer regarding a somewhat similar question: http://answers.ros.org/question/59347/publishers-priority/#59357

Ben_S gravatar imageBen_S ( 2013-04-16 04:34:53 -0500 )edit

Since your messages are custom, you could send a "good-bye" message from node B, after which the subscriber would switch back to handling node A messages immediately.

joq gravatar imagejoq ( 2013-04-16 05:12:26 -0500 )edit

Cheers, guys. Yeah I was just thinking that joq, but I was thinking the opposite way around, i.e. node B has a "hello" message, or an "on" message that is sent with each data set. I'm not quite sure how to implement this though.

luke91 gravatar imageluke91 ( 2013-04-17 00:06:35 -0500 )edit

Edit: managed to work it out, think I've gone about it the long way but it works!

luke91 gravatar imageluke91 ( 2013-04-17 00:10:26 -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

Stats

Asked: 2013-04-13 16:19:01 -0500

Seen: 144 times

Last updated: Apr 15 '13