Hacking Your Lego Robot for Fun and Profit

I, for one, welcome our new robot overlords

Last week, at a friend’s suggestion, I bought a Lego Mindstorms NXT 2.0 kit. This thing knocks the socks off the Legos I had growing up (and don’t get me wrong, those old Lego sets were amazing). The premise of Mindstorms is that you build a robot body out of Legos – and we’re talking some cool Lego pieces here, like gears, joints, axles, etc. Then, you make it come alive.

The “coming alive” is courtesy of that gray rectangular control unit in the center of the picture above. It hooks up to three motors and four sensors (two touch, one light/color, one ultrasonic – for echolocation), and it can play sounds, print text or images to its screen, and flip colored lights on and off. In other words, it’s a primitive brain, and the body you construct lets it see, hear, and move.

Of course, a brain’s job is to think, and that’s where the programming comes in. The Mindstorms kit comes with a simple, proprietary, graphics-based programming environment. It looks like this:

Kid-friendly and Turing-complete!

You can “build” a program out of functional blocks to control the robot’s behavior using primitive loops and if/then statements. For its target audience (kids and the general public), this is a pretty cool piece of software. For a professional computer programmer (and part-time mad scientist) like myself, it has several important limitations. For example:

1. The simplistic development environment lacks some basic features, like debugging, which  makes advanced programming very inconvenient.

2. No way to integrate your programs with other tools or libraries.

3. All programs have to run on the Lego control unit, which is battery-powered and has limited memory.

When the system doesn’t give you what you want, it’s time to hack the system.

In this case, said hacking was made much easier by a fellow named Anders, who back in 2009 wrote a communications library that lets you control the robot with the C++ programming language, which is vastly more powerful than what Lego gives you. In the Visual C++ compiler, it looks like this:

More power!!

It took a few hours to get Anders’s libraries working (the first compile’s always the hardest), but I managed it. Now instead of running programs on the little control unit, I can run them right on my PC, which will control the robot wirelessly thanks to a USB/Bluetooth adapter I picked up from Best Buy on Saturday. Robot successfully hacked!

My intense focus on software means I’ve had little time to play with the hardware thus far. The simple robot in the top picture is the only thing I’ve built. But the kit comes with over 600 pieces, and you can make anything from a robot alligator to a humanoid walker to an automatic Rubik’s cube solver. I can’t wait to try out the possibilities.

And why did I go to all this trouble with a toy? Well, if you’re going to make an artificial intelligence, it probably ought to have a body…

For you programmers/engineers out there: ever done anything with robotics? For the rest of you: ever make anything cool out of Legos? Tell me about it!

About these ads

3 responses to “Hacking Your Lego Robot for Fun and Profit

  1. This is Epic! You should totally build battle bots! They can even sustain real Lego Damage! I guess you could teach them to do some cool stuff too. lol mazes, scare your wife! all kinds of stuff. Two creepy red lights coming down the hallway at night, good times that.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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