Robots and Python, first in a series

December 28, 2009

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.


Quick Python Book, 2nd Edition

December 26, 2009

Book project complete

I’ve finally finished a book project – The Quick Python Book, 2nd ed. from Manning Publications was published as an ebook last week and will be available in traditional dead tree format in mid-January.

QPB had been selling steadily for the Manning folks for years, since it came out in 2000 and they wanted it updated for Python 3.x. Since the original authors weren’t available, I got the job.

It was billed as a quick and easy job, and it was probably easier than writing from scratch, but revising a programming book from version 1.5 of Python to version 3.x was a lot harder than I’d expected. On the other hand, I also learned much more about Python 3 than I’d expected. Suffice to say I’m a complete convert and am impatient for everyone to get their libraries converted so we can move to Python 3 everywhere.

I also got a real feel for the tech book production process. I really think that Manning’s process is very sound and the people I worked with were first rate. Unlike my ill-fated project with O’Reilly, this was tolerable and my efforts to get things done on schedule were appreciated.

Anyway, my goal now is to do some screencasts to help publicize the book. Since I’ve never done any video editing before, this will take a little learning as well.

I also have a couple of other Python projects in the works which I’ll now be spending my time on – more about those soon.