Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

Remove preprended '|' from pretty-printed strings#1114

Merged
dirk-thomas merged 2 commits intoros:lunar-develfrom
christian-rauch:fix_pp_urdf
Feb 2, 2018
Merged

Remove preprended '|' from pretty-printed strings#1114
dirk-thomas merged 2 commits intoros:lunar-develfrom
christian-rauch:fix_pp_urdf

Conversation

@christian-rauch
Copy link
Copy Markdown
Contributor

Calling:
rosparam get -p /robot_description > robot.urdf
results in a malformed URDF file because it contains a prepended | in the first line.
E.g.:

$ cat robot.urdf | head -n2
|
  <?xml version="1.0" ?>

What is the | used for?

@gavanderhoorn
Copy link
Copy Markdown
Contributor

What is the | used for?

it's standard yaml and is used to indicate that the text following it should be interpreted as one single multi-line scalar value (from here).

Not sure whether that can be removed from there, as it would probably break things that need that | there to correctly parse the output.

@christian-rauch
Copy link
Copy Markdown
Contributor Author

Why is the output interpreted as YAML? The parameter robot_description was originally parsed from an XML file. Fetching the parameter should reproduce the exact file content.

Can someone give an example for the case that removing the pipe | would break documented behaviour?

@gavanderhoorn
Copy link
Copy Markdown
Contributor

gavanderhoorn commented Jul 29, 2017

yaml is used all over ROS. In essence, the parameter server is a large yaml dict. Exporting parameters is also done as yaml, so that the output can be loaded onto the parameter server again.

The wiki page for rosparam also notes this:

rosparam contains the rosparam command-line tool for getting and setting ROS Parameters on the Parameter Server using YAML-encoded files.

This PR would seem to break that documented behaviour.

@christian-rauch
Copy link
Copy Markdown
Contributor Author

The removal of the | should only effect the pretty printing, not the usual import/export of parameters. Is pretty printing used within the parameter server?
E.g. is there an example where _rosparam_cmd_get_param is called with pretty=True?

@gavanderhoorn
Copy link
Copy Markdown
Contributor

I have no idea. Pretty printing is stated to be "not yaml safe", so perhaps the | could be removed there.

@dirk-thomas
Copy link
Copy Markdown
Member

I can only speculate what the pretty print was intended for when it was originally implemented. This code area hasn't been touched for many years.

In case rosparam get -p is being called with an argument identifying a dictionary of parameters the output is still going to be yaml-style. But for your case of printing one specific parameter I think it is safe to assume that the caller isn't expecting yaml since then he would have called it without the pretty print option. Therefore I think it is ok to remove the pipe as being done in the current patch.

But I would argue that the output shouldn't add the two space indentation for values with newlines either. Instead the value should be printed as is. Does that sounds reasonable? If yes, please update the PR to remove the if block (line 269-273 in the original file).

@christian-rauch
Copy link
Copy Markdown
Contributor Author

I agree, the printed value should be the original without indentation.
I removed the indentation and rebased on lunar-devel.

@dirk-thomas
Copy link
Copy Markdown
Member

Thank you for the patch as well as the quick update.

@dirk-thomas dirk-thomas merged commit 1074ad2 into ros:lunar-devel Feb 2, 2018
@christian-rauch christian-rauch deleted the fix_pp_urdf branch February 2, 2018 18:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants