-
Notifications
You must be signed in to change notification settings - Fork 532
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
ros2 - Adaptaions to Eloquent #493
Conversation
- adapt rosbridge_suite to ROS2 Eloquent - increase spin period to 1000Hz to allow 1000 messages per second into the websocket - increase parsing speed of sensor_msgs/CompressedImage - add some debug messages - allow interpreting int as float when needed - better handling array.array and numpy arrays - allow bytes and str websocket messages
- adapt rosbridge_suite to ROS2 Eloquent - increase spin period to 1000Hz to allow 1000 messages per second into the websocket - increase parsing speed of sensor_msgs/CompressedImage - add some debug messages - allow interpreting int as float when needed - better handling array.array and numpy arrays - allow bytes and str websocket messages Contributors: @joshwapohlmann @mmatthe
I'm happy to merge this with a review by a ROS2 user. |
Tested and confirmed on Ubuntu 18.04 with ROS2 Eloquent. NOTE: to run, I had to tested with webviz.io resulted in a service call error. I think the service that webviz was looking for just was missing. tested on a less-complex website and it worked great. |
just tested it with dashing too...works great |
Please try removing the pip-installed pymongo package and test with apt package It looks like the webviz error would go away if the rosapi node (part of rosbridge) were running. |
followed your recommendation - uninstalled the pip pymongo and installed the apt package python3-bson. same as before, compiled and worked great. I also tried to launch the rosapi node in another terminal, however it looks like the service |
Is there something new in ROS2 where having a requirements.txt is either supported or desired? |
|
||
def populate_instance(msg, inst): | ||
""" Returns an instance of the provided class, with its fields populated | ||
according to the values in msg """ | ||
inst_type = msg_instance_type_repr(inst) | ||
if inst_type == "sensor_msgs/CompressedImage": |
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.
I'm not convinced yet that hardcoding special handling for specific message types in this module in this way is a good idea.
If the data is coming in as anything but a base64 string, it shouldn't be coming anywhere near this code path. I don't see any place where base64 decoding was added, so I don't understand how this decoder could possibly work. Can you explain how this works?
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.
I agree that this is kind of a hacky solution to shortcut decoding of CompressedImage
. At this point in the data flow, msg is a dict
containing all the fields. In particular, arrays/lists have already been decoded into python/numpy arrays. From this point in the data flow on, the only remaining thing is to translate the fields from the dict into the attributes of inst
(inst
is already the target object of the correct type). in our debugging sessions it happened that decoding of CompressedImages was extremely slow. This is due to an known problem within the python-idl mapping. Particular, inst.data = msg["data"]
would be the slow thing. Instead, it should be inst.data = array.array("B", msg["data"])
which omits the runtime check if all values are within bounds.
Since the generic decoding within populate_instance
can only do inst.data = msg["data"]
, I have included the shortcut here.
Please let me know, if I should delete it in this fork or keep it.
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 seems like this could be made into a general solution by moving it into _to_inst
with the rest of the decoding. Otherwise I would accept this hack in this PR if there is a comment linking to your comment explaining why it exists.
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.
I have created an extra file that collects shortcut decoders. Currently, it only contains a decoder for sensor_msgs/CompressedImage
. I needed that file to keep the message_conversion.py
clean. I have moved the call to these function into the _to_object_inst
Please see, if this solution is fine with you.
rosbridge_library/src/rosbridge_library/internal/message_conversion.py
Outdated
Show resolved
Hide resolved
rosbridge_library/src/rosbridge_library/internal/message_conversion.py
Outdated
Show resolved
Hide resolved
rosbridge_library/src/rosbridge_library/internal/message_conversion.py
Outdated
Show resolved
Hide resolved
rosbridge_library/src/rosbridge_library/internal/message_conversion.py
Outdated
Show resolved
Hide resolved
rosbridge_library/src/rosbridge_library/internal/subscribers.py
Outdated
Show resolved
Hide resolved
- remove extraneous print statements - remove unused packages - remove whitespace - move message conversion to str into websocket_handler
Adding a dict `shortcut_object_decoders` that contains functions that handles decoding of specific objects quicker than the generic method. remove requirements.txt Co-authored-by: joshwapohlmann <joshwa.pohlmann@barkhauseninstitut.org>
Co-Authored-by: joshwapohlmann <joshwa.pohlmann@barkhauseninstitut.org>
just tested this for foxy on ubuntu 20.04 - works there too! |
I am confused on which ros2 bridge I shall use now!? |
either one! this ones based on python and the ros2-web-bridge one is based on js. they provide similar functionality the maintainer provides an answer to this question here RobotWebTools/ros2-web-bridge#117 |
IIRC this service is provided by |
# explicitely cast to array.array to overcome a costly runtime | ||
# check within inst.data instance. | ||
# See also https://github.com/RobotWebTools/rosbridge_suite/pull/493#discussion_r425151919 | ||
inst.data = array.array("B", msg["data"]) |
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.
Is it not true that if you did this for all uint8[]
in message_conversion.py _to_binary_inst
you wouldn't need special cases for specific message types?
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.
Well, you can, in the deeply buried code where the instance is set (it'd be in _to_object_inst
and _to_list_inst
), capture if a uint8[] is set and then apply the optimization. However, this is not very clear to understand and it might be too general, as sometimes you might want to have the additional error check that is done by ROS2 idl_typesupport. Therefore, I would not recommend using this optimization generally.
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.
I don't see how maintaining unique decoder logic for specific message types is better. Everything about rosbridge is general and should remain general. If the usual decoding pathway is too slow for CompressedImage it's probably too slow for every other message that uses uint8[]
. If the additional error check can be bypassed for CompressedImage it can probably be bypassed for every other message type.
If there is an open issue about ROS2 message conversion performance somewhere else please link.
Also compiled and tested on Ubuntu 18.04.3 with ROS Eloquent. Seems to work 👍 |
Hello ! Here is the issue i opened: rctoris/jrosbridge#29 I need help pleaaaaase.... im running ros-dashing. Thanks in advance ! |
im using dashing too. but nothing works. my issue: rctoris/jrosbridge#29 need help ! |
@mmatthe if you make one more small commit on your PR branch it should trigger the new ROS2 CI for this PR. might be helpful in diagnosing if some of these fixes help solve some of the compilation issues. |
@mmatthe I've opened an additional PR in your fork for a simple addition to this PR regarding @mvollrath Is the only outstanding issue holding up the approval of this PR related to the addition of the shortcut decoders in If so, is there any way we can move that portion to a separate PR for further discussion? There are some other fixes in this branch that address some currently broken functionality in the base branch, and it'd be nice to see this merged. |
Yes. |
Is there any way we can just comment/remove the two offending lines relating to checking for / returning a shortcut decoder, and potentially discuss their reintroduction in a different PR if desired? It'd be nice to see the majority of this moved into the I don't want to clutter things and open a new PR containing most of these same changes with this PR still open, but it seems @mmatthe might not be actively monitoring this PR right now. |
@mvollrath its seems that the change request was already proceeded. Please check object_decoders.py. |
@mvollrath I've removed the offending |
@mvollrath It looks as though this has sat abandoned by the original author for almost a year and can be closed thanks to #533 |
During usage of the ROS2 branch of the rosbridge_suite, several problems occured in the Python Code. These were fixed such that it works for our use case. The overview of the changes: