ROS Filesystem Concepts: Packages | Manifest | Stacks | Stack Manifest | msg | srv

Note: This is a legacy, rosbuild based, version of the ROS Filesystem Concepts

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:

#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
uint32 an_integer

You cannot embed another service inside of a service.

Building .srv Files

The ROS Client Libraries implement service generators that translate .srv files into source code. These service generators must be invoked from your build script, though most of the gory details are taken care of by including some common build rules. By convention, all .srv files are stored in a directory within your package called "srv," and you can build all of them by adding the line gensrv() to your CMakeLists.txt file. Here is an example:

cmake_minimum_required(VERSION 2.6)
include(rosbuild)
rospack(robot_srvs)
gensrv()

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.

Wiki: rosbuild/srv (last edited 2013-10-18 22:16:54 by WilliamWoodall)