0
$\begingroup$

Rosanswers logo

Hi!

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'.

http://www.ros.org/wiki/ROS/Tutorials/CreatingMsgAndSrv#Creating_a_srv

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!

Nishant.


Originally posted by Nishant on ROS Answers with karma: 143 on 2012-06-08

Post score: 0


Original comments

Comment by Nishant on 2012-06-08:
Thanks Lindzey and joq for your insights! Especially for (1) and (4). I will post a new question if I have any further doubts! :)

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

  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:

    rosbuild_gensrv() 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.


Originally posted by lindzey with karma: 1780 on 2012-06-08

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by joq on 2012-06-08:
2) A service invocation is basically a remote procedure call. The caller (normally) waits until the response is available.

Comment by joq on 2012-06-08:
4) advertise() is for topics, advertiseService() is for services.

Comment by lindzey on 2012-06-08:
@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!

Comment by joq on 2012-06-08:
That's fine. I would have felt presumptuous editing your answer myself. :-)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.