Ask Your Question

Creating own service (not copying from some other package)

asked 2012-06-08 10:44:51 -0500

Nishant gravatar image

updated 2014-01-28 17:12:37 -0500

ngrennan gravatar image


So I am new to ROS and I went through most of the beginner tutorials. I am at the point where I am learning how to create my own services. In the ROS tutorial on the link below, they tell you how to copy a service from some other package, using 'roscp'.

A few questions come to mind after following the tutorial on the link above, and the subsequent 2-3 tutorials:

1) How do I create my OWN service? This tutorial shows how to copy one from some other package. Any steps that I can follow to create my own service with my own choice of messages?

2) Can anyone tell me how the client-server model works with the services? Its hard to understand what's going on without namespaces in the tutorial. A step-by-step description of what exactly is going on, would be really helpful.

3) This is not an essential piece of knowledge, but I am just curious about why there exist two commands rosservice and rossrv. Can't the functionality of both these commands be captured into one, say 'rosservice' only?

4) In the tutorial link above, they use the function advertiseService() with the nodehandle pointer. Is this a new addition to ROS? I remember seeing something like advertise() which does the same thing as advertiseService() on some other tutorial page.

Thanks for the patience to go through my post!


edit retag flag offensive close merge delete


Thanks Lindzey and joq for your insights! Especially for (1) and (4). I will post a new question if I have any further doubts! :)

Nishant gravatar image Nishant  ( 2012-06-08 13:58:17 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2012-06-08 11:27:28 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

1) Rather than using roscp as shown in section 1.5 of the tutorial you linked, create a my_service.srv file in the srv directory. Edit this file to have the fields you want, using the format described (request fields above the ---, response fields below the ---). So long as your CMakeLists.txt file includes the line:


all the services defined in the package's srv directory will be made.

2) A service invocation is basically a remote procedure call. The caller (normally) waits until the response is available.

3) I see the distinction between rosservice/rossrv (and rostopic/rosmsg) being that rosservice provides you with tools to analyze and interact with the services in your currently-running system, while rossrv only deals with what's defined in the code.

4) advertise() is for topics, advertiseService() is for services.

edit flag offensive delete link more


2) A service invocation is basically a remote procedure call. The caller (normally) waits until the response is available.

joq gravatar image joq  ( 2012-06-08 11:49:15 -0500 )edit

4) advertise() is for topics, advertiseService() is for services.

joq gravatar image joq  ( 2012-06-08 11:50:11 -0500 )edit

@joq - I updated the answer with your comments & made it a wiki ... let me know if this isn't the preferred way to handle questions like this!

lindzey gravatar image lindzey  ( 2012-06-08 11:54:55 -0500 )edit

That's fine. I would have felt presumptuous editing your answer myself. :-)

joq gravatar image joq  ( 2012-06-08 12:27:37 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-06-08 10:44:51 -0500

Seen: 357 times

Last updated: Jun 08 '12