0
$\begingroup$

Rosanswers logo

What's the correct syntax for performing a service call from the command line in ROS2 ?

Consider the following service, defined in example_interfaces package

AddTwoInts.srv

int a
int b
---
int c

Assuming that the server is called "add_two_ints"

I managed to pass one argument to the service call in the following way

$ ros2 service call /add_two_ints example_interfaces/AddTwoInts "a: '1'"        
requester: making request: example_interfaces.srv.AddTwoInts_Request(a=1, b=0)

How to pass also the second argument ?

These are not working

$ ros2 service call /add_two_ints example_interfaces/AddTwoInts "a: '1'b:'2'"
$ ros2 service call /add_two_ints example_interfaces/AddTwoInts "a: '1' b:'2'"
$ ros2 service call /add_two_ints example_interfaces/AddTwoInts "a: '1', b:'2'"
$ ros2 service call /add_two_ints example_interfaces/AddTwoInts "a:'1'" "b:'2'"
$ ros2 service call /add_two_ints example_interfaces/AddTwoInts "a:'1'", "b:'2'"

Originally posted by alsora on ROS Answers with karma: 1322 on 2018-08-31

Post score: 3

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You need to pass a string which is valid YAML, e.g.:

ros2 service call /add_two_ints example_interfaces/AddTwoInts "{a: 1, b: 2}"

Originally posted by Dirk Thomas with karma: 16276 on 2018-08-31

This answer was ACCEPTED on the original site

Post score: 3

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.