[Documentation] [TitleIndex] [WordIndex

ROS on MATLAB

SIG Coordinators: Remo Pillat and Giampiero Campa, Topics: ROS-MATLAB and ROS-Simulink Interfaces

Mailing List:

https://groups.google.com/group/ros-sig-matlab

Official MATLAB ROS Support

Official ROS Support from MathWorks was released in January 2014. Users can create ROS nodes in MATLAB and exchange messages with other nodes on the network. This allows control of ROS-enabled robots and simulators through a convenient MATLAB interface. Building on top of the newest rosjava Hydro library, the software can be used cross-platform on Windows and Linux. It provides a MATLAB API interface for the following functionality:

A demo application controlling a simulated Turtlebot in Gazebo is available on File Exchange.

Some commercial companies also provide examples on how to use this interface:

Other Interfaces

This is a list of existing interfaces, some of which are somewhat documented and in fair working conditions. However note that the extent to which these interfaces are actually actively maintained is unknown.

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".

ros4mat

ros4mat, is an open source client/server library, developed at Laval University, which allows for a platform-independent connection between a robot (running ROS) and multiple clients (running only Matlab). The communication between servers and clients is based on standard TCP sockets, therefore the main concept is not dissimilar from the IPC bridge solution described above, except that, as argued by the authors, ros4mat is multiplatform, easier to install and use, and generally more flexible. Currently, the ros4mat node integrates eight sensor types (IMU, GPS, RGB Cameras, Laser Rangefinder, Kinect, Analog Inputs, Battery Information, and System Information).

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:

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.

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.


2024-11-16 14:38