ROS services provide a call-and-response model for communication between nodes, unlike topics which provide continual updates. ros2 service list
returns a list of active services, while ros2 service type
and ros2 service find
provide information on service types. ros2 service call
can be used to call a service from the command line.
Services are another method of communication for nodes in the ROS graph. Services are based on a call-and-response model versus the publisher-subscriber model of topics. While topics allow nodes to subscribe to data streams and get continual updates, services only provide data when they are specifically called by a client.
<aside>
💡 Check if /turtlesim
& /teleop_turtle
nodes are active, if not run ros2 run turtlesim turtlesim_node
& ros2 run turtlesim turtle_teleop_key
in separate terminal respectively.
If no node is active, you will not get any output!
</aside>
Running the ros2 service list
command in a new terminal will return a list of all the services currently active in the system. In this example, the currently running nodes are the turtlesim_node
and the turtle_teleop_key
nodes.
The output of the ros2 service list
command is below:
/clear
/kill
/reset
/spawn
/teleop_turtle/describe_parameters
/teleop_turtle/get_parameter_types
/teleop_turtle/get_parameters
/teleop_turtle/list_parameters
/teleop_turtle/set_parameters
/teleop_turtle/set_parameters_atomically
/turtle1/set_pen
/turtle1/teleport_absolute
/turtle1/teleport_relative
/turtlesim/describe_parameters
/turtlesim/get_parameter_types
/turtlesim/get_parameters
/turtlesim/list_parameters
/turtlesim/set_parameters
/turtlesim/set_parameters_atomically
You will see that both nodes have the same six services with parameters
 in their names. Nearly every node in ROS 2 has these infrastructure services that parameters are built off of. There will be more about parameters in the next tutorial. In this tutorial, the parameter services will be omitted from the discussion.
For now, let’s focus on the turtlesim-specific services, /clear
, /kill
, /reset
, /spawn
, /turtle1/set_pen
, /turtle1/teleport_absolute
, and /turtle1/teleport_relative
.
Adding the additional --show-types
argument, abbreviated to -t
, to the ros2 service list
command will return the message type of the service.
/clear [std_srvs/srv/Empty]
/kill [turtlesim/srv/Kill]
/reset [std_srvs/srv/Empty]
/spawn [turtlesim/srv/Spawn]
...
/turtle1/set_pen [turtlesim/srv/SetPen]
/turtle1/teleport_absolute [turtlesim/srv/TeleportAbsolute]
/turtle1/teleport_relative [turtlesim/srv/TeleportRelative]
...
<aside>
💡 This needs atleast one service running, Check if /turtlesim
or /teleop_turtle
nodes are active, if not run ros2 run turtlesim turtlesim_node
orros2 run turtlesim turtle_teleop_key
in separate terminal respectively.
If no service is active, you will not get any output!
</aside>
Services have types that describe how the request and response data of a service is structured. Service types are defined similarly to topic types, except service types have two parts: one message for the request and another for the response.