Skip to content
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

Message conversion fails to convert list of integers to float32[] #764

Closed
barulicm opened this issue Jul 16, 2022 · 0 comments · Fixed by #777
Closed

Message conversion fails to convert list of integers to float32[] #764

barulicm opened this issue Jul 16, 2022 · 0 comments · Fixed by #777
Labels

Comments

@barulicm
Copy link

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:

let joy_msg = new ROSLIB.Message({ axes: [ 0.0 ] });

joy_publisher.publish(joy_msg)
  • Library Version: 1.2.0
  • ROS Version: Humble
  • Platform / OS: Ubuntu 22.04

Steps To Reproduce
python3 example.py

# example.py
from json import loads
from rosbridge_library.internal import message_conversion, ros_loader

msg_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]
@barulicm barulicm added the bug label Jul 16, 2022
jtbandes added a commit that referenced this issue Aug 16, 2022
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
Fixes RobotWebTools#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant