ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Use Matlab Code within ROS

asked 2013-03-12 22:42:13 -0500

Felix Messmer gravatar image

Dear all,

I am currently investigating several methods for how Matlab code can be used within ROS.

I was able to use rosbridge to exchange data with Matlab. However, this requires a lot of ASCII-parsing on the Matlab side.

Then I found out about the possibility to package Matlab code into C++ shared libraries using the Matlab Compiler toolbox (deploytool). This would have been the ideal solution to my problem since Matlab would not need to be running and still ROS could use the Matlab functionality. However, because Matlab comes with its own Boost libraries integrated (version 1.44) it is not possible to use these shared libraries within ROS (linked against Boost version 1.46 under Ubuntu 12.04). Is there anyone else who tried to use Matlab shared libraries within ROS? And succeeded?

I also found the IPC-Bridge approach (IPC-Bridge) and TU Darmstadt's rosmatlab. However, both will need a running Matlab.

Furthermore, although IPC-Bridge solves the ASCII parsing problem, it is limited to support topic communication. Or has support for services been added already?

As to rosmatlab, linking ROS against Matlab's Boost libraries is not really suitable for my problem as I use other software packages depending on Boost as well. So it would get really nasty.

Anyway, I would like to hear about your experiences with any of the proposed solutions!

Best regards, Felix

edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted

answered 2013-03-20 05:25:36 -0500

Felix Messmer gravatar image

Thank you, Ben. I already knew about the ROS Matlab SIG.

After reading about all the various approaches, I tried to test the IPC-Bridge approach. (Most importantly because I don't want to compile ROS from source against Matlab libs ;)

Firstly, my settings are the following: I am using ROS Fuerte under Ubuntu 12.04 with Matlab R2012b

I tried to follow the installation here.

In step 4, I simplified the LD_LIBRARY_PATH since all ROS libs are now in /opt/ros/fuerte/lib. Thus, my environment variables look like this:


The compilation of ipc_bridge_ros works fine as well.

But when running

roscd ipc_roslib && make

I get the following error messages:

fxm@sony-fxm:~$ roscd ipc_roslib && make
bash -c "mkdir -p bin"
bash -c "`rospack find ipc_bridge`/ ."
Generating roslib_Header.h
mex  -I./include   -I/home/fxm/projects/miror/ipc-bridge/ipc_bridge_stack/ipc_bridge_matlab/include  -I/home/fxm/projects/miror/ipc-bridge/ipc_bridge_stack/ipc_bridge/include  -I/home/fxm/projects/miror/ipc-bridge/ipc_bridge_stack/ipc/include -I/home/fxm/projects/miror/ipc-bridge/ipc_bridge_stack/ipc_bridge/include -lstdc++ -L/home/fxm/projects/miror/ipc-bridge/ipc_bridge_stack/ipc/lib -lipc mex/ -output bin/roslib_Header

Warning: You are using gcc version "4.6.3-1ubuntu5)".  The version
         currently supported with MEX is "4.4.6".
         For a list of currently supported compilers see: 

echo  -L/opt/ros/fuerte/lib
echo  -lroscpp  -lrostime  -lrosconsole  -lroscpp_serialization  -lxmlrpcpp
-lroscpp -lrostime -lrosconsole -lroscpp_serialization -lxmlrpcpp

I can see that something is wrong with an unsupported mex-compiler within Matlab, but I don't know how to change the settings.

Has anyone worked with the IPC-Bridge under ROS-Fuerte? Does anyone know how to fix this?

And finally, is the IPC-Bridge still only supporting topic communication or has the service functionality been added yet?

Any help is appreciated!

edit flag offensive delete link more



Please, bear in mind that this site is not a forum, so you should only post answers to the original question, and NOT responding to some given answer and asking a bunch of other stuff. You should mark the answer from @ben as correct, delete your answer and create a new question, with your new doubt.

Procópio gravatar image Procópio  ( 2013-03-21 05:12:56 -0500 )edit

Procópio, your comment seems overly strict and pedantic. I appreciated Felix's follow up questions and learned something from it. If we cannot have discussions and follow up on, maybe such discussions should move back to ros-users.

odestcj gravatar image odestcj  ( 2013-03-21 07:51:32 -0500 )edit

Sorry, but it was not my intention. I am just trying to explain the proper way of using this website. Sure Felix post was interesting, but essentially he posted a question as the answer to a question. Asking a new question will trigger alerts and there is a higher chance people will see it and help.

Procópio gravatar image Procópio  ( 2013-03-21 09:07:18 -0500 )edit

I kindly suggest you read (no pedantic intended)

Procópio gravatar image Procópio  ( 2013-03-21 09:11:37 -0500 )edit

I understand. Thanks for your kind explanation. That said, I think ros-users was better for facilitating this type of discussion at the cost of search-ability and larger email inbox.

odestcj gravatar image odestcj  ( 2013-03-21 09:28:16 -0500 )edit

Procópio, to be honest (and I don't want to be rude), I am sick of reading "please use the forum" on or "please use ros-answers" on the forum! There is no contribution to the question within your comment. Sorry!

Felix Messmer gravatar image Felix Messmer  ( 2013-03-23 01:03:06 -0500 )edit

@Felix Messmer I understand. But I have not suggested you to use the ROS forum, I suggested you to create a new question with your post. I think it is well written and useful, but the benefits for the community and for you could be bigger, if it was posted as a new question. Cheers!

Procópio gravatar image Procópio  ( 2013-03-25 01:37:14 -0500 )edit

answered 2013-03-12 22:51:50 -0500

ben gravatar image

Giampiero Campa at MathWorks recently put up a well organized page documenting the different methods of communicating between Matlab & ROS here:

edit flag offensive delete link more

answered 2013-08-05 00:04:27 -0500

Ahwen gravatar image

I just thought could drop a penny of my thought here for the MEX problem. You may wish to try adding the following line to ~./bashrc

export PATH=<your path to matlab>/bin:$PATH

edit flag offensive delete link more

answered 2013-03-21 07:47:10 -0500

odestcj gravatar image

Regarding rosbridge, is your concern about ASCII parsing due to performance or implementation?

I would think there are a number of existing libraries for JSON parsing. A quick google search yielded a few options:

Regarding performance, it is obvious that a binary version of rosbridge would bring a big improvement. We have not done this in order to keep the protocol open and separate from a specific implementation. However, contributions to better support binary and compressed data in rosbridge would be very welcome.

edit flag offensive delete link more


Thank you Chad for pointing me to the JSON parsing libraries for Matlab. I just thought using the IPC-Bridge with its MEX-Files (see Link above) would save me all the parsing ;-) For the time being I implemented a parser for the required rosbridge messages within Matlab myself.

Felix Messmer gravatar image Felix Messmer  ( 2013-03-23 01:12:59 -0500 )edit

Question Tools



Asked: 2013-03-12 22:42:13 -0500

Seen: 3,341 times

Last updated: Aug 05 '13