Ask Your Question
0

Addressing messages using different topics vs. using in-message identifier

asked 2015-09-15 07:02:43 -0500

anoman gravatar image

Suppose we have one control node ns_a/control and multiple device nodes ns_b_[1|2|3|...]/device (i.e. for 2 device nodes it would be ns_b_1/device, ns_b_2/device). I want to send a control message m1 tp different device nodes. There are two possibilities to do so.

1) Create specific topic for each tuple (ns_a/control, ns_b_1/device), (ns_a/control, ns_b_2/device) and so on. Thus the message m1 will always get to one specific device node depending on which topic I publish to. The drawback is the fact that I would have to create as many publishers as many device nodes I have.

2) Create only one topic to publish to and specify the receiver in the message m1 itself. I could for instance add variable int receiver to the message m1 which would specify for which device the message was sent. The drawback of this approach is the fact, that all device nodes would have to process all messages m1 no matter for which device node this message was sent and they would have to check themselves whether the message was addressed for them.

Which approach is more 'clean' and/or is there any other and better approach to deal with such a situation?

Thank you in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2015-09-15 11:03:03 -0500

destogl gravatar image

I would say first approach is more ROS-approach. Since you are working with same data types and only topic name is different, you can just have array of publishers and send data accordingly, so you don't have duplicate code.

The second approach IMHO is not clean, because components receive messages not intended for them. Also you are generating more traffic through ROS network since you are sending all the time messages to N other nodes.

edit flag offensive delete link more

Comments

Yes, I share your opinion so I will stick with the first option and it is a good idea to create the array of publishers to avoid duplicate code. Thank you!

anoman gravatar imageanoman ( 2015-09-16 06:13:27 -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

2 followers

Stats

Asked: 2015-09-15 07:02:43 -0500

Seen: 251 times

Last updated: Sep 15 '15