-
Notifications
You must be signed in to change notification settings - Fork 76
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
Numbers in scientific notation are not tolerated #319
Comments
Are you sure about that? $ python3 -c 'print(type(1e-9))'
<class 'float'> Also, if I take that function, put it in a file, and then call it, like the following: def check_sequence_type_is_allowed(sequence):
# Check if the items of the sequence aren't dissimilar.
# Also, check if the item type is one of bool, int, float, str.
if not sequence: # Don't allow empty sequences
return False
subtype = type(sequence[0])
if subtype not in (bool, int, float, str):
return False
for item in sequence:
if not isinstance(item, subtype):
return False
return True
print('Empty:', check_sequence_type_is_allowed([]))
print('Float:', check_sequence_type_is_allowed([1.0]))
print('Scientific:', check_sequence_type_is_allowed([1.0, 1e-9])) I get: Empty: False
Float: True
Scientific: True What's the larger problem that you are having? |
The problem is in the ROS components parameter load chain. I think (but now I will give it a try) that scientific numbers are parsed from yaml config files as strings and not floats. I encountered an error wile switching robot_localization package from being a node to being a component. Small covariances in config file (1e-9) started to throw the exception from evaluate_parameters.py |
I printed
see that 1e-9 is parsed as string in yaml? The question that arises is: is this an invalid notation in yaml files? Note: launching robot_localization as upstream (so Node, not Component) does not trigger this behaviour. |
I may have spotted the issue... the problem is with how I loaded the parameters from file to fill the dictionary to pass to ComposableNode. I close, sorry for the noise. |
Ah yeah, I see. In short, this seems to be a bug in PyYAML: yaml/pyyaml#173 . Indeed, if I run the following: python3 -c "import yaml ; print(yaml.safe_load('[1.0e-9, 1e-9]'))" I get:
|
Thanks for spotting the issue in the library! I am trying to figure it out (I work with C++ in ROS2 so I need a bit of time to figure out how to efficiently browse |
It uses PyYAML:
|
I digged in rclpy and if you pass a filepath from launch file, rclpy seems to use the rcl implementation (so bypassing PyYAML). A simple string (filepath) brings to this switch:
so it is passed "as it is" to the Node. |
launch_ros/launch_ros/launch_ros/utilities/evaluate_parameters.py
Lines 47 to 58 in 476ff34
This code rejects numeric lists containing numbers in scientific notation, like:
[1.0, 1e-9]
The text was updated successfully, but these errors were encountered: