Important ROS Commands – ROS Service Message
In order to get the information about the service messages, “rossrv” command is used.
Difference between Topic Message and Service Message
As we already knew that Topics use messages to transfer information. Similarly, Services use Service messages.
The difference between Topic message and Service message is that the topic message files have the extension “.msg”, and they are defined inside the “msg” directory. While, service message files have the extension “.srv”, and they are defined inside the “srv” directory.
Another difference is that the topic message consists of only one section, while the service message consists of two sections (request and response) separated by “- – -” from each other.
In order to get the information about topic messages, the command “rosmsg” is used (as described in the previous blog). On the other hand, for getting information about Service messages, the command “rossrv” is used.
In literature, some authors call it “service information” instead of “service message”.
ROS Service Command “rossrv”
First we will check the options which can be used with the command “rossrv”.
Run following command in the terminal
rossrv -h
We can see the options that can be used with “rossrv” command in figure below.
You will notice that these options are the same as we have seen with “rosmsg” in previous blog.
Now we will go through these commands one by one.
Note: The order of the commands in above list may be different from the order of the commands in our description. This is because, we will follow the order which is convenient to explain and execute the commands.
Close all terminals, and open three new terminals to run the following three commands in each terminal separately
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
“rossrv list” command
The “rossrv list” command displays the the list of all service messages of the services which are currently installed. The output of executing the command “rossrv list” also depends on the packages installed in ROS.
Open a new terminal and run the command
rossrv list
You can see a long list of service messages that are listed in alphabet order. Since the list is very long, we are displaying only few of them in figure below
“rossrv show” command
The “rossrv show” command displays the information of a specific service message. The structure of the command is as follows
rossrv show [Service_Message_Name]
For example, we can visualize the information of turtlesim/SetPen service message.
Run the command
rossrv show turtlesim/SetPen
We can see the service message information in figure below
In above picture ,we can see that the service message contains the variables “r”, “g”, “b”, “width”, and “off”.
If you remember, in the blog of ROS Services, we have already call the service “turtle1/set_pen”, where we set the value of r equal to 255 (maximum value for red), and width equal to 5 (thickness of pen) to show the movement of turtle in red color.
Difference between ROS Service and ROS Service Message
Since for some readers, it might be confusing what is ROS Service and what is ROS Service message. Here we will briefly describe the difference by example.
First we see the list of active services.
Run the command
rosservice list
We can see in figure below that there is a service “/turtle1/set_pen” in the list.
Run the “rosservice info” command to see the information of the the service “/turtle1/set_pen”
rosservice info /turtle1/set_pen
Running this command, we have following output
Node: /turtlesim
URI: rosrpc://kashif:46201
Type: turtlesim/SetPen
Args: r g b width off
It shows that the service “/turtle1/set_pen” is of type “turtlesim/SetPen”. The type of the service is actually service message.
Further run the command to the display the list of service messages (filter it with “SetPen” using “grep”)
rossrv list | grep SetPen
We can see that the “turtlesim/SetPen” is a service message displayed in the list.
Now we get the information of the message “turtlesim/SetPen”
Run the command
rossrv show turtlesim/SetPen
To summarize, in figure below the commands and outputs are displayed, which clearly distinguish service and service message from each other.
It can be concluded that the service “/turtle1/set_pen” uses the service message “turtlesim/SetPen” for communication. Hence the service “/turtle1/set_pen” is of type “turtlesim/SetPen”, which is actually service message.
“rossrv package” command
The “rossrv package” command is used to show the service messages used in a specific package. The structure of the command is as follows
rossrv package [Package_Name]
Run in terminal
rossrv package turtlesim
“rossrv packages” command
There is another similar command “rossrv packages”, which is used to display the list of all packages that use service messages.
We run the command to see the result
rossrv packages
Note that the command “rossrv package turtlesim” will display the “service messages” used in the package “turtlesim”, while the command “rossrv packages” will display all “packages” that use any service messages.
As show in figure below
“rossrv info” command
The “rossrv info” command is Alias for “rossrv show”, and does exactly the same thing as show in the figure below
Run the command
rossrv info turtlesim/SetPen
The command “rossrv md5” is used to verify the integrity of the service message. However, it is not commonly used. you can further read about it on wikipedia if needed.