This tutorial demonstrates how to get the MATLAB mobile robotics toolkit for ROS to run on a linux workstation. In this tutorial we show how to get the Range-Only EKF-SLAM algorithm to run.

Our example will use the default turtlebot packages and the gazebo simulator to run a virtual simulation of range only SLAM.

Install ROS and ROS Turtlebot and Gazebo Packages

First you must Install ROS.

You must then install the ROS turtlebot packages. The screenshot below shows the key packages to install to make the necessary turtlebot packages available. You can install these packages using synaptic, aptitude or one of the other apt package management interfaces (Ubuntu Software Center) etc.

Install MATLAB

Update MATLAB's ROS Messages

All versions of MATLAB to date (up to R2017b) include outdated versions of the ROS message files. As such, MATLAB can only communicate with Gazebo for very old versions of ROS, e.g., ROS Hydro which went out of support in 2015. This is both a nuisance and ridiculous. It turns out that MATLAB uses Java to communication with ROS. Specifically, MATLAB includes a version of the rosjava library and the specific library causing this incompatibility is the rosjava_message.jar library.

In this section we describe how to replace the rosjava_message.jar library that MATLAB uses to interact with other ROS nodes. In doing so, we update the messages and make MATLAB compatible with newer versions of ROS and incompatible with older versions of ROS.

To replace the library, do the following:

Locate your matlab ros msg definitions jar:

Windows: (usually C:\Program Files\Matlab\R2016a\java\jarext\rosjava\rosjava_messages.jar).

Linux: (usually /usr/local/bin/MATLAB/R2016a/java/jarext/rosjava/rosjava_messages.jar).

Rename rosjava_messages.jar to rosjava_messages_old_jar. NOTE THE RENAMED FILE CANNOT END IN .jar or this will not work!

Download the rosjava_messages.jar file below and copy into the folder listed above as appropriate to your platform.


You can re-compile your own versions of the ROS messages if you like (details are here rosjava).

Create a script to run the Gazebo Turtlebot simulator

Create the restart_gazebo.sh shell script. This should be a text file with the contents shown below.

#export XAUTHORITY=/home/user/.Xauthority
#export DISPLAY=:0.0
source /opt/ros/kinetic/setup.bash
export ROS_IP=$(ifconfig wlp1s0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}')
#export TURTLEBOT_3D_SENSOR="hokuyo"
roslaunch turtlebot_gazebo turtlebot_world.launch

There are 2 possible edits you may need to introduce to customize this shell script to your specific computer:

  1. You may need to change “kinetic” to “lunar” or whatever distribution of ROS you are using.
  2. You may need to change “wlp1s0” to the device name of your network card. To see the device name of your network card run the command below and replace the wlp1s0 with the network device name you see when you run this command on your computer.
$ ifconfig -a
lo        Link encap:Local Loopback  
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:24503738 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24503738 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:124825172423 (124.8 GB)  TX bytes:124825172423 (124.8 GB)

wlp1s0    Link encap:Ethernet  HWaddr 00:db:df:dc:02:3a  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::6bb3:31e1:4c13:8aa7/64 Scope:Link
          RX packets:983283 errors:0 dropped:0 overruns:0 frame:0
          TX packets:746815 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:565862557 (565.8 MB)  TX bytes:161584716 (161.5 MB)

Make the text file an executable script by executing the following command in a shell.

shell$> chmod 755 restart_gazebo.sh

You should now be able to run the Gazebo simulator and create a default world containing several objects including a turtlebot (small black object), garbage bin (large green object), Jersey barrier (large grey object) and other objects. The Gazebo simulator software sends simulated sensor data to MATLAB via ROS network messages and responds to MATLAB ROS commands sent to it via ROS network messages.

Start the Gazebo simulator using your new script as shown below from the shell/console.

$ ./restart_gazebo.sh

Run the MATLAB Range Only EKF SLAM Code

Download the zip file below and extract it into a folder.


  1. Run MATLAB.
  2. Open the RSSI_ROSGUI_ROSLAM.m file in MATLAB
  3. Run RSSI_ROSGUI_ROSLAM.demo at the MATLAB console prompt.

Here's a video of how it runs on my Linux laptop:

YouTube Link

When you run a simulation you will have to shutdown MATLAB's ros node and restart gazebo. Do this as follows:

  1. In MATLAB run “rosshutdown” at the MATLAB console prompt.
  2. In your shell window running Gazebo, i.e., the “restart_gazebo.sh” script. Press Ctrl-C to kill the application. Then re-run the application by initiating the “./restart_gazebo.sh” command. This can be done more quickly by pressing the “Up arrow” key and then pressing the “Enter” key.
  3. In MATLAB re-run “RSSI_ROSGUI_ROSLAM.demo” at the MATLAB console prompt.
range-only_slam_from_matlab_using_ros_and_the_gazebo_simulator.txt · Last modified: 2018/03/16 00:34 by arwillis