Defining Custom Services
This tutorial will show you how to define your own custom service data types using the ROS Service Description Language.
Generating Services
Generating a service is easy. Simply place a .srv file inside the srv directory in a package. Then, in your CMakeLists.txt file, add the gensrv() macro somewhere after the call to rospack():
cmake_minimum_required(VERSION 2.4.6) include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake) rospack(my_package) gensrv()
The service file could look something like this:
string first_name string last_name --- uint32 last_score
Any .srv file in the srv directory will generate code for use in all supported languages.
The full specification for the service format is available at the Service Description Language page.
Exporting Services
A service isn't very useful if other packages cannot access it. Some languages require service be exported explicitly.
C++
For C++ we export services through the manifest's export tag. If you don't already have a C++ export tag, just exporting the services looks like this:
<export> <cpp cflags="-I${prefix}/srv/cpp"/> </export>
Including/Importing Services
C++
Services are put into a namespace that matches the name of the package. ie.
or