MATLAB Answers

How can ROS Custom Messages be exchanged or even moved to another folder?

6 views (last 30 days)
The task seems simple:
Generate ROS Custom Message for a ROS Package and copy it to other machines, so that my students don't have to go through with generating the custom message by their own. Before R2020b it was no problem. We generated the message definitions by the separate toolbox and could exchange the created folder with it's message definitions. Since R2020b has build in support for generating ROS custom messages I can't even move the generated folder on the same PC.
What System is used: Ubuntu 20.04, Matlab R2020b
Workflow:
I generate my message type by starting Matlab with:
LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6:/usr/lib/x86_64-linux-gnu/libcurl.so.4" matlab
(LD_PRELOAD is needed, because cmake is not working with std-libs provided by the Matlab version.)
Using rosgenmsg(...) is working and I can use:
addpath(...);clear classes;rehash toolboxcache;
rosmessage('...') is giving me my custom message object.
Restarting Matlab and using addpath again still works for getting my object.
Now I simply rename the generated "matlab_msg_gen_ros1" folder into "matlab_msg_gen_ros1_"
After restarting Matlab and using addpath(...);clear classes;rehash toolboxcache; with the modified path, the message type is not recognized by Matlab anymore.
(Now, even renaming the folder back into the old name and using the old path for addpath ... is not working anymore. Only if I redo the rosgenmsg procedure, it is working again)
Is there a way to exchange / move the generated message definition, or is there another way to export and import (share) custom message definitions?

Accepted Answer

Cam Salzberger
Cam Salzberger on 6 May 2021
Hello Sven,
The "addpath" command is only a small part of getting the custom messages working with MATLAB. It is required to register the generated M-files with MATLAB, but the libraries that get built are registered in a different way as part of the "rosgenmsg" run.
In R2020b, if you run rosgenmsg on a custom message folder, and then re-run it without changing anything, it shouldn't actually build the messages a second time. A quick check is done (on a package-by-package basis) to see if the message definitions have changed, and if not, they are simply re-registered to MATLAB.
You can take advantage of this to transfer pre-built packages between computers. Be aware that it only works when built by the same MATLAB version and on the same computer architecture (OS). If your folder structure looks like this:
custom_interfaces/
|-matlab_msg_gen_ros1/
|-package_1_msgs/
| `-msg/
| `-MyMsg.msg
`-package_2_msgs/
`-msg/
`-MyMsg2.msg
then transfer the full "custom_interfaces" folder to the other machine and run "rosgenmsg" on that folder. It won't work if the generated folder name changes from "matlab_msg_gen_ros1", as that will make it appear that messages have not been generated at all.
-Cam
  5 Comments
Cam Salzberger
Cam Salzberger on 11 May 2021
Hello Sven,
I followed up with the team, and found that I was somewhat mistaken about the way the build-check worked. Apparently it makes use of CMake and catkin (Python tool) to perform the check to see if a rebuild is required or not. So simply changing around the order of operations would make sense, since those build tools are required to see if a build is necessary.
I have opened a separate enhancement request to allow for the registration of pre-created custom messages without checking for rebuild, but it's not a trivial request. Sorry about the confusion!
-Cam

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!