You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
When trying to populate a ROS message that includes a float32[] field, if the JSON data for that field is a list of integer values, the conversion raises an error instead of converting the integer values to floats.
This can become problematic when the library on the JS side decides to truncate float values, such as with this:
# example.pyfromjsonimportloadsfromrosbridge_library.internalimportmessage_conversion, ros_loadermsg_inst=ros_loader.get_message_instance('sensor_msgs/Joy')
msg_json=loads('{ "header": { "stamp": { "sec": 0, "nanosec": 0 }, "frame_id": "" }, "axes": [0], "buttons": [] }')
# this fails because it can't find an array of floats in [0]message_conversion.populate_instance(msg_json, msg_inst)
Expected Behavior
The conversion function should be able to convert the array of "ints" into a float32 array.
Actual Behavior
The following error is raised:
Traceback (most recent call last):
File "/home/matt/example.py", line 8, in <module>
message_conversion.populate_instance(msg_json, msg_inst)
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosbridge_library/internal/message_conversion.py", line 177, in populate_instance
return _to_inst(msg, inst_type, inst_type, inst)
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosbridge_library/internal/message_conversion.py", line 294, in _to_inst
return _to_object_inst(msg, rostype, roottype, inst, stack)
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosbridge_library/internal/message_conversion.py", line 399, in _to_object_inst
setattr(inst, field_name, field_value)
File "/opt/ros/humble/local/lib/python3.10/dist-packages/sensor_msgs/msg/_joy.py", line 165, in axes
assert \
AssertionError: The 'axes' field must be a set or sequence and each value of type 'float' and each float in [-340282299999999994960115009090224128000.000000, 340282299999999994960115009090224128000.000000]
The text was updated successfully, but these errors were encountered:
Fixes#764 by using `ndarray`/`array` assignment operations that accept ints as well as floats, rather than directly assigning the incoming list value, which failed at the msg/idl generated python code's validation step.
jihoonl
pushed a commit
to floatic-unicorn/rosbridge_suite
that referenced
this issue
Oct 6, 2022
FixesRobotWebTools#764 by using `ndarray`/`array` assignment operations that accept ints as well as floats, rather than directly assigning the incoming list value, which failed at the msg/idl generated python code's validation step.
Description
When trying to populate a ROS message that includes a float32[] field, if the JSON data for that field is a list of integer values, the conversion raises an error instead of converting the integer values to floats.
This can become problematic when the library on the JS side decides to truncate float values, such as with this:
Steps To Reproduce
python3 example.py
Expected Behavior
The conversion function should be able to convert the array of "ints" into a float32 array.
Actual Behavior
The following error is raised:
The text was updated successfully, but these errors were encountered: