Thursday, May 31, 2007

Robotics - Getting your feet wet (or: "Ya gettin' in deep, man.")

Way back in the past I was an even worse geek. I played D&D. I never subscribed to any of the gaming mags, but a friend of mine had a subscription to Dragon Magazine. In there was a really good comic called Snarfquest. I wound up getting a book of Snarfquest comics, which I still have to this day. One of my favorite frames from the whole book is one where Snarf, who is obviously on a quest, winds up finding out just what he has to do in order to accomplish his goals. As his trusty advisor is giving him all SORTS of advice, he's thinking to himself, "Ya gettin' in deep, man."

One problem with having a machine shop in the house is that you have to find something to do with it. I should've put "problem" in quotes because it's rarely a problem. Once things pick up, the "problem" is deciding which projects to undertake and which ones to shelve, potentially forever. As a very wise person put it in a forum post a few years ago, there are too many things I want to do before assuming room temperature.

Regardless, the projects that do wind up in the shop often stretch it beyond its means. Another tool here, another cutter there, and pretty soon the shop can do something it couldn't previously do. Such is the way of things. I can't count how many projects have gone this route, eventually resulting in a more capable shop.

So one entire hobby I've wanted to take on for years is robotics. I was itching to in high school, but couldn't afford the bits 'n pieces. Heck 72-step Airpax stepper would've set me back over a hundred bucks. These days you can get those from practically any dead fax machine or printer. And a microprocessor? Forget it. They didn't exist. But now they do! So a while back I dove into the wild 'n wooly world of robotics. Ooooh boy. Ya gettin' in deep, man.

I started off with an OOPic. It's a neat processor, and is a snap to interface new hardware to. It's basically a particular model of PIC processor with an object-oriented interpreter loaded onto it. Programs must be stored on an external I2C EEPROM chip, and run through the interpreter on the OOPic. They come with their own development tools, which really do make it easy to program, test, load, and run. I built my first mini-sumo using this, and had a blast.

Problem is they have something like 98 bytes (yeah, bytes) of RAM and limited EEPROM for program space. So you can quickly run out of room. A mini-sumo is about the limit of what I could do using the built-in objects. And if you resort to the scripting language itself, execution speed dumps to about a thousand instructions per second. Not great by modern standards. Don't get me wrong, I still love the OOPic architecture. I just wish they were more capable.

Enter the Orangutan line of controllers from Pololu Robotics. I picked up a Baby-Orangutan, then an Orangutan, and finally an Orangutan-X2. These are all based on Atmel AVR processors, and offer more capability as you move up the line. The Baby-O is a bare ATMega168 with a dual 1A H-bridge motor driver tacked on. The Orangutan adds an LCD and three pushbuttons. The X2 is a whole 'nuther beast, and can drive over a horsepower of electric motor through its dual H-bridge complete with current sensing, overtemp shutdown, etc.

But I'm finding that sometimes even the Baby-O is too much. So a while back I got a fistful of bare Atmel ATTiny processors. I got three varieties, from a tiny 8-pin jobbie on up to a 14-pin device. They run at 8MHz, have onboard A/D conversion, lots of timers and interrupts, just all sorts of stuff. And I haven't done a danged thing with them.

Until now... The setup on the Orangutans has been so nice, it's hard to look at a problem and say for sure it's too small a job for the Baby-O. I can plug the Baby-O into a breadboard, load code on it, and be good to go. But darn it, sometimes you DO get a project that's just too small. A good case in point is a project that came up recently at a club meeting:

Take a pinewood derby car and take away the center rail. Now add a steering servo and a microprocessor. Oh, and put some twists and turns in the track. Tack on two IR sensors, one on each side, and you have a pinewood derby car with a brain. The originator of the idea calls them "downhill racers". You read the two side sensors, looking at the sidewalls of the track, and try to steer the servo so it keeps the car centered in the track. If your centering algorithm works well, the car will handle all sorts of twists and turns without slamming into the wall.

Which, from a robotics standpoint, is a very straightforward project. One I/O pin handles the servo and sends a 1ms to 2ms pulse to handle steering. One analog input reads the left side sensor. Another reads the right side sensor. DONE!

So why waste a perfectly good $30 Baby-O on the thing when a $1.50 ATTiny will more than do the job? Well... But the Baby-O is so easy to use! Ok, ok, I'm being a bum.

So today I bit the bullet and logged into Digikey. A couple of clicks later and an AVR Dragon and AVR STK500 combination kit is in the mail. These are programmers that'll handle just about any device Atmel makes, including all the ATTiny chips I picked up. The Dragon is a USB device that will even power the target device off the USB cable, so it's dead easy to use. I checked in AVR Studio, and switching from the AVRISP mkII (which I use to program the Orangutans) to the Dragon is a single click. Couldn't be easier. Plus the Dragon and STK500 allow you to do in-chip debugging, so you can watch your code execute line-by-line. Not simulated, mind you, but live in-system debugging. Can't beat it.

Still, as I clicked that last click and saw my order confirmation coming up, I was reminded once again of that frame from Snarfquest: Ya gettin' in deep, man.

Yeah, I'm in deep. A year ago I was a home shop machinist thinking golly gee willickers, maybe now's a good time to get into robotics. Now I'm realizing I have at least four ways to program AVR hardware (the three already mentioned plus the AVR Butterfly I have on my bench as well), I'm starting to work with bare chips, and the idea of designing and building surface mount boards is starting to sound doable. I'm in deep.

Still, you can't beat it for the fun factor. I love this stuff.

Tom