MATLAB Answers

Distributing ROS2 compiled custom messages to other computers without needing to compile again?

1 view (last 30 days)
Peter Polidoro
Peter Polidoro on 16 Oct 2020
Answered: Robert Clarke on 23 Feb 2021
I would like to use some ROS2 custom messages with the ROS Toolbox on multiple computers. Is it possible for me to compile the messages on one computer and then distribute and use those compiled messages on other computers? I would like to avoid having to install Python, CMake, and Visual Studio on those other computers and going through the compilation process on every computer. Can I have computers with only Matlab and the ROS Toolbox installed and download compiled messages to them, add them to the Matlab path, then use them just as if they were standard messages? If this works, what are the minimum and specific files needed to distribute and use these compiled custom messages? What are the limitations, that all computers run the same operating system, for example Windows 10, and the same version of Matlab, for example 2020b? Thanks!

Answers (1)

Robert Clarke
Robert Clarke on 23 Feb 2021
I made a script, copied in below, from the cut-down internals of ros2genmsg, The script should go in the original folder passed to ros2genmsg (i.e. alongside matlab_msg_gen). Copying the whole folder originally passed to ros2genmsg to a new machine and running the script should add updated paths for that machine.
It appears to be sufficient for letting MATLAB know about the messages. There is probably more that can be cut from the build space to reduce deployment size but I haven't explored that.
% Selectively copied from ros2genmsg
% Get current folder name
[folderPath,~,~] = fileparts(mfilename('fullpath'));
% Get generated file directory
genDir = fullfile(folderPath, 'matlab_msg_gen', computer('arch'));
% Get the directories that contain the messages that have been built
pkgDirs = ros.internal.custommsgs.getPkgDirs(folderPath);
% Get the msg files
pkgInfos = cell(1,numel(pkgDirs));
pkgMsgFiles = ros.internal.custommsgs.checkValidityOfMessages(pkgDirs,folderPath,'ros2', pkgInfos);
% Generate msgFullName list
msgFullName = {};
for iPkg = 1:numel(pkgDirs)
msgFiles = pkgMsgFiles{iPkg};
for iMsg = 1:numel(msgFiles)
[~, msgName] = fileparts(msgFiles(iMsg).name);
msgFullName{end+1} = [pkgDirs{iPkg} '/' msgName]; %#ok<SAGROW>
% Add the messages to the toolbox registry

Community Treasure Hunt

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

Start Hunting!