[Documentation] [TitleIndex] [WordIndex

For rosbuild, see: rosbuild/srv

ROS uses a simplified service description language ("srv") for describing ROS service types. This builds directly upon the ROS msg format to enable request/response communication between nodes. Service descriptions are stored in .srv files in the srv/ subdirectory of a package. You should familiarize yourself with the msg format before attempting to write .srv files.

Service descriptions are referred to using package resource names. For example, the file robot_srvs/srv/SetJointCmd.srv is commonly referred to as robot_srvs/SetJointCmd.

Command-line Tools

rossrv prints out service descriptions, packages that contain .srv files, and can find source files that use a service type.

Service Description Specification

A service description file consists of a request and a response msg type, separated by '---'. Any two .msg files concatenated together with a '---' are a legal service description.

Here is a very simple example of a service that takes in a string and returns a string:

string str
---
string str

We can of course get much more complicated (if you want to refer to a message from the same package you must not mention the package name):

#request constants
int8 FOO=1
int8 BAR=2
#request fields
int8 foobar
another_pkg/AnotherMessage msg
---
#response constants
uint32 SECRET=123456
#response fields
another_pkg/YetAnotherMessage val
CustomMessageDefinedInThisPackage value
uint32 an_integer

You cannot embed another .srv inside of a .srv.

Building .srv Files

See: catkin/CMakeLists.txt#msgs_srvs_actions

Client Library Support

In Python, the generated Python service type file (e.g. foo_srvs.srv.Foo) provides nearly all the information you might want about a .srv file. You can examine the __slots__ and _slot_types and other fields to introspect information about the request and reply Messages. For advanced users, the roslib.srvs module in the roslib Package provides basic support for parsing .srv files in Python. This library is only recommended for those implementing service generators.


2024-11-30 17:57