launch file with nested quotes

asked 2020-04-26 06:37:46 -0500

eusebius gravatar image

updated 2020-04-26 06:49:06 -0500

I want execute the following command:

rosservice call /gazebo/apply_joint_effort "joint_name: 'joint2' effort: 10.0 start_time: secs: 0 nsecs: 0 duration: secs: 10 nsecs: 0"

I can type this in the command line and everything works fine. Now suppose I need to execute this command not from terminal but from a launch file. I think I have to write something like this in my .launch file

<launch>

    <node pkg="rosservice" type="rosservice" name="torque" args=
    call /gazebo/apply_joint_effort "joint_name: 'joint2'
    effort: 10.0
    start_time:
    secs: 0
    nsecs: 0
    duration:
    secs: 10
    nsecs: 0" />

</launch>

Of course in this way I have a mistake, because I should put quotes at the beginning and at the end of args. However I don't know how to do, since neither single quotes nor double quotes are available any more. If I add a couple of single/double quotes at the beginning and end it doesn't work. Any suggestions?

edit retag flag offensive close merge delete

Comments

1

Strings don't need quotes in YAML (which is what the args essentially are) unless they contain spaces and it's unclear/ambiguous for the parser (ie: it cannot determine it from the context) where a string ends or starts.

So your joint2 does not need quotes.

gvdhoorn gravatar image gvdhoorn  ( 2020-04-26 07:01:39 -0500 )edit

Thanks gvdhoorn, this was helpful, but does not solve my problem completely. If I just remove quotes from 'joint2' I get the following error

yaml.scanner.ScannerError: mapping values are not allowed here
  in "<string>", line 1, column 30:
    joint_name: joint2     effort: 10.0     start_time:       sec ...

Judging from this post I think it is an indentation problem, I tried several solution changing the spacings and the indentations but I always get errors.

As an example I add one of the versions of the launch file with changed indentations which did not work.

<launch>

    <node pkg="rosservice" type="rosservice" name="torque" args='call /gazebo/apply_joint_effort "joint_name: joint2
    effort: 10.0
    start_time:
      secs: 0
      nsecs: 0
    duration:
      secs: 10
      nsecs: 0"'/>

</launch>
eusebius gravatar image eusebius  ( 2020-04-26 09:07:53 -0500 )edit
1

As I wrote earlier, it's all yaml. It's likely the parser is confused as in the end it just sees a long string (with a lot of whitespace) and a lot of illegal key:value combinations outside of a map. That's most likely the cause of the "mapping values not allowed here".

I'd try the following syntax (called a "flow map"):

{ joint_name: joint2, effort: 10.0, start_time: { secs: 0, nsecs: 0 }, duration: { secs: 10, nsecs: 0 } }

Note: this is all just a single line. There are no line-breaks nor indenting.

gvdhoorn gravatar image gvdhoorn  ( 2020-04-26 10:32:27 -0500 )edit

Now it works, thanks a lot!! :)

eusebius gravatar image eusebius  ( 2020-04-26 10:47:40 -0500 )edit

Note that at least #q265816 is a duplicate of your question.

gvdhoorn gravatar image gvdhoorn  ( 2020-04-26 10:50:04 -0500 )edit