code-iai / ROSIntegration

Unreal Engine Plugin to enable ROS Support
MIT License
411 stars 133 forks source link

Faster binary messages with cbor? #61

Open jteuber opened 5 years ago

jteuber commented 5 years ago

As outlined in https://github.com/RobotWebTools/rosbridge_suite/issues/370 I have some problems when sending a large amount of messages with arrays as they need to be encoded and decoded. In the above issue, one of the contributors of rosbridge suggested trying the cbor compression that was recently added to the development branch of rosbridge. As far as I can see, cbor seems like it would be a good adition to ROSIntegration. Over at http://cbor.io/impls.html they have links to quite a lot of different cbor libraries to pick from. Depending on how much work it would take I'm very interested in (helping to) add cbor to ROSIntegration or create a fork using cbor. I'm well aware that all messages would need new de- and encoding code and that the communication with the rosbridge has to be reworked.

So, tl;dr, my question is, how much work would it take to change the encoding of the messages in the backend of ROSIntegration? Does it need any work at all? In theory, if all message-converters are rewritten, it's mostly a question of configuring rosbridge differently, isn't it?

Sanic commented 5 years ago

Hi!

Interesting find, i also thought about using CBOR, but didn't use it because the libraries weren't so well available like (hopefully) nowadays when i started this project. Before going this step, it would be interesting to repeat the experiments from RobotWebTools/rosbridge_suite#370 and compare them against BSON to see how much processing time it would actually save. I don't know what is meant with "When I evaluated BSON for binary ROS messages I found that the JS decoder was very slow and the message size was larger than JSON." in the mentioned PR, as the JS decoder/encoder shouldn't be called when using bson_only_mode.

Regarding your argument "every value is prefixed with the index": You could try to use the "binary" type of BSON. Then you shouldn't need to prefix every list element.

Converting to CBOR would roughly be a two-step process: 1) Extending https://github.com/Sanic/rosbridge2cpp/ to support CBOR . ROSIntegration uses a copy of this project, but in this repo you have the code separated and you can use it outside of unreal 2) Exchange the ROSIntegrationInstance handling to support CBOR

You are right, all the message converts have to be changed to support CBOR, as the data retrieval and setting methods differ quite a lot between the different libraries.

jteuber commented 5 years ago

Hi Sanic, thanks for your fast answer! Yes, I would also like to evaluate that. I just asked in the issue in rosbridge for the evaluation code, maybe we can save some time there. I tried to use the binary type in messages instead of arrays, unfortunately when I do that, rosbridge complains that the type of the field is not the corresponding array type and discards the message. (I don't have the actual error message handy but it just wouldn't take it as binary).