How to launch RVIZ from Matlab?

14 views (last 30 days)
Hi,
I'd like to launch RVIZ from Matlab. RVIZ runs in a separated window and will be started using the system command.
The following line runs on the Linux shell:
rviz rviz -d runMyRvizLaunchFile.rviz
It opens RVIZ and visualized the topics as expected.
In Matlab I execute
[status,cmdout] = system('rviz rviz -d runMyRvizLaunchFile.rviz');
disp(['cmdout: ' cmdout(1: end-1) ' status: ' num2str(status)])
the output on Matlab shell is:
cmdout: execute 'runMyRvizLaunchFile.rviz' on myPC
rviz: /usr/local/MATLAB/R2021a/bin/glnxa64/libQt5Widgets.so.5: no version information available (required by rviz)
rviz: /usr/local/MATLAB/R2021a/bin/glnxa64/libQt5Core.so.5: no version information available (required by rviz)
rviz: /usr/local/MATLAB/R2021a/bin/glnxa64/libQt5Gui.so.5: no version information available (required by /opt/ros/melodic/lib/librviz.so)
rviz: /usr/local/MATLAB/R2021a/bin/glnxa64/libQt5Core.so.5: no version information available (required by /opt/ros/melodic/lib/librviz.so)
rviz: /usr/local/MATLAB/R2021a/bin/glnxa64/libQt5Core.so.5: no version information available (required by /opt/ros/melodic/lib/librviz.so)
rviz: /usr/local/MATLAB/R2021a/bin/glnxa64/libQt5Widgets.so.5: no version information available (required by /opt/ros/melodic/lib/librviz.so)
rviz: /usr/local/MATLAB/R2021a/bin/glnxa64/libcurl.so.4: version `CURL_OPENSSL_4' not found (required by /opt/ros/melodic/lib/libresource_retriever.so)
rviz: /usr/local/MATLAB/R2021a/bin/glnxa64/libtiff.so.5: no version information available (required by /usr/lib/x86_64-linux-gnu/libfreeimage.so.3)
runMyRvizLaunchFile.rviz executed status: 0
How to trigger a Lauch script for RVIZ from Matlab?
Thanks for your help!

Accepted Answer

Cam Salzberger
Cam Salzberger on 27 Jul 2021
Hello Andreas,
My suspicion of what is happening here is library path conflict. ROS Toolbox ships with ROS libraries, which probably overlap with the libraries that rviz uses. When you start MATLAB, the environment within MATLAB is setup to have MATLAB's libraries on the environment path. If you compare the environment variables from inside of MATLAB with those from a standard terminal, you can see the difference.
I would generally suggest starting rviz from outside MATLAB. If your workflow requires that it is started from within MATLAB, you could temporarily set the relevant environment variables to hardcoded values that are copied from outside of MATLAB, call the system command to start rviz, then reset the environment variables to their original values. The variables I would look at first are PATH and LD_LIBRARY_PATH, though there may be others.
Something like this:
% Prepare to reset the environment to MATLAB's current values
inMATLABPath = getenv("PATH");
inMATLABLDPath = getenv("LD_LIBRARY_PATH");
cleanPath = onCleanup(@() setenv("PATH", inMATLABPath));
cleanLDPath = onCleanup(@() setenv("LD_LIBRARY_PATH", inMATLABLDPath));
% Set environment to match outside of MATLAB
setenv("PATH", outsideMATLABPath)
setenv("LD_LIBRARY_PATH", outsideMATLABLDPath)
% Start rviz
[status,cmdout] = system('rviz rviz -d runMyRvizLaunchFile.rviz');
% Reset environment to default
clear cleanPath cleanLDPath
-Cam

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!