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

Calling ROS services in Python using yaml notation for the parameters?

asked 2011-08-08 21:12:29 -0500

pparescasellas gravatar image

updated 2014-01-28 17:10:10 -0500

ngrennan gravatar image

Hey everybody! I was wondering if it was possible to call a ROS service from within a python node using YAML notation for the parameters like the console tool rosservice. Something like:

rosservice call /add_two_ints '{a:1, b:2}'

But from within a python node:

add_two_ints = rospy.ServiceProxy( 'add_two_ints', AddTwoInts )
add_two_ints( "{a:1, b:2}" )

I already know that the following is possible, but it's not what I'm looking for:

add_two_ints( a=1, b=2 )

Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-08-09 06:08:19 -0500

kwc gravatar image

No, but the Python yaml module is very easy to use and will convert the yaml notation into a form suitable for Python.

In [5]: yaml.load("{a: 1, b: 2}")
Out[5]: {'a': 1, 'b': 2}

similarly, the add_two_ints( a=1, b=2 ) form is equivalent to

d = {'a': 1, 'b': 2}
add_two_int(**d)

NOTE: the keyword-form is not recursive

edit flag offensive delete link more

Comments

Oh great! I'll give it a try, thanks ;)
pparescasellas gravatar image pparescasellas  ( 2011-08-10 02:38:06 -0500 )edit
Is it possible to call the service without specifying the service message name? I'm trying to do a generic service caller and that's why I wanted to send parameters in yaml-format. I'd like to be able to call any service by just knowking the service name and the yaml parameters
pparescasellas gravatar image pparescasellas  ( 2011-08-10 03:04:19 -0500 )edit
You can look at the source code for rosservice, which is in Python.
kwc gravatar image kwc  ( 2011-08-10 04:02:50 -0500 )edit

Question Tools

Stats

Asked: 2011-08-08 21:12:29 -0500

Seen: 893 times

Last updated: Aug 09 '11