0
$\begingroup$

Rosanswers logo

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.


Originally posted by anoman on ROS Answers with karma: 1 on 2015-09-15

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by destogl with karma: 877 on 2015-09-15

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by anoman on 2015-09-16:
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!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.