Running ros service
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/201617/how-to-call-a-service-inside-a-node/ 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 :
/dynamicmap
/gmapping/getloggers
/gmapping/setloggerlevel
/rosout/getloggers
/rosout/setlogger_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 ?
Asked by Milow on 2017-05-18 04:18:36 UTC
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
Asked by angeltop on 2017-05-18 04:37:31 UTC
Okay for roscore. I don't see what I have to advertise. I can do :
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 ?
Asked by Milow on 2017-05-18 04:48:50 UTC
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 */}
Asked by angeltop on 2017-05-18 04:55:23 UTC
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).
Asked by Milow on 2017-05-18 05:46:14 UTC
I thought
reset_positions
could reset the position of my turtlebot without I had to implement the foo function.Asked by Milow on 2017-05-18 05:46:36 UTC
On [ https://github.com/ros-simulation/stage_ros/blob/lunar-devel/CHANGELOG.rst ] 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.Asked by Milow on 2017-05-18 05:56:56 UTC
In this case you should start the node of this package that runs the ServiceServer
Asked by angeltop on 2017-05-18 06:31:01 UTC
Okay it's working, thanks
Asked by Milow on 2017-05-19 04:38:05 UTC