ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Like the others have said, you can use topics to send information from Node1 to Node2 and then reply along that topic from Node2 back to Node1 But, topics are many-to-many communication channels so there could be many different nodes publishing along that topic and sending replies along that topic as well. Also, topics only carry one data type (message) along them so that means that the message would have to include the communication and response both ways.

For example, let's say that you want to send a message saying "hi" from Node1 to Node2, then a response saying "hello" from Node2 back to Node1. If there's only Node1 and Node2, this isn't such a big deal because it's only a string and that same message type can be used to communicate back and forth. This simple message can have a simple definition:

string greeting

Now, if there's also Node3, Node4, Node5, ...,NodeN then you're going to have issues because they're all using the same topic to greet each other. How is each node supposed to know where the greeting came from and what its destination is? You're going to have to increase the complexity of the message:

string source
string destination
string greeting

This is already problematic because you're potentially tripling the bandwidth of your topic and adding the burden of filtering the messages to make sure that the nodes don't get unwanted greetings. Not to mention that this topic is kept open even if nothing is being sent.

This example is trivial, but imagine that you have several robots running at the same time and you need to send a command telling only one of the robots where to go. This will require you to send the command and also include some sort of identifier.

PoseStamped destination
string name
bool acknowledgement

Again, you have the problem with needing to keep the channel open and having to send the same message back and forth (request and response). What if you're send images? Images consume a large amount of bandwidth (even compressed) and now you're going to have to send an image back and forth. If you were using a service this would be much easier. The service is always available, but not necessarily consuming the band width plus there's an entire request/response cycle. A service client sends a request (take a picture, go over there, etc.) and the server sends a response (acknowledgement, a picture, etc). The entire message isn't sent, first the request, then the response such as

Image image
---
bool acknowledgement

The top portion, Image image, is the request and the bottom portion, bool acknowledgement, is the response. (This is a custom srv by the way.)

So, you can use nodes to send information along with responses, but it can be done better depending on your situation and what you're trying to accomplish. Also, as @NEngelhard mentioned, there's also actions that you should checkout as well.