Thursday, November 1, 2007

The Making of Sparky I - Preparing the Roomba

First in a series of posts about how Milestone #1 of creating the autonomous robot "Sparky ". This post deals with the basics of using the Roomba as the platform for moving around.

Modern Roomba vacuums come already capable of being controlled through a serial interface, using a well documented API of commands via a 7-pin DIN connector on their sides hidden by a covering piece of plastic though. Prior to this modern era, there was a "near" modern era that had the 7-pin connectors and all other the other hardware setup to make it controllable. However, its software did not support this. I happened to have one of these.

Luckily though, the iRobot folks provided a software updater for it called the OSMO Hacker. It costs $30, and there are two versions which adds a little thrill to purchasing it. One needs to decipher serial numbers to determine which is needed. Fortunately, I got it right.

Once delivered, it was relatively (though not completely) obvious how to use it: plug it in, turn on the roomba, watch light blick, wait for light to stop blinking, restart.

Now, since it is all flashing lights and invisible software, who really knows what was happening or if it worked. First test is to make sure the Roomba itself still operated, which was a relief when I found out that I did not just create a $300 paperweight. Next up is to hook up a computer's serial interface to the Roomba to see if it accepts and responds to API commands. Here's where the fun begins.

Being a hardware novice, the book Hacking Roomba was a very good crutch and how-to manual on the basics. In the book, the author shows a number of ways to do this, which basically comes down to a build vs. buy decision. I opted for 'buy' at this point, wanting to worry more about the software, though many things would conspire to have to build anyway. Given I was a soldering klutz, Iwanted to ensure my software upgrade worked without having to worry about failure being caused by my soldering. I'm much, much better at soldering now btw.


Simplest solution was to buy the 'RooStick', which I got from Sparkfun Electronics.
$30 seemed a little expensive, but figured the time it saved me would be worth it. When it actually arrived, the size of it (puny) certainly made me wonder about its price tag again. This thingy's job is to convert a computer USB port into a serial port specifically for talking to a roomba. This is no small trick because of two important things:
  • the Roomba has this funky, non-standard 7-pin DIN connector; and
  • the Roomba's serial port operates at +5 Volts (the RS232 spec is a +12V serial port).
And if $30 seemed a little steep for this, wait because we are not done yet: one needs a non-standard cable to hook up the RooStick to the Roomba (actually an 8-pin DIN cable, which happens to fit into the 7-ping female connectors).

With (pricey) hardware in hand, onto hooking it up and seeing if we can control the Roomba. This was successful, both from my Mac Powerbook (OS X 10.3) and my GNU/Linux (Ubuntu 7.04) laptops. Below are details on getting this to work on each platform. While the excitement of being able to control the roomba for the first time was great, it was also severely constraint by a 6 ft. cable. Still this was a major mini-milestone, proving that a Roomba can indeed be used as my robot platform.


RooStick on GNU/Linux (Ubuntu 7.04)

Plugged in RooStick to USB port, and dmesg reads:

[86202.740000] usbcore: registered new interface driver usbserial


[86202.744000] drivers/usb/serial/usb-serial.c: USB Serial support registered for generic

[86202.744000] usbcore: registered new interface driver usbserial_generic

[86202.744000] drivers/usb/serial/usb-serial.c: USB Serial Driver core

[86202.784000] drivers/usb/serial/usb-serial.c: USB Serial support registered for cp2101

[86202.788000] cp2101 1-2:1.0: cp2101 converter detected

So it was automatically detected, and driver installed. Nice.

In an xterm, set device setting with:

stty -F /dev/ttyUSB0 57600 raw -parenb -parodd cs8 -hupcl -cstopb clocal

And test commands to drive (though need to pick it up to stop it due to cable length):

printf "\x80" > /dev/ttyUSB0
printf "\x82" > /dev/ttyUSB0
printf "\x89\x00\xc8\x80\x00" > /dev/ttyUSB0

Worked, but I had to send the last line a few times before it seemed to take. Maybe the sequence got messed up and it took a while to coordinate what the first byte was.


Roostick on Mac OSX 10.3

First needed to download and install the USB driver:

https://www.mysilabs.com/public/documents/software_doc/drivers/Microcontrollers/Interface/en/Mac_OSX_VCP_Driver.zip

Needed to restart the machine. I hate that.

Device now shows up as:

/dev/cu.SLAB_USBtoUART
/dev/tty.SLAB_USBtoUART

Next, needed to get and unzip RoombaComm java library from Hacking Roomba site.

After downloading and unzipping, I needed to initialize something with respect to the rxtxlib that java code calls out to.

% ./rxtxlib/macosx_setup.command

Also needed to restart after this. Yuck again.

Power on manually roomba, then run this:

% sh runit.sh roombacomm.SimpleTest /dev/cu.SLAB_USBtoUART

And it worked.

No comments: