ROS on MATLAB
Contents
Temporary SIG Coordinator: Giampiero Campa Topics: ROS-MATLAB and ROS-Simulink Interfaces
Mailing List:
https://groups.google.com/group/ros-sig-matlab
Existing Interfaces
This is a list of existing interfaces, most of which are somewhat documented and in fair working conditions.
IPC Bridge
IPC Bridge, developed originally by Nathan Michael and packaged up by Ben Cohen at UPenn (last updated on March 2013). It is an inter-process communication layer that allows MATLAB and ROS to communicate. It is mature and relatively well documented, but installation requires several steps. Roughly speaking the limitations of this approach are due to the fact MATLAB and ROS just talk to each other but are not really "integrated".
Java MATLAB Bridge
The Java_MATLAB_Bridge, developed by Tingfan Wu at UCSD (last updated on October 2012). This is based on rosjava. Specifically some rosjava JAR files are repackaged so that they can be invoked directly from MATLAB. The result is a easy-to-use cross-platform ros_matlab_bridge. This approach leads to a much closer integration between MATLAB and ROS. Total platform independence, ROS automatic java code generation for messages and topics, and the fact that java datatypes are converted and available in the MATLAB workspace automatically are just some advantages of this approach.
The MEX Approaches:
A different approach is to write mex files that wrap up ROS C-APIs. However, the versions of dynamic libraries (eg. boost) and compilers (gcc) used by ROS are different and incompatible from those shipped with MATLAB. This causes compile-time and runtime errors. An obvious solution is to rebuild ROS with the same version of GCC/DLLs used by Matlab. Along these lines there are 3 different attempts:
rosmatlab
Johannes Meyer at TU Darmstadt has developed a rosmatlab package (last updated on May 2013, and also described here). With this package, it only takes minutes to download the necessary boost headers and download and install groovy from source (using catkin) into a subfolder of the Matlab root directory with the BOOST_ROOT/BOOST_INCLUDEDIR/BOOST_LIBRARYDIR variables set correctly. This allows code built on top of roscpp to be compiled against the MATLAB/Mex libraries.
MATLAB/Mex Tools
Edward T. Kaszubski at USC has developed a package called MATLAB/Mex Tools (updated in November 2011, so perhaps it's not being maintained anymore), which uses CMake to allow for easy compilation against the MATLAB/Mex libraries (from an existing MATLAB installation). A C++ wrapper around the mxArray data type and a simple ROS/Mex bridge that allows for ROS messages to be sent and received within a Mex file are also included.
The manual approach at MPI
Finally, Martin Riedel, (working for the Antonio Franchi's Group at the Max Planck Institute in Tübingen, Germany) had some success, (previous attempts are also described here).
Reading ROS Bags in MATLAB
matlab_rosbag is a small library (last updated in May 2013) which lets you read ROS bags in MATLAB. This library (also described here) is intended to replace the one-off python / C++ programs / shell scripts that one has to write to analyze or play data inside MATLAB. The library wraps the C++ rosbag API and therefore it supports bag file format 1.2 and later, including things like reading compressed messages. Message instances are converted to MATLAB structs using the message definitions contained within the bag.
Note that ROS doesn't need to be installed on the system to use the library, (you just need to download a mex function and a matlab class file).
Other possible approaches (speculative)
This part lists other possible approaches that one could use towards interfacing MATLAB and ROS:
Code Generation from MATLAB/Simulink
It is possible (and actually it is common practice in the control community) to generate C code from Simulink, for different target hardware and operating systems. On a Linux installation, the Simulink Coder can generate C code and compile it as a Linux executable using the generic GRT and ERT Targets (integrating the Embedded Coder with Eclipse allows even more flexibility).
This allows the possibility of creating a Simulink model which, when compiled into a Linux executable, can fully connect to ROS. Note that this approach is different from the point #3 above because the connection to ROS does not happen during the simulation of the model, but when the executable generated by the model is run. This is how, for example, the orocos-simulink-toolbox integrates Simulink with OROCOS.
It is important to note that, differently from a mex file (which must work within Simulink), the executable generated by the Simulink Coder does not need to connect to Simulink at all and does not have to link to the same dynamic libraries used by MATLAB, therefore sidestepping many problems faced by the approach #3.
A guide that explain how to build blocks that, when compiled, perform target-specific operations is here.
Rosbridge
It should be possible to use the Rosbridge suite to interface MATLAB and ROS, and a few groups (including for example Felix Meßmer of the Fraunhofer IPA) plan to attempt this, but nothing is available yet as far as I know.
A Native MATLAB API (?)
Ideally, a native MATLAB API would also allow ROS utilities to be written and used natively in MATLAB/Simulink, so that essentially MATLAB could be added to the ROS API List. Whether this can be easily done or if it even makes sense (as opposed to, for example, using rosjava or roscpp within MATLAB as in approaches 1.2 and 1.3 above) is still not entirely clear at this point.
Use Cases and Requirements
Interested in an interface between ROS and MATLAB ? What is your "use case" ? What are you trying to accomplish ? More generally, what are in your opinion the requirements that such an interface should fulfill ?
Please feel free to share your thoughts either in the mailing list or in a private email to the coordinator of this page.
Robotics software developer positions available with MathWorks
MathWorks (maker of MATLAB and Simulink) is hiring a Robotics Software Developer, which will "develop new technologies that translate MATLAB and Simulink designs to run on robotics platforms such as Robot Operating System (ROS), LEGO MINDSTORMS NXT, and VEX".






