[roslaunch] Add yaml type for <param> tag#1045
Conversation
|
I dig it. I've wanted something like this for ages. |
4105d70 to
ef0dee9
Compare
ef0dee9 to
b746f71
Compare
tools/roslaunch/package.xml
Outdated
| <run_depend version_gte="1.13.3">rosunit</run_depend> | ||
|
|
||
| <test_depend>rosbuild</test_depend> | ||
| <test_depend>rospy</test_depend> |
There was a problem hiding this comment.
Why is this necessary? I don't see any part in the patch which requires it.
| try: | ||
| if '.' in value: | ||
| return float(value) | ||
| return float(value.strip()) |
There was a problem hiding this comment.
This is not necessary. float() already works even if the passed argument has leading / trailing spaces.
Same below.
| pass | ||
| #bool | ||
| lval = value.lower() | ||
| lval = value.strip().lower() |
There was a problem hiding this comment.
In which case do you expect the strings true and false to have leading / trailing spaces?
| # - lazy import | ||
| global yaml | ||
| if yaml is None: | ||
| import yaml |
There was a problem hiding this comment.
Please move the import to the top of the file and avoid the conditional block.
| global yaml | ||
| if yaml is None: | ||
| import yaml | ||
| return yaml.load(value) |
There was a problem hiding this comment.
How is that represented on the parameter server? Does this store a complex type (e.g. a nested dictionary) under a single name?
There was a problem hiding this comment.
It is set like this:
% rosparam get /test1
bin_contents:
bin_I: [sharpie_accent_tank_style_highlighters, dr_browns_bottle_brush]
work_order:
- {bin: bin_I, item: sharpie_accent_tank_style_highlighters}
% rosparam get /test1/bin_contents/bin_I
[sharpie_accent_tank_style_highlighters, dr_browns_bottle_brush]
% rosparam get /test1/bin_contents
bin_I: [sharpie_accent_tank_style_highlighters, dr_browns_bottle_brush]
% rosparam get /test1/bin_contents/bin_I
[sharpie_accent_tank_style_highlighters, dr_browns_bottle_brush]
| return False | ||
| raise ValueError("%s is not a '%s' type"%(value, type_)) | ||
| elif type_ == 'yaml': | ||
| return yaml.load(value) |
There was a problem hiding this comment.
Should any yaml specific exceptions be catched here and a ValueError be raised instead?
|
Had error below: |
2d9ecb7 to
c907f36
Compare
|
I am sorry for the late response. This looks good now. Merging... Can you please add appropriate documentation for this new feature to the wiki and link to the change here. Thanks. |
|
Thank you. I reformated the paragraph a little bit and changed the note that it is only available as of Lunar atm: http://wiki.ros.org/action/info/roslaunch/XML/param?action=diff&rev2=12&rev1=11 |
* Add yaml type for <param> tag * Support type for command output of <param> tag * Add test for yaml type * Add test for identifying commandline output as types * Support yaml type with textfile for <param> * Reserve current behavior with handling strip cleanly * Revert <test_depend>rospy</test_depend>: no need * Revert no need strip() * Remove the lazy import for yaml * Raise ValueError for yaml parse error * Strip for boolean rosparam
Why?
To set dict, list string as a parameter.
This is ok if we use
<rosparam>tag, but it does not have the feature of running arbitrary commands which<param>tag has.Example
My motivation is ways to use like below:
% cat apc2015_00.json { "bin_contents": { "bin_I": [ "sharpie_accent_tank_style_highlighters", "dr_browns_bottle_brush" ] }, "work_order": [ { "bin": "bin_I", "item": "sharpie_accent_tank_style_highlighters" } ] } % cat spam.launch <launch> <param name="/test" type="yaml" command="/usr/local/bin/json2yaml $(find roslaunch)/apc2015_00.json" /> </launch> % roslaunch ./spam.launch % rosparam get /test bin_contents: bin_I: [sharpie_accent_tank_style_highlighters, dr_browns_bottle_brush] work_order: - {bin: bin_I, item: sharpie_accent_tank_style_highlighters}