Ask Your Question
0

Executing the service command from c++ file

asked 2016-03-09 11:17:35 -0500

anonymous user

Anonymous

updated 2016-03-09 11:19:29 -0500

Here curr_x and curr_y are the co-ordinates of the turtle

I'm getting these errors when I try to execute the following command. I would like to teleport the turtle to absolute co-ordinates using the command

kv@kv:~/krssg$ rosservice call /turtle1/teleport_absolute "x: 0.25
y: 10.68
theta: -0.7854"

but I'm getting these errors when I to invoke this command from a c++ file

Traceback (most recent call last):
  File "/opt/ros/indigo/bin/rosservice", line 35, in <module>
    rosservice.rosservicemain()
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rosservice/__init__.py", line 746, in rosservicemain
    _rosservice_cmd_call(argv)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rosservice/__init__.py", line 607, in _rosservice_cmd_call
    service_args.append(yaml.load(arg))
  File "/usr/lib/python2.7/dist-packages/yaml/__init__.py", line 71, in load
    return loader.get_single_data()
  File "/usr/lib/python2.7/dist-packages/yaml/constructor.py", line 37, in get_single_data
    node = self.get_single_node()
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/usr/lib/python2.7/dist-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/usr/lib/python2.7/dist-packages/yaml/parser.py", line 428, in parse_block_mapping_key
    if self.check_token(KeyToken):
  File "/usr/lib/python2.7/dist-packages/yaml/scanner.py", line 116, in check_token
    self.fetch_more_tokens()
  File "/usr/lib/python2.7/dist-packages/yaml/scanner.py", line 220, in fetch_more_tokens
    return self.fetch_value()
  File "/usr/lib/python2.7/dist-packages/yaml/scanner.py", line 576, in fetch_value
    self.get_mark())
yaml.scanner.ScannerError: mapping values are not allowed here
  in "<string>", line 1, column 12:
    x: curr_x y: curr_y theta: 0.785
               ^
[ INFO] [1457543780.559175654]: 

[ INFO] [1457543780.559260990]: curr_x = 1.10889 curr_y = 9.98001
[ INFO] [1457543780.559285090]: [X][Y] = 0 0
Traceback (most recent call last):
  File "/opt/ros/indigo/bin/rosservice", line 35, in <module>
    rosservice.rosservicemain()
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rosservice/__init__.py", line 746, in rosservicemain
    _rosservice_cmd_call(argv)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rosservice/__init__.py", line 607, in _rosservice_cmd_call
    service_args.append(yaml.load(arg))
  File "/usr/lib/python2.7/dist-packages/yaml/__init__.py", line 71, in load
    return loader.get_single_data()
  File "/usr/lib/python2.7/dist-packages/yaml/constructor.py", line 37, in get_single_data
    node = self.get_single_node()
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-03-10 01:47:44 -0500

updated 2016-03-10 01:49:29 -0500

According to this error message:

  yaml.scanner.ScannerError: mapping values are not allowed here
  in "<string>", line 1, column 12:
    x: curr_x y: curr_y theta: 0.785

and the invoke call that you posted as a comment on Tully's answer:

 system("rosservice call /turtle1/teleport_absolute {\"x: curr_x y: curr_y theta: 0.785\"}");

The problem is that you need to substitute the strings curr_x and curr_y in the system call for the actual x and y values (double) that you want to send.

I bet this system call works well:

 system("rosservice call /turtle1/teleport_absolute {\"x: 0.25, y: 10.68, theta: 0.785\"}");

Anyway, if you are working in C++ this is not the proper way to call a ROS service. Better take a look at this tutorial: Writing a Service Client Node

edit flag offensive delete link more
0

answered 2016-03-09 15:56:32 -0500

tfoote gravatar image

The command line arguments need to be yaml. Copy and paste of yours worked for me. But to be more explicit use the one line yaml syntax more like "{x: 5.25, y: 10.68, theta: 1.085}"

edit flag offensive delete link more

Comments

I tried the above method but I got this message

while parsing a flow mapping
  in "<string>", line 1, column 1:
    {x: curr_x y: curr_y theta: 0.785}

The invoke call was:

 system("rosservice call /turtle1/teleport_absolute {\"x: curr_x y: curr_y theta: 0.785\"}");
anonymous userAnonymous ( 2016-03-10 01:13:38 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-03-09 11:17:35 -0500

Seen: 752 times

Last updated: Mar 10 '16