I am using ROS system and I am a beginner. I came across Service and Message (srv and msgs) in ROS. From the ros wiki, I manage to understand like msgs are used to define the type of message been passed and service is about request and response. Please correct me if I got this wrong.
Nevertheless, I am unable to understand when to use them. I thought that maybe it would be useful if I have modules written in C++ and other Processing Modules in Python than perhaps I can use srv and msgs for communicating between the 2 modules. However, than ROS also have publisher and subscriber system which could be used instead?
Secondly, when we use srv than only we need to define the msgs or either can be independently be used?
First of all, let me point you here:
http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29
It's the first example given by Ros
tutorials.
Publishers and subscribers are entities used to achieve node intercommunication. Publishers post messages to a channel, while subscribers listen to such channels to acquire messages possibly sent by publishers. Publishers post to channel using messages and which hold different kind of data depending on what is trying to be achieved. Subscribers take these messages and automatically execute a callback function
to achieve something useful with the data.
Now let me point you here:
http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28c%2B%2B%29
It is a similar example, but this time, services are used to achieve communication. The things with messages is that, once the node publishes a message, the whole communication thing is over and the node continues with the rest of its job. On the other hand, client (they use services) communicate with servers; they publish a message to a server, and then wait for a response by that server.
Examples:
If you make sure you understand a simple program with messages and a simple program with services, then you can expand your knowledge by creating examples, like the one presented above. Only then will you be able to fully grasp it with full detail.