ROS 2 runs obviously less efficient with custom message than with build-in message
Show older comments
Hello,
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().
Reproduce:
- 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
tic
for i=1:10
ros2message(build_in_msg);
end
toc % -> Elapsed time is 0.005391 seconds.
tic
for i=1:10
ros2message(custom_msg);
end
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.)
Best,
Jianye Xu
Accepted Answer
More Answers (0)
Categories
Find more on ROS Network Access in MATLAB 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!