Robots and Python, first in a series

It must just be something in the air, but robots have become much more a part of my life the past couple of months. First of all, I bought an iRobot Create to experiment with for possible use in class. If you’re not familiar with the Create, it’s really a Roomba with the vacuum removed and an additional serial interface with can be used with an optional control unit or to interact with various sensor inputs.

I was so  impressed with the Create that I took advantage of a black Friday two-for-one sale and got both an interior Roomba and the shop-vac version. We’ve been fairly happy with those two as they’ve bounced around the house, picking up some of the mountains of dog hair generated by our three aussies.

In  the meantime, I was teaching a C programming elective at school and we decided to try to use an Arduino and some of the hardware from an old kit to create a line following robot. It wasn’t pretty, but after several struggles, they got it working and made it follow a line.

So all of this robotic fooling around gave me an idea. I wanted to mount a computer and web cam on the Create and see if I could drive it using Python. Then, I would see if we could use it in teaching at all.

My first idea was to use an eee 900 that I had. It was having hard drive (SSD) problems, but it would run just fine off of a USB stick with Ubuntu on it, and it already had a web cam.

My eee pc 901 perched on the iRobot Create.

To keep things simple, I’d just enable remote desktop sharing, use a VNC viewer to connect, and run Cheese to see the camera output. That would give me visuals from the bot’s point of view.

The Create (and most later Roomba’s) have a serial interface for controlling them, which takes a somewhat unusual connector. Fortunately that correct cable was included with the Create, going from standard 9-pin serial to the bot. Of course, the eee doesn’t have a serial port, but an old Belkin USB to serial converter I had from my Palm and Visor days seemed to make a connection. However, my attempts to use a terminal program (Miniterm) got nowhere. I’d see the bot boot up, but it ignored all of my commands. The problem was that the terminal program was sending the numeric command codes as text, not numbers. Finally, I switched to using Python and the serial module and the bot reacted.

However, controling the bot with raw codes is no fun so instead, I used iRobot’s to connect to the bot. This took some tweaking of the code, since it was looking only for Windows style numbered comm ports rather than Linux device files. But once that was fixed, I could ssh to the eee, connect to the bot and run Python, and drive the bot from my desktop.

It really didn’t take long to put everything together. In the course of an evening, I had the eee perched on the Create, everything hooked up and a remote connection. Since I was still pretty ignorant of the Create’s operation, I just used the Python shell, imported and confined myself to the drive_straight(), stop() and turn_in_place() methods.

Driving was a bit cumbersome. For one thing the screen updates were slow, and for another, the weight of the eee was enough to give the Create just a little bit of trouble in getting over thresholds, carpet edges, etc. In any case, I managed to drive it from one room to another, much to my amusement and the puzzlement of the dogs. Seeing a giant dog snout fill up the field of view was enough to make me lose control and crash into a dog crate.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: