Friday, February 1, 2008

LEGO MINDSTORMS NXT: Robotics Beyond Building

.FLYINGHEAD CONSUMER ROBOTICS
.TITLE LEGO MINDSTORMS NXT: Robotics Beyond Building
.AUTHOR David J. Perdue
.SUMMARY When we decided to increase our coverage of LEGO personal robotics, we really wanted to find someone who truly understood how it all works. No one could possibly have a better, comprehensive perspective of LEGO’s MINDSTORMS NXT robotics system than David J. Perdue, author of The Unofficial LEGO MINDSTORMS NXT Inventor’s Guide. This article is a must-read.
.OTHER

.BEGIN_SIDEBAR
.H1 About this article
.IMAGEPAIR A RIGHT
Over the years, we at ZATZ have had the opportunity to publish articles by some well known authors and true experts in the field. When we decided to increase our coverage of LEGO personal robotics, we really wanted to find someone who truly understood how it all works. No one could possibly have a better, comprehensive perspective of LEGO’s MINDSTORMS NXT robotics system than David J. Perdue, author of The Unofficial LEGO MINDSTORMS NXT Inventor’s Guide.

[[http://www.nxtguide.davidjperdue.com/|The Unofficial LEGO MINDSTORMS NXT Inventor’s Guide]] published by No Starch Press, helps you to harness the capabilities of the MINDSTORMS NXT set and effectively plan, build, and program your own MINDSTORMS NXT robots. We’re thrilled that David’s able to write this article for us.

And now, David J. Perdue’s article…
.END_SIDEBAR

.TEASER This stuff is so cool. Tap here to enter the exciting world of consumer robotics.
Robot uprisings and alien invasions are practically synonymous with science fiction, but the increasing prevalence, complexity, and capability of robots certainly hasn’t helped to assuage any fears of a sinister robotic revolution. In fact, robots are infiltrating our lives with astonishing speed and success.

The 2006 release of the LEGO MINDSTORMS NXT set, a powerful robotics toolset, has given great impetus to the spread of robots, thrusting them into bedrooms, living rooms, kitchens, backyards, offices, and other equally dubious places. Forget the aliens. These MINDSTORMS robots, equipped with all the menacing power of AA batteries, truly are storming the world. And I’m enjoying every moment of it.

With a price of $250 and the capability to produce thousands of unique, functional robots, the NXT set has enabled multitudes of people — including children, teenagers, and adults — to create their very own robotic creatures, contraptions, and contrivances. Figure A shows one of my NXT robots called Tag-Bot, which is a four-wheeled steering vehicle.

.FIGPAIR A Tag-Bot, a NXT robot, is a four-wheeled steering vehicle.

Tag-Bot plays a game called "flashlight tag" in which you attempt to "tag" the robot by shining a flashlight into its light sensor for a brief period of time (e.g., three seconds). To escape the beam of light, Tag-Bot dashes around the room while avoiding objects.

Although building may seem to be the NXT set’s main purpose (after all, we’re talking about a LEGO kit here), you can do far more than simply build with the set. So we’ll observe five aspects of the world of NXT:

.BEGIN_LIST
.BULLET Building
.BULLET Programming
.BULLET Computer-aided design
.BULLET Online communities
.BULLET Competitions
.END_LIST

There are, of course, other aspects that I could have listed here, but these main ones will reveal the enormous potential of the set and, hopefully, pique your interest in creating your own NXT robots.

Realize, however, that I first bought a MINDSTORMS set "just to see what it’s like," and years later I’m still surrounded by robots. You’ve been warned. Now let’s start with the first item on our list: building.

.H1 Building
The NXT set includes nearly 600 LEGO pieces, but don’t expect to see any of the LEGO bricks you played with as a kid. First, you’ll find a selection of electronic parts. Chief among them is a programmable microcomputer simply called the "NXT", shown in Figure B.

.FIGPAIR B The NXT is a LEGO microcomputer.

The NXT controls the other electronic components. The servo motors, shown in Figure C, use built-in rotation sensors or "tachometers" to measure rotation. They power your creations.

.FIGPAIR C The servo motor powers NXT creations.

Sensors, shown in Figure D, include a touch sensor, a light sensor, a sound sensor, and an ultrasonic sensor, used to measure distance.

.FIGPAIR D The touch, light, sound, and ultrasonic sensors all provide information to the NXT brick.

You use special electrical cables to connect all the motors and sensors to the NXT.

Besides the electronic parts, which invariably get the most attention, there are hundreds of additional pieces that mainly serve structural and mechanical purposes. Most of these non-electronic pieces belong to the "TECHNIC" category of LEGO parts, which are radically different from the familiar LEGO bricks.

Figure E shows just a sampling of parts from the NXT set; all the non-electronic parts in the kit fall into one of four categories: beams, connectors, gears, and miscellaneous pieces. With the variety and quantity of pieces in the NXT set, it would be difficult to exhaust the building possibilities.

.FIGPAIR E This is a sampling of parts from the NXT set.

.H1 Programming
I mentioned that the NXT is a "programmable" microcomputer, but programmable in what sense? While you can perform limited programming on the NXT itself, you’ll do the majority of programming on your home computer and then download the instructions to the NXT.

The NXT set includes a graphical programming language called "NXT-G" that is easy to use but very powerful — and compatible with both PC and Mac. Figure F shows the colorful interface and some of the programming "blocks" that make up a program.

.FIGPAIR F This is a sample NXT-G program.

The NXT-G tutorials found on the unofficial "NXT Tutorial" Web site (see http://www.ortop.org/NXT_Tutorial/) are an excellent resource if you’d like to learn more about NXT-G.

If you’d prefer a text-based programming language, you’re not alone. A number of unofficial text-based languages for the NXT have been released in the past year, and most of them are free and even more powerful than NXT-G.

One of the most popular is Not eXactly C (NXC), a C-like language that uses the standard firmware on the NXT. John Hansen, the developer of NXC, has also developed Next Byte Codes (NBC), which uses an assembly language syntax. Hansen’s recently published book, LEGO MINDSTORMS NXT Power Programming: Robotics in C (Variant Press, 2007), teaches both languages. I’ve written a review of Hansen’s book, which you can find at the book’s page on Amazon.com. You can download NXC and NBC and other resources for free from Hansen’s Web site: http://bricxcc.sourceforge.net/nbc.

Are you interested in a "real" C language for the NXT? If so, then you’ll like RobotC, a C-based language available from http://www.robotc.net. RobotC is not free, however, and you must purchase it from the RobotC Web site where you can download a copy for immediate use or buy a CD-ROM version.

How about Java? The leJOS community at http://lejos.sourceforge.net developed leJOS NXJ: Java for the NXT. You can download the software for free from the leJOS Web site, and a great resource for learning more about leJOS NXJ is Brian Bagnall’s book, Maximum LEGO NXT: Building Robots with Java Brains (Variant Press, 2007).

These are only some of the languages available for the NXT, and you can discover many more programming resources on the "Internet Resources" section of my Web site at http://www.nxtguide.davidjperdue.com/internetresources.html.

.H1 Computer-Aided Design
As you may have noticed, I rendered most of the images in this article with CAD (computer-aided design) software. There’s another large segment of the LEGO community that develops CAD software specifically for LEGO, and most of these resources are available online for free.

First, the "official" CAD software is LDD (LEGO Digital Designer), which recently added support for the NXT set, as shown in Figure G.

.FIGPAIR G LDD (LEGO Digital Designer) is official CAD software.

Using LDD, you can assemble virtual robots and then automatically generate building instructions. You can download LDD for free from http://ldd.lego.com. Unfortunately, LDD still needs some development to make the NXT features more user-friendly, but the software is still worth checking out.

Second, the unofficial LDraw system of tools is currently the most powerful LEGO CAD software available. The central Web site for LDraw is http://www.ldraw.org where you can download the software for free. One of the most popular LDraw programs is MLCad, shown in Figure H, but there are a host of other programs available that serve different purposes (MLCad, like LDD, is for creating virtual LEGO models and building instructions).

.FIGPAIR H MLCad is unofficial but powerful LEGO CAD software.

Numerous authors of LEGO books, including me, use LDraw to create print-quality building instructions. If you’re interested in learning more about LDraw and the various software tools available, visiting the LDraw Web site will get you started.

.H1 Online communities
Since the NXT set’s release, numerous Web sites have sprung up that focus specifically on the NXT set. The ultimate online community for NXT fans is the official MINDSTORMS Web site at http://mindstorms.lego.com.

An unofficial blog, The NXT STEP (see http://thenxtstep.blogspot.com), has numerous contributors that frequently post information about anything and everything related to the NXT set. Still another unofficial blog, nxtasy.org (at http://nxtasy.org), offers extensive forums and a repository of building, programming, and other resources.

LUGNET (LEGO Users Group Network) at http://www.lugnet.com is a "global community of LEGO enthusiasts." Although LUGNET is not specifically for the NXT set, it offers a number of resources and related forums that are helpful. In short, the Internet harbors incredible communities and resources for the NXT set, and visiting any of the sites mentioned here are great starting points.

.H1 Competitions
Finally, competitions or "challenges" are a popular MINDSTORMS activity and can take many forms: racing, line-following, maze-solving, weight-lifting, object-finding, and much more.

Some of the most well-known competitions are hosted by the official MINDSTORMS Web site; an example is their recently concluded robotic sumo competition. In this contest, the official rules asked NXT fans to create "sumo-bots" that could push each other off an arena. Over one-hundred people from nineteen countries took up the challenge, submitting pictures, programs, LDD files, and other information about their sumo-bots to a section of the MINDSTORMS Web site known as NXTLOG.

.BEGIN_KEEP
Judges selected sumo-bots from among the entries, rebuilt them, and then held a robotic sumo contest. The results? Visit http://mindstorms.lego.com/specialevent/default.aspx to find out.

The nxtasy.org blog also hosts "challenges" in which anyone can participate by submitting video and other information about their entry (robot). We might define such contests or competitions as "virtual competitions" because no one actually meets face-to-face. However, actual gatherings for competitions are quite common, especially among LEGO user groups.

A handy feature of the LUGNET Web site, LUGMap (see http://www.lugnet.com/map), lists LEGO users groups around the world.

.H1 Conclusion
LEGO MINDSTORMS NXT is so much more than building. As we’ve seen here, it’s also about programming, CAD, online communities, and competitions — for starters. I hope you’ve gained a new appreciation for the NXT set and will consider experimenting with all it has to offer. In the end, this is one robotic revolution that I’m glad to support.

.BEGIN_SIDEBAR
.H1 Product Availability and Resources
Read The[[http://www.nxtguide.davidjperdue.com|Unofficial LEGO MINDSTORMS NXT Inventor’s Guide]].

Learn more about [[http://mindstorms.lego.com|MINDSTORMS]].

Learn more about [[http://www.ortop.org/NXT_Tutorial/|NXT-G]].

Learn more about [[http://bricxcc.sourceforge.net/nbc|NBC/NXC]].

Learn more about [[http://www.robotc.net|RobotC]].

Learn more about [[http://lejos.sourceforge.net|leJOS NXJ]].

Find more [[http://www.nxtguide.davidjperdue.com/internetresources.html|programming resources]] for the NXT.

Learn more about [[http://ldd.lego.com|LEGO Digital Designer]].

Learn more about [[http://www.ldraw.org|LDraw]].

Read [[http://thenxtstep.blogspot.com|The NXT STEP]]/

Read [[http://nxtasy.org|nxtasy.org]].

Learn about [[http://www.lugnet.com|LUGNET]].
.END_SIDEBAR

.BIO David J. Perdue bought his first MINDSTORMS set in 2001 and has since written Competitive MINDSTORMS (Apress, 2004) and The Unofficial LEGO MINDSTORMS NXT Inventor’s Guide (No Starch Press, 2007). He is currently a full-time college student majoring in Management Information Systems, and he maintains his Web site at http://www.davidjperdue.com and blog at http://www.nxtblog.davidjperdue.com.
.END_KEEP