Running ros service

asked 2017-05-18 04:18:36 -0500

Milow gravatar image

How to run a ros service (not a personnal one, I have already read the tutorial about create personnal service and use them) ? I saw on this question that create a serviceClient was enough. But in my case a simple

 client = n.serviceClient<std_srvs::Empty>("/reset_positions");


[ INFO] [1495007235.234008766]: waitForService: Service [/reset_positions] has not been advertised, waiting...

I deduce the node isn't running. But I thougth /reset_positions was a ros service and would run in background when starting roscore.

After a roscore, when I run rosservice list, it returns :


So obviously, there is no /reset_positions service running.
I'm a bit lost, what I'm supposed to do to use the reset_position service ?

edit retag flag offensive close merge delete


Are you running the ServiceServer on the same topic? The server advertises the service. roscore does not automatically start services, custom or otherwise. It only starts the default logger service servers

angeltop gravatar image angeltop  ( 2017-05-18 04:37:31 -0500 )edit

Okay for roscore. I don't see what I have to advertise. I can do :

ros::ServiceServer service = n.advertiseService("reset_positions", foo);

and do the process into a foo function. But it's just a personnal service called with the same name as a ros service. How can I advertise a ros service ?

Milow gravatar image Milow  ( 2017-05-18 04:48:50 -0500 )edit

I do not understand the term "personal service" You can setup your Server with: ros::ServiceServer service = n.advertiseService("/reset_positions", foo); bool foo(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res){ /* process stuff */}

angeltop gravatar image angeltop  ( 2017-05-18 04:55:23 -0500 )edit

As I understand ros, there are services implemented by ros (which I would like to call) and services users can code by their own. By "personnal service", I mean a service implemented by me (user).

Milow gravatar image Milow  ( 2017-05-18 05:46:14 -0500 )edit

I thought reset_positions could reset the position of my turtlebot without I had to implement the foo function.

Milow gravatar image Milow  ( 2017-05-18 05:46:36 -0500 )edit

On [ ] it's write : Added reset_positions service to stage (adds dependency on std_srvs). I don't understand the purpose of adding a service if I have to recode it.

Milow gravatar image Milow  ( 2017-05-18 05:56:56 -0500 )edit

In this case you should start the node of this package that runs the ServiceServer

angeltop gravatar image angeltop  ( 2017-05-18 06:31:01 -0500 )edit

Okay it's working, thanks

Milow gravatar image Milow  ( 2017-05-19 04:38:05 -0500 )edit