-
Notifications
You must be signed in to change notification settings - Fork 914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[roslaunch] Add yaml type for <param> tag #1045
[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
@@ -32,6 +32,7 @@ | |||
<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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary? I don't see any part in the patch which requires it.
@@ -70,30 +70,36 @@ def convert_value(value, type_): | |||
#attempt numeric conversion | |||
try: | |||
if '.' in value: | |||
return float(value) | |||
return float(value.strip()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary. float()
already works even if the passed argument has leading / trailing spaces.
Same below.
except ValueError as e: | ||
pass | ||
#bool | ||
lval = value.lower() | ||
lval = value.strip().lower() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]
@@ -94,6 +95,8 @@ def convert_value(value, type_): | |||
elif value == 'false' or value == '0': | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: