• +4917626969472
  • info@ur-techpartner.de

Important ROS Commands (03/09) – ROS Service

Important ROS Commands Robot Operating System(ROS1/ROS2)

ROS Commands – ROS Service

“Service” is an important concept of ROS. As we have already described services briefly in previous articles (please refer to the ROS Terminologies and ROS Communication blogs), now we will go through ROS service commands.

ROS Service Command “rosservice”

Before running the service commands, we check which options (or arguments) are used with the “rosservice” command.
Open the terminal and run

rosservice –h

We can see multiple options to be used with “rosservice” command as shown in figure below

We run these commands one by one.
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

“rosservice list” command

The “rosservice list” displays the information of active services which are being used in the same network.
Open a new terminal and run the command

rosservice list

You can see a list of active services as shown in the figure below

“rosservice info” command

The structure of “rosservice info” command is

rosservice info [Service_Name]

As we can see a number of active services in previous figure, we can get the info of the service (e.g. turtle1/set_pen) using this command.

Run in terminal

rosservice info turtle1/set_pen

The command displays the Node, URI, Type, and parameter (i.e. Args) of the service “turtle1/set_pen” as shown in figure below

In examples of forthcoming commands, we will see how we can call the service by giving the parameters as input.

“rosservice type” command

This command is used to determine the type of the service. The structure of the command is

rosservice type [Service_Name]

Run the command in terminal

rosservice type turtle1/set_pen

“rosservice find” command

The “rosservice find” command is used to search a specific service using its type. The structure of the command is

rosservice find [Service_Type]

Run the command in terminal

rosservice find turtlesim/SetPen

“rosservice uri” command

Using “rosservice uri” command, we can check the Uniform Resource Identifier (URI) of the specified service.

The structure of the service is same as previous commands.

rosservice uri [Service_Name]

Run in terminal

rosservice uri turtle1/set_pen

“rosservice args” command

Using “rosservice args” command, we can check the parameter of the specified service. For example, if we want to check the parameter of the service “turtle1/set_pen”

Run the following command

rosservice args turtle1/set_pen

The results of running “rosservice type”, “rosservice find”, “rosservice uri”, and “rosservice args” commands on service “turtle1/set_pen” are shown in figure below

“rosservice call” command

We have already seen the parameter of the service “turtle1/set_pen”. By using “rosservice call”, we can request the service “ turtle1/set_pen”, by giving the parameter values as an input at the time of service call.

The structure of the command is as follows

rosservice call [Service_Name]

As we know the parmeter of “ turtle1/set_pen” are “r g b width off”. Here “r” represents red, “g” represents green and “b” represents blue colors. While “width” is the thickness of the writing pen. The value of “off” is set either 1 (true) or 0 (false) which is used to either “display” or “not display” the line.

We call the service by giving input to the parameter and see what happens.

Run in Terminal

rosservice call /turtle1/set_pen 255 0 0 5 0

It sets the value of “red” equal to 255 (maximum value), while green and blue are set to zero. Width of the pen is set to “5”, and “off” parameter is zero which means the line will be displayed.

Now we use the arrow keys to move the turtle and we can see the red line is displayed along with the movement of the turtle.

Note: For the movement of the turtle, remember to click on the terminal where “turtle_teleop_key” node is running.

Now, We set the parameter again to new values, (Now set red to zero and green to 255), and run the following command

rosservice call /turtle1/set_pen 0 255 0 5 0

By moving the turtle with arrow keys, we can see that the color of pen is changed from red to green.
The “rosservice call” command is very important command which is mainly used for testing purpose.

No comments