ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
11

Call a service at startup with a launch file

asked 2011-09-21 01:02:04 -0500

Is it possible to call a service from a launch file once at startup? We want to call the service /global_localization of AMCL the first time we launch our robot.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
24

answered 2011-09-21 08:31:22 -0500

bhaskara gravatar image

updated 2021-09-14 11:42:33 -0500

lucasw gravatar image

Just have the call be its own node in the launch file:

<node pkg="rosservice" type="rosservice" name="global_loc" args="call --wait /global_localization" />
edit flag offensive delete link more

Comments

That was my first idea, too. But as Lorenz wrote above, roslaunch tends to pass additional parameters which let rosservice choke.
roehling gravatar image roehling  ( 2011-09-21 19:44:25 -0500 )edit

This worked for me, I just added that line verbatim directly under my AMCL launch line. I like this method better, it just feels right, light, and clean. :)

Dereck gravatar image Dereck  ( 2012-10-22 08:14:35 -0500 )edit

Apparently this no longer works in Groovy.... Comment here if you want this feature fixed I suppose: https://github.com/ros/ros_comm/issues/180

Dereck gravatar image Dereck  ( 2013-02-28 05:47:37 -0500 )edit
1

This works under hydro i just tested with this line of code in launch file under ubuntu 12.04: <node pkg="rosservice" type="rosservice" name="switch_ranger" args="call --wait /switch_ranger sonar_pioneer true"/>

Oscar Lima gravatar image Oscar Lima  ( 2015-05-05 07:29:54 -0500 )edit

This still works under indigo like charm!

Karsten gravatar image Karsten  ( 2015-12-18 12:21:33 -0500 )edit
2

This also works under kinetic! Thank bhaskara for the answer:)

renweiros gravatar image renweiros  ( 2017-04-28 21:32:20 -0500 )edit
1

still works in melodic

Hakaishin gravatar image Hakaishin  ( 2019-09-10 06:07:21 -0500 )edit
2

Thanks works for me in melodic , for Gazebo service,

<node pkg="rosservice" type="rosservice" name="rosservice" args="call /gazebo/reset_simulation"/>
amjack gravatar image amjack  ( 2020-12-10 06:17:16 -0500 )edit
3

answered 2011-09-21 01:39:37 -0500

updated 2011-09-21 01:40:10 -0500

I don't know how if it is possible in a clean way. A quick and dirty hack for Linux would be the misuse of the launch-prefix attribute.

In your package foo, create a file named kickstart with the content

#!/bin/bash
rosservice call --wait /global_localization &
exec "$@"

Then, make it executable using

chmod +x kickstart

Finally, add the following attribute to one of your <node> declarations in the launch file:

launch-prefix="$(find foo)/kickstart"

This will coax roslaunch into executing the kickstart script with the real node launch command line as parameters. The script performs the service call and executes the remainder of the command line, thus launching the node.

The --wait parameter ensures that the service is actually available, and the ampersand at the end of the rosservice line runs the call in the background, so the node launch will not be delayed.

edit flag offensive delete link more

Comments

I think that won't work because roslaunch passes additional parameters such as renamed topics and the node's name which causes rosservice to die with an exception. I think the only way to call the service is to not use any cmd line params in the script but put the complete command there.
Lorenz gravatar image Lorenz  ( 2011-09-21 02:11:29 -0500 )edit
That is why the kickstart script is needed. The rosservice call is completely independent of the node launch in the exec line below.
roehling gravatar image roehling  ( 2011-09-21 02:49:07 -0500 )edit
Sorry. My bad. Never mind... I didn't read your code carefully enough. :)
Lorenz gravatar image Lorenz  ( 2011-09-21 02:52:02 -0500 )edit
Thanks, it worked
Javier gravatar image Javier  ( 2011-09-21 05:52:26 -0500 )edit

Question Tools

Stats

Asked: 2011-09-21 01:02:04 -0500

Seen: 16,209 times

Last updated: Sep 14 '21