yaml error in rosservice call

asked 2018-07-02 03:06:39 -0500

JayDe gravatar image


I have a service defined as:

string name                       
uint8 some_int                  
string a_file                            
string[] array_of_strings 
float32[] array_of_floats   
float32[] array_of_floats_two
bool successful

And I am not able to call this service directly from the command line when array_of_strings is supposed to contain more than one string. Here is an example call:

rosservice call /my_service 'a_name' 1 '/blub/myfile.txt' ['string1', 'hey'] [20,2] [33,4]

This gives me the error:

Traceback (most recent call last):   File "/opt/ros/kinetic/bin/rosservice", line 35, in <module>
    rosservice.rosservicemain()   File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosservice/__init__.py", line 746, in rosservicemain
    _rosservice_cmd_call(argv)   File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosservice/__init__.py", line 607, in _rosservice_cmd_call
    service_args.append(yaml.load(arg))   File "/home/accm/.local/lib/python2.7/site-packages/yaml/__init__.py", line 71, in load
    return loader.get_single_data()   File "/home/accm/.local/lib/python2.7/site-packages/yaml/constructor.py", line 37, in get_single_data
    node = self.get_single_node()   File "/home/accm/.local/lib/python2.7/site-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()   File "/home/accm/.local/lib/python2.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)   File "/home/accm/.local/lib/python2.7/site-packages/yaml/composer.py", line 82, in compose_node
    node = self.compose_sequence_node(anchor)   File "/home/accm/.local/lib/python2.7/site-packages/yaml/composer.py", line 110, in compose_sequence_node
    while not self.check_event(SequenceEndEvent):   File "/home/accm/.local/lib/python2.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()   File "/home/accm/.local/lib/python2.7/site-packages/yaml/parser.py", line 495, in parse_flow_sequence_entry
    return self.parse_flow_node()   File "/home/accm/.local/lib/python2.7/site-packages/yaml/parser.py", line 268, in parse_flow_node
    return self.parse_node()   File "/home/accm/.local/lib/python2.7/site-packages/yaml/parser.py", line 371, in parse_node
    token.start_mark) yaml.parser.ParserError: while parsing a flow node expected the node content, but found '<stream end>'   in "<string>", line 1, column 10:

What am I doing wrong? Thanks in advance :)

edit retag flag offensive close merge delete



I would not expect this to work, as the shell interpreter will probably not like the [, ] and , in the command line there.

If you use tab-completion after /my_service, you should get a template that you can fill in.

gvdhoorn gravatar imagegvdhoorn ( 2018-07-02 03:10:47 -0500 )edit

Alternatively, you could use in-line yaml enclosed in the proper (amount and type of) quotes.

See wiki/rostopic - rostopic pub for some examples (especially the cmd_vel example at the end of the section).

gvdhoorn gravatar imagegvdhoorn ( 2018-07-02 03:11:52 -0500 )edit

Thanks, I opted for tab-completion. Even though I still do not quite understand why this does not work, since it works, when my fourth parameter just includes a single string...so I guess it has to do with the ,

JayDe gravatar imageJayDe ( 2018-07-09 03:26:18 -0500 )edit