ROS 2 runs obviously less efficient with custom message than with build-in message
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jianye Xu am 2 Jun. 2022
Beantwortet: Jagadeesh Konakalla am 3 Jun. 2022
I use currently ROS 2 to let agents communicate with each other. I successfully created a custom message using MATLAB function ros2genmsg() to meet my need. However, I noticed that when I used custom message, MATLAB ran significantly slower than I used build-in message. I also tested it with the custom message given in the MATLAB doc example.
Results: the execution of ros2message() with custom message type needs about 0.16 sec, while the time is less than 0.0005 sec with build-in message. The same phenomenon for ros2publisher() and ros2subscriber().
- run openExample('ros/ROS2CustomMessagesExample') in MATLAB command window
- run the opened live skript, where a custom message called "example_b_msgs/Standalone" will be created.
- run the following test code:
build_in_msg = "std_msgs/ByteMultiArray"; % build-in message
custom_msg = "example_b_msgs/Standalone"; % custom message
toc % -> Elapsed time is 0.005391 seconds.
toc % -> Elapsed time is 1.627962 seconds.
There are some ways to acoid this problem. Simplest one is that I use ros2message() only once and modify the created variable whenever I need but not call the function again.
I'm wondering if there is something I can do to let ROS 2 custom message run as efficient as build-in message.
Any help would be appreciated.
(Note: I am using MATLAB R2022a in Windows 10 with version 21H2.)
Jagadeesh Konakalla am 3 Jun. 2022
Hi Jianye Xu,
I am able to reproduce the issue that you reported.
The way custom messages are registered with MATLAB are causing this issue. By deisgn, we assumed that this function can be used only once in a script or function and not in the loop.
For now, as you mentioned, the solution i advice you to use ros2message() only once and not the call the function in loop.
Weitere Antworten (0)
Find more on ROS Custom Message Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!