Running ros service

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

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 http://answers.ros.org/question/20161... that create a serviceClient was enough. But in my case a simple

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

return

[ 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 :

/dynamic_map
/gmapping/get_loggers
/gmapping/set_logger_level
/rosout/get_loggers
/rosout/set_logger_level

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

Comments

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 imageangeltop ( 2017-05-18 04:37:31 -0600 )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 imageMilow ( 2017-05-18 04:48:50 -0600 )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 imageangeltop ( 2017-05-18 04:55:23 -0600 )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 imageMilow ( 2017-05-18 05:46:14 -0600 )edit

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

Milow gravatar imageMilow ( 2017-05-18 05:46:36 -0600 )edit

On [ https://github.com/ros-simulation/sta... ] 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 imageMilow ( 2017-05-18 05:56:56 -0600 )edit

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

angeltop gravatar imageangeltop ( 2017-05-18 06:31:01 -0600 )edit

Okay it's working, thanks

Milow gravatar imageMilow ( 2017-05-19 04:38:05 -0600 )edit