ROS I/0: Getting started with Mathwork’s new ROS package for MATLAB

Part 1: Installation

This is a quick start guide for using the new ROS I/O package from Mathworks for creating ROS nodes within MATLAB and using them to communicate with other nodes in a ROS network. I am using Ubuntu 12.04 LTS with ROS Groovy and MATLAB 2013a however the process should be similar with any combination of MATLAB 2013a or 2013b, Ubuntu 12.04 or higher, and ROS Groovy or Hydro.

I’ll assume that ROS is already installed and functional. If not, installation instructions are on and so are tutorials if you are new to ROS.

First go to and download the appropriate package (glnxa64 for 64-bit Ubuntu). You will need an academic account on the Mathworks website to access the download.

Next extract the files from the zip to a convenient folder. It will contain the installer and a PDF guide.

If you’re using Ubuntu an extra package, ia32-libs, is necessary to run the installer. Use the following command in a terminal to install it:

sudo apt-get install ia32-libs

Also, enable the execute permission for the installer by navigating to the folder in Nautilus (the file browser), right clicking, and selecting Properties. In the Permissions tabs, check the box for Allow executing the file as program.

You will need the location of the root folder for MATLAB. Open MATLAB and type matlabroot and note the resulting folder location. CLOSE MATLAB BEFORE CONTINUING.

Next you will need to run the installer as root. I found the following to be easiest method. Open a terminal and run gksudo nautilus. This opens a file browser with root permissions. Navigate to the location of the installer and double click it to run.

Click through the installer, being mindful to enter the MATLAB root folder properly when prompted. More detailed instructions for this step can be in the Getting Started PDF provided by Mathworks.

Now open MATLAB and try running the following:

>> roscore = rosmatlab.roscore(11311);

If this successfully runs, you’re likely finished. If it results in an error, most likely MATLAB cannot find the files you just installed. MATLAB needs to know where both the MATLAB (.m) functions and Java libraries (.jar) are that make up the package.

The ROS I/O package has two functions to help MATLAB find the files rosmatlab_SetPath and rosmatlab_AddClassPath. 

In MATLAB make your active directory the folder containing these m-files. On my installation it is /usr/local/MATLAB/R2013a/toolbox/psp/rosmatlab.

Run the following two commands:

>> rosmatlab_SetPath(0)

>> rosmatlabAddClassPath()

This may result in the following error or one similar:

>> rosmatlab_SetPath(0)
 Error using fwrite
 Invalid file identifier. Use fopen to generate a valid file
 Error in rosmatlab_AddClassPath (line 43)
 fwrite(fid, cleanPaths);
 Error in rosmatlab_SetPath (line 14)

MATLAB is trying to write to the classpath.txt file but does not have the proper permissions. This file sets the Java static classpath for MATLAB.

To change permissions, you must navigate to the folder containing this file in a terminal. Then change the file permissions to be writable for the world. On my system the commands would be:

cd /usr/local/MATLAB/R2013a/toolbox/local

sudo chmod 666 classpath.txt

Now try running the following again in MATLAB:

>> rosmatlab_SetPath(0)

>> rosmatlabAddClassPath()

Restart MATLAB and try:

>> roscore = rosmatlab.roscore(11311);

This should succeed to start a roscore from within MATLAB. You may now interact with a ROS network from MATLAB.

Part 2 will cover nodes, publishers, and subscribers. Part 3 will dive into custom messages.

Arduino Serial Communication via Digital Pins 0 and 1 with RS232 DB9

Over the last few months since my last post, I’ve been working on new software for coordinated robot test beds (details of that effort can be found on this project page). One of  the test beds uses underwater vehicles tethered to a power supply and a computer to do feedback control.

As part of the project, I am replaced the existing custom electronics in the robots with open source alternatives. The current electronics and communication protocol are sparsely documented. With the new software system, I wanted to have the option of changing the software on the microcontroller on board the robot. The difficulty of determining how the old board worked gave me an excuse to replace the electronics.

The on board circuitry must control two 24V DC brushed motors in both directions, one 180° hobby servo, read the value from a pressure sensor, and communicate with the computer. I chose the arduino platform for a microcontroller because of its ubiquity, simplicity, and availability of accessories. Specifically, I chose the ruggeduino variant because of its over-voltage and over-current protections and things can occasionally get shorted in a wet environment. It also can source more through its 5V regulator which will be used to power the servo and pressure sensor. I chose Rugged Circuits’ Rugged Motor Shield to drive the DC motors. It comes assembled which saves me a little time when I need six of them, can handle the 24V supply, and uses DRV8801 H-bridge chips which can deliver much more current than LM293 or LM298 H-bridges typically found on motor shields.

The tethers to the robots are up to 50 feet long. Over this distance, USB communication (the typical method for Arduinos) does not work without a power boost. The two common options would be ethernet or RS232 serial. The existing tether only has six lines, only 3 of which can be used for communication, made RS232 the logical choice.

By why does RS232 communication work over long distances when USB does not? USB communicates with a voltage differential of ~3.3V between high and low while RS232 uses a differential of at least 6V and up to 50V between high and low. When a voltage is transmitted over a wire the voltage drops due to the resistance of the wire. The longer the wire the higher the drop. The larger differential in the serial communication essentially makes it easier to distinguish between high and low even if there is a voltage drop.

The pinout for RS232 communication using a DB9 port is shown in the figure. The Arduino pin 0 (Rx) should read data from pin 2 of the serial port. Arduino pin 1 (Tx) should receive from pin 3 of the serial port. The reset pin on the Arduino should read from the Data Terminal Ready. This connection is used to signal software loading over the Tx/Rx pins. Finally grounds should be connected.

RS232 DB9 Pinout from

These pins cannot be directly connected because the large voltage differential of the RS232 communication brings about a issue when communicating with an Arduino. A logical 0 or low is 0V and a 1 or high is +5V for the Arduino. The RS232 sends -3V to -25V as low and +3V to +25V for high. Thus a level shifting chip is necessary. I chose to make a circuit with the MAX232 chip because there were some in the lab. I found a circuit design online specifically for this purpose which saved me a bit of time.

RS232 DB9 communcation to Arduino with MAX232 from ArduinoDIY

Missing from this diagram is a bypass capacitor (1 or 0.1 μF) from Pin 16 of the MAX to ground. The LEDs are optional and flash during communication. Resistors R1 and R2 are also optional but they offer a little protection if you wire the circuit in correctly. I believe C1 and C3 are used as part of current pumps to reach the higher voltage levels of the RS232 port. Pins 2 and 6 of the MAX232 are output supply voltages.

There are Arduino shields that have this circuit with a DB9 connector. The tether to the robots in this application does not terminate in a standard DB9 port so it did not make sense to use one.

I prototyped the circuit using perfboard:

Prototype MAX232

I hooked it up to the robot and loaded a some code to make it a Robot Operating System node using the rosserial library. The circuit worked and I could control the robot using a joystick. The robot now has open source electronics that have vast documentation around the web. This will be useful if a future student tackle the challenge of making a robot wireless. New software can be loaded to the robot through the tether instead of having to open the pressure chamber as the old board required.

I am currently designing a custom shield to replace that mess of wires and will be sending off the files to have boards made soon.

Links of the Week

Follow me on twitter @brnd4n for notice of blog postings!

If you haven’t heard about it, someone is doing a lean startup around an online personality called FAKEGRIMLOCK (@FAKEGRIMLOCK). Video above. Background info at (

A 40 minute film on design thinking. Design “snacks” if you will. (

Using the animals’ natural swarm behavior, researchers were able to make logic gates out of CRABS! ( and PDF)

During sleep your mind arranges the information taken in during the day allowing deeper connections to made. Maybe the idea brought up in this article of a two periods of sleep with an hour awake in between of deep or creative thought is a better option than the (questionably) recommended eight straight hours. (

Links of the Week

Follow me on twitter @brnd4n for notice of blog postings!

A rant by Jason Silva that, no matter if you agree, will make you think. (

A description of trip to a Chinese electronics market. It makes me want to fly across the Pacific. (

Reasons not to be the boss and not to start a company. (

Wildly successful Kickstarter campaigns can be extremely stressful. There is a big difference between producing and shipping a few hundred units and tens of thousands of units. (

” If you don’t like choosing between horrible and cataclysmic, don’t become CEO.” A description of the stresses of running a company. (

A creative blog format and an interesting read. I like the line “Stop being an entrepremartyr.  It projects weakness and insincerity.” (

Site Updates

I completed a description of my indoor robot navigation project.

I added an introduction to servo motors to the Hacking Education page.

Links of the Week

Follow me on twitter @brnd4n for notice of blog postings!


Most of the coverage on 3D printers focuses on printing products instantly at home and issues like piracy around that application. I believe 3D printers will never produce satisfying enough products cheaply enough to justify widespread consumer adoption. The benefits will never outweigh the costs over traditional manufacturing techniques. All that said, this link shows where 3D printers will have real impact in our lives. (

I’m a big believer in design tenet form follows function. This article sums up my (negative) opinion of iOS. One of Steve Job’s biggest mistakes was hanging onto skeuomorphism too long. It made sense when users were acclimating to computers but solely functional design in the vein of Windows Phone and Windows 8 is the now and the future. (

One popular area for consumer robotics is health care assistance. Researchers from Georgia Tech published a study showing seniors were more comfortable with robots assisting with chores than they were with robots assisting with personal tasks such as grooming. (Conference paper [pdf] via

An opinion piece on how many startups are solving “trifling” problems. (

How to quick-start a product business. Simple (to describe, not in practice) steps to get a hardware product off the ground. (

Site Updates

I’ve added, a site to find overseas suppliers, and Lin Engineering, stepper motor supply, to the List of Part Suppliers.

I’ve linked the Adafruit soldering tutorial on the Hacking Education page.

Links of the Week

Follow me on twitter @brnd4n for notice of blog postings!

A swarm of quadcopters perform a show outdoors. Dealing with all of the disturbances of the outdoors makes this centralized swarm control quite impressive. ( via

An extensive article on Nerf’s design process including a cool inside look at a focus group involving kids shooting each other at close range. (

The Hitchhiker’s Guide to the Boston Tech Community. This is a fantastically useful and invaluable resource for entrepreneurs in Boston. (

Stanford is offering free online classes in computer science and entrepreneurship.  (

Site Updates

I’ve added a tutorial on added a solder mask to your home-brew PCB on the Hacking Education page.

Links of the Week

Links for two weeks! Follow me on twitter @brnd4n for notice of blog postings!


It seems like I get asked about metal 3D printing at least once a week. This article gives a look at some of the more impressive work in this area. (

Marissa Mayer is attempting to make Yahoo! run more like a startup by instilling hacker culture. (

Growth hacking is a popular buzz phrase right now. Here is what it is and how to do it with A/B testing. (

Using business tools (decision matrices!) to help you plan your career. (

If you are an entrepreneur, this is the most important link you’ll see today. A comprehensive list of startup resources. (

Site Updates

I’ve added The Basics of Thermocouples to the Hacking Education page.

Links of the Week

Follow me on twitter @brnd4n for notice of blog postings! 

Detailed online factory tours are one of the best starting places to learn about manufacturing techniques. This tour of the Arduino factory provides a lot of information on how circuit boards are mass produced. (

This mechanical skeeball machine made completely of Knex is of the most impressive project I have ever seen. It even has a mechanical system to only accept quarters in its coin slot. Enough said. Definitely check out this link. (

An autonomous robot is being deployed along with a network of buoys to track great white sharks in the Pacific. (

In this TEDx talk, Andrew McAfee  discusses the implications of the digital revolution for the labor force and why he believes this revolution toward automation is the best economic news in the world today. (

Books that saved a startup. (

Site updates

I have added Coursera and a tutorial on the secret Arduino voltmeter to the Hacking Education page.

Links of the Week

Second links of the week! I’m also going to start adding notes of changes to the site at the bottom. Follow me on twitter @brnd4n for notice of blog postings! 

Anytime an article combines whiskey and entrepreneurship, it will lead here. On small entrepreneurial distillers executing in an industry dominated by major corporations. (

A robot teddy bear(!!!) that uses an innovative string actuation method instead of hard parts to move its limbs so it remains soft. (

A detailed look at detailing (see what I did there).  Engrossed me for 15 minutes and an excellent explanation of a topic I knew almost nothing about. (

Hangout with a Roomba! I have a soft spot for Roomba hacks and this one is well documented. (

A book list for entrepreneurs. A starting point for anyone looking to a read and learn. (

Advice for hardware startups within a story about Kiinde baby bottle warmer. (

Site updates

I added seeed, an opensource hardware vendor and small batch PCB maker, and ladyada’s supplier list page to the List of Part Suppliers page.

I launched a page of tutorials and other hacking education resources.