Skip to main content

Robotics for fun and profit

Gary Pollice, Professor of Practice, Worcester Polytechnic Institute
Author photo
Gary Pollice is a professor of practice at Worcester Polytechnic Institute, in Worcester, MA. He teaches software engineering, design, testing, and other computer science courses, and also directs student projects. Before entering the academic world, he spent more than thirty-five years developing various kinds of software, from business applications to compilers and tools. His last industry job was with IBM Rational Software, where he was known as "the RUP Curmudgeon" and was also a member of the original Rational Suite team. He is the primary author of Software Development for Small Teams: A RUP-Centric Approach, published by Addison-Wesley in 2004. He holds a B.A. in mathematics and an M.S. in computer science.

Summary:  from The Rational Edge: Read how to get started in robotics programming, whether you want to teach the basics to students or your own kids, or simply develop a few skills for your own benefit. This content is part of the The Rational Edge.

Date:  15 Mar 2008
Level:  Introductory
Activity:  1316 views
Comments:  

robotics While the number of college students enrolled as computer science majors has remained steady over the last couple of years, the number is nowhere near the high point we saw at the turn of the century. It has become difficult to interest young people in the exciting world of computers and computer science. Part of the problem is that computers are so ubiquitous that their novelty has worn off. Students in high schools and lower grades have already been exposed to some form of programming and the excitement we experienced when we were young is hard to find these days.

So, how do we interest young people in pursuing a course of study in computer science or some of the related areas that also suffer this "contempt bred of familiarity?" As I've pointed out before, CS has become an integral part of other disciplines, such as game development, bioinformatics, and robotics. 2 So, I suggest that you and your kids get involved with robotics. Robotics is cool. Robotics appeals to the nerd and being a nerd is cool today. Nerds are intelligent, have great earning potential, and they're a lot of fun to be around. Ask most kids whether or not they'd like to be the next Bill Gates or Steve Jobs or Kim Komando. 2 You'll get their attention.

I was planning on writing this article for the December 2007 issue of The Rational Edge, but the timing just wasn't right for me. (I imagined encouraging you to go out and get a robotics kit for you and your kids as a holiday treat.) But, although the holidays have passed, it's never too late to purchase a robotics kit for a birthday or for no occasion at all.

A little background on me and robotics

I have to admit that I'm hardware-phobic. Many years ago when hobbyists were getting started with personal computing I saved up about $1,600 for a computer kit. I got the SOL-20 processor that had a whopping 8K memory and the ability to connect to a tape recorder and a television set. 3 I had built shortwave radio receivers when I was a kid so I figured I could handle the soldering and construction of the SOL-20. I was not, however, really up-to-date on the electronic devices of the late 1970s and made one mistake as I was making all of the connections. I touched the wrong pins causing a current reversal and all of the diodes on the circuit board exploded. Ever since then I've been afraid to experiment too much with hardware. My wife still hasn't let me forget that it cost about $300 to have a "professional" repair the damage and get the system running. And $300 in those days was a lot of money.

You can imagine my angst when I found out that next year I will be participating in the unified robotics curriculum at Worcester Polytechnic Institute, in Massachusetts. Although I'm scheduled to teach the software engineering part of the course, I feel that I should be somewhat knowledgeable about robotics in general and gain some experience -- if not in the hands-on construction of robots, at least in programming them.

I decided to jump into the robotics water feet first and hoped that the water wouldn't be over my head. It turns out that there are some pretty simple entry points to robotics that have a moderate cost. I'd like to introduce you to two of them in this article and give you some pointers to other robotics resources.

Legos are not just building blocks

One of the more popular robotics platforms that appeals to all levels of experience is the Lego Mindstorms platform, of which the NXT is the current version. The NXT contains a microprocessor with flash memory and has ports for sensors and motors. It offers Bluetooth support so that it can communicate with a computer wirelessly or with other NXT robots. The NXT's processor is a major upgrade over the original Mindstorms platform, making it possible to implement much more sophisticated robotics software applications. The processor is enclosed in a rectangular component with a LCD screen known as the "brick." Any Lego robot you build will contain the brick.

The NXT has a visual programming environment based on National Instruments LabVIEW, a programming environment for embedded systems and robotics that supports several platforms. 4 A program in LabVIEW is constructed by composing various program building blocks and supplying parameters to the blocks. The visual programming style might not appeal to hardcore coders, but it is popular with engineers and non-programmers who need to solve real problems with software-controlled hardware. I'll discuss LabVIEW-based environment in more detail below.

What makes the Lego system a great one for introducing a young person to robotics is not just the software capabilities, but the hardware that you have at your disposal. The hardware comes with Lego building blocks that many kids encounter as they grow up. You can take blocks, gears, and pieces from other Lego systems and include them in the robots you construct. So, if your child is inclined to rolling up her sleeves and building things, she'll enjoy putting together a cool robot and learn how to develop a simple program to test it out. If you have son who likes programming more than the hardware part, he can write cool programs and learn how to construct a minimal robot that will obey the program's commands.

One of the simplest Lego robots you can make from the basic kit 5 is the TriBot. This is a three-wheeled robot that scoots around the floor under your program's command. If you follow the tutorial in the RoboCenter portion of the programming environment or the documentation that comes with the Mindstorms NXT, the first version of the TriBot project you build is a robot with the wheels, the brick, and nothing else. This TribBot has everything you need for future additions. You can put it together, program the demo, and test it out in less than an hour.

The second version of the TriBot builds upon the first by adding a bumper that senses when the robot runs into an obstacle. It's a simple device that contains a pressure-sensitive button that sends a signal when it is pressed or released. If you're familiar with developing applications using a graphical user interface, you can imagine how it works: It's similar to mouse buttons that are pressed and released. The version of the TriBot with the bumper sensor is shown in Figure 1. The brick sits on top of the TriBot with two of the servo motors controlling the left and right wheel. The bumper is below the two beams sticking out of the front. Hanging from these beams is a crossbar that moves freely. When the TriBot runs into an obstacle, the crossbar pushes into the bumper and pushes the button.

Photo of robot rolling on floor

Figure 1. The Lego Mindstorms NXT TriBot

The demo program for this TriBot has it move forward until it runs into a wall, reverses, then stops. This may not seem terribly interesting, but it proves that the TriBot and sensor works properly. Kids will probably be a little bored with this, so you might suggest a different program. A more interesting program would have the TriBot run into something, back up, turn a bit, and continue. You can have this behavior run forever or you can stop it after a certain number of bumps. I programmed mine to stop after ten collisions. This adds some new programming techniques to your child's repertoire, such as looping. Let's look at the program. Figure 2 shows the LabVIEW environment.

Screen image for Lab View showing palattes and tools

Figure 2: The LabVIEW environment

The LabVIEW environment consists of five parts. A palette sits on the upper left side of the window. All available blocks can be selected from this palette and moved into the program area -- the large pane to the right of the palette. Below the program pane is a detail pane that shows the details for the currently selected block. The pane on the upper right of the window is the Robo Center. The Robo Center contains the tutorial projects for the basic Mindstorms NXT system and other documentation. Below the Robo Center is a pane with two tabs. One provides a link to additional help, and the other provides a thumbnail view of your complete program. From the thumbnail view you can click on a block and it becomes visible in the program pane.

Let's look a little closer at the complete program for the TriBot with the touch sensor, shown in Figure 3.

Image of program in Lab View environment

Figure 3. A complete TriBot program

There are seven blocks used in the program. The starting point for the program is at the far left. The first block in the program is a loop block that encompasses five other blocks in sequence. The loop will execute through ten iterations as specified in the details pane shown in Figure 4.

Image of details in Lab View environment

Figure 4. Details for the loop block

The five-block sequence in the loop contains the following blocks:

  1. A move block that will move the TriBot forward at 75% power.
  2. A wait block that waits until the touch sensor is pressed. That is, the robot moves until the sensor is pressed and then control passes through this block to the next.
  3. A sound block that plays a short crying sound.
  4. A move block that will move the TriBot backwards for one complete rotation of the wheels.
  5. A move block that will just move the left wheel backwards 1.3 rotations of the wheel. This will cause the TriBot to turn approximately 45° to the left.

After the loop executes ten times, a sound block executes that plays "Goodbye" and the program ends.

The square containing controls at the lower right of Figure 3 can be used to compile the program, download it into a NXT brick, and execute it if desired. Typically, you will download your program into the brick over a USB cable, detach the cable from the brick and then use the controls on the brick to execute your program.

The loop details shown in Figure 4 are quite simple. Figure 5 shows details for the more complex Move block.

Image of move block details in Lab View

Figure 5. Details of a Move block

The standard brick contains three ports for motor connections. In the TriBot, you connect two of the motors to the B and C ports. The left motor connects to port C and the right to port B. You can specify whether to move the wheels forward or backward by selecting the correct direction below the port selection.

The details for the movement in Figure 5 show that you will apply power equally to both ports. The slider at the bottom can be changed to apply power unequally, resulting in turning the TriBot. The power can be adjusted at the top right of the details pane -- more power moves the TriBot faster, but drains the available power faster as well. 6

Below the power slider is a control that allows you to specify how long the movement should last. In the example, this command will run forever, or until a condition is met as specified by the next block in our program that waits for the touch sensor's button press. Finally, you can select the next action for the wheels -- either apply brakes or coast. This section of the details is not always available. It becomes active based on settings of the other details in the control.

Although I don't use it in this program, there is a section (green) on the left side of the details that show the number of rotations each wheel makes. You can use this to determine how many revolutions it takes to travel a specified distance. These are feedback boxes.

Naturally parallel

We learn best when we're having fun. Robots are not sequential systems, but rather they are highly parallel in nature. When we talk about parallel systems, programmers immediately think about the dirty details of setting up threads and other low-level elements of programs. Getting parallel programs to run correctly is difficult. Certain languages that are now emerging purportedly make the tasks easier, but these languages are not yet widely used. 7 LabVIEW makes parallelism so easy that you may not even be aware that you're writing a parallel program. We might decide that it would be fun to have the LCD display on the brick show a beating heart as the TriBot moves during the tutorial. The program shown in Figure 6 does just that.

 Image of NXT program in Lab View environment

Figure 6. A parallel NXT program

There are two threads of control shown in Figure 6. The top thread contains our original program that moves the TriBot. The second thread -- called a sequence beam -- has the additional program thread that displays the beating heart. We do this by displaying a large heart icon, waiting a half second, displaying a small heart icon, waiting another half second, and then repeating this loop forever. That's all there is to it!

If kids can use parallelism in their early efforts, they will be able to grasp some of the more difficult concepts of robotics later. If you've spent most of your programming career writing sequential code, you might have more trouble adapting to the parallel nature of the robotics programs than your kids will.

Extensibility

The Lego system can be easily extended with additional sensors, motors, and activators. There are several suppliers who make components for the Lego platform. Some of these cost as little as $10, while other complex sensors or motors can cost several times as much.

Pieces from other Lego sets can be used with the Mindstorms platform. You can also use components from other robot kits and mix and match them to make fantastic creations.

The Lego system is more than a toy. It's the doorway into a wonderful world for both you and your kids. If you're not sure whether the kids might be more interested in the mechanical, electrical, or software aspects of robotics, the Lego system is the right place to start.

If you're going to use the NXT for your own projects after the kids are asleep, you might want to program in a language that you are more familiar with and that gives you more control over the processor. There are quite a few options for you. There are C and Java™ programming systems as well as some dynamic language ports that you can download and use with a little bit of configuration effort. 8

iRobot Create

The Lego NXT was not my first robot. It is the one that I'm using to learn more of the non-software basics. My first robot was the iRobot Create™ from iRobot Corporation -- the folks who developed the Roomba sweeper. 9 We've had a Roomba in our house for several years, and when I heard about the Create I wanted to get one to try my hand with it. 10

The Create consists of a Roomba base -- the circular platform with two driving wheels and an optional third free wheel, and some connectors to your computer, including a supplied cable, external sensors, and to an optional command module that contains a separate microprocessor. 11 (If you plan to do any useful projects with the Create, you definitely want to get the command module.)

The Create offers two ways of controlling the unit. The first is a simple bytecode language that you can use to create scripts that you download into the unit. You don't really need a command module for this, but the memory is very limited. There is a small 100-byte buffer that holds the bytecode instruction stream. You can "program" using the bytecode open interface by directly loading the script into the machine from a cable directly connected to your computer. While this is useful for familiarizing yourself with the unit, it's not going to be useful for real applications, and you and your kids will lose interest quickly.

Programming the Create command module's processor requires a true C compiler and other development tools. The recommended approach to programming the Create is to use the WinAVR toolset. WinAVR is a set of tools that are open source and freely available. 12 The WinAVR tools is based upon the popular gcc compiler tools with a code generator for the AVR family of processors. The main tools in the toolset are the compilers, a library that provides functions specific to accessing and modifying the AVR hardware and memory, and a program for loading programs into the Create. On my Macintosh system there is an editor called Smultron that serves as an IDE for Create development. A similar tool exists for the Windows version of the tools.

Once you have the programming environment installed and configured, you can begin to explore the built-in sensors of the Create. The device comes with a base docking station that recharges the battery while the unit is docked. The station emits an infrared signal that is picked up by the unit's infrared sensor. One of the demos that comes built into the Create lets you position the unit anywhere in a room and it seeks the docking station. If it does not dock properly it reverses direction for a bit and tries again until it is completely docked.

The standard Create unit has special sensors for other events, such as when the unit bumps into a wall or object and when the unit is at the edge of a surface like a table. You can purchase other sensors from iRobot or other sources and connect them directly to the Create or to the command module. Some of these sensors react to physical phenomena such as light, temperature, and so on. Once you understand how to write programs that work with one type of sensor, you'll be able to work with most of the other types of sensors quite easily.

Since I was busy with my Lego robot, I lent my Create to one of my students for him to use on one of his projects. He quickly had some interesting behavior implemented on the Create and then proceeded to add new hardware and programs. He constructed a platform on the device that holds a laptop computer to provide a wireless connection, a holder for a Sun SPOT, 13 and stereo cameras to see where the unit was going. His resulting Create is shown in Figure 7.

We've had a lot of fun with the Create. Bob, the student, brought the robot to my office and we sat at my laptop looking at the view from the cameras on the Create as it wandered down the hall. We used the unit to deliver candy to some of the other professors on the floor and peek into the various offices. With just a few keystrokes on the laptop keyboard we could steer the robot by sending signals over our wireless network to the laptop on the unit. The unit's laptop is connected directly to the Create and translates the keystrokes to the appropriate commands to move the machine and send back the pictures.

Photo of iRobot Create on wooden floor

Figure 7. iRobot Create with cameras and a Sun SPOT

The main differences between the Create and the Lego Mindstorms systems are:

  • The Create chassis and drive mechanisms are pre-built, while you have to assemble the Lego robots.
  • The Create does not have a lot of plug-and-play hardware and sensor pieces like the Lego system. This means that you need to be much more of a hardware tinkerer if you want to extend the Create.
  • You must be willing to program at a lower level with the Create than with the Lego. There is no development environment similar to LabVIEW that I know of that you can use with the Create, although you can execute simple scripts.

When I first acquired my Create, I was more interested in programming robots than building the hardware myself; I was still handcuffed by my hardware phobia, convinced that I would not be able to actually construct anything useful. Since the Create was already built, with the drive system in place, I thought it would be the easiest way to start learning about robotics. I'm not sure I was right. The system that would best suit you will depend on your background and your willingness to get down into the microprocessor interface with the hardware sensors at a very low level. If you're going to get serious about robotics, you'll soon want more than either of these two systems provide in their base kit. You'll probably want to collect several microprocessors and hardware components and build your unique creations from the ground up. Luckily, there is a wealth of information and resources available to you, some of which I've listed at the end of this article.

Conclusion

I bet that if you give robotics a try, many of you will get hooked on it. The programming and hardware tinkering will bring back memories of a time when digging into something new was truly fun. Perhaps it will remind you of using an old lawn mower engine to build your own go-kart. Some of you will be reminded of that first BASIC program you wrote to actually display something on the TV screen hooked up to your TRS-80 or Commodore computer. These memories will help you share the experience with your children as they experience the joy of creating something with cool hardware and software, and you can be a part of their memories.

Not only will you be doing something with the kids, but they'll be learning lessons that they can take and use in school. They can also get involved with robotics competitions like the FIRST competition. FIRST (For Inspiration and Recognition of Science and Technology) is an organization founded by Dean Kamen, the inventor of the Segway and many other innovative technologies. FIRST runs a robotics competition every year where high school students team up with mentors from universities and industry to build robots for specific tasks. Teams compete at local and district levels, with the winners moving on to the world championships. This April, several thousand young roboticists will fill an arena in Atlanta to compete for the right to claim the 2008 FIRST trophy. A lot of them will also be gaining experiences that will look great on their college applications.

So, rather than spending a couple of hundred dollars on a game box, I suggest you invest in a robotics kit. I bet the kids will have just as much fun, and you'll be able to learn along with them. It will be time well spent.

Notes

  1. See Where have all the CS majors gone?, http://www.ibm.com/developerworks/rational/library/sep07/pollice/index.html.
  2. If you're not familiar with Kim Komando, she hosts a very popular show for current and would-be computer geeks. http://www.komando.com/.
  3. You can find out about the SOL-20 at http://www.digibarn.com/collections/systems/sol-20/index.html.
  4. You can find out more about LabVIEW at http://www.ni.com/labview/.
  5. There are several versions of the Lego Mindstorms NXT set. When I talk about the basic kit, I'm referring to the educators set that I ordered. This set costs about $300.
  6. The brick comes standard with space for using AA batteries. However, for any significant usage, you should get the optional rechargeable brick battery that will last for several hours between charges.
  7. See the December column, Computing in a parallel universe. http://www.ibm.com/developerworks/rational/library/dec07/pollice/index.html.
  8. A list of programming options for the NXT can be found at http://www.teamhassenplug.org/NXT/NXTSoftware.html.
  9. You can find information on the iRobot Create at http://www.irobot.com/create.
  10. The Roomba is a small circular robot sweeper that wanders over your floors picking up dust and dirt. While it doesn't replace a vacuum cleaner, it's a handy way of keeping the floors clean in between major cleanings.
  11. The command module in my system uses an Amtel ATMega168 microprocessor.
  12. These tools can be obtained from the iRobot pages. (http://www.irobot.com/sp.cfm?pageid=305).
  13. The Sun SPOT is a palm-sized box that implements the Small Programmable Object Technology. It comes with a daughter board that contains a temperature sensor, light sensor, 3-D accelerometer, eight LEDs, and two switches. The SPOT is programmed in Java.

Resources

Learn

Discuss

About the author

Author photo

Gary Pollice is a professor of practice at Worcester Polytechnic Institute, in Worcester, MA. He teaches software engineering, design, testing, and other computer science courses, and also directs student projects. Before entering the academic world, he spent more than thirty-five years developing various kinds of software, from business applications to compilers and tools. His last industry job was with IBM Rational Software, where he was known as "the RUP Curmudgeon" and was also a member of the original Rational Suite team. He is the primary author of Software Development for Small Teams: A RUP-Centric Approach, published by Addison-Wesley in 2004. He holds a B.A. in mathematics and an M.S. in computer science.

Comments



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=294095
ArticleTitle=Robotics for fun and profit
publish-date=03152008
author1-email=gpollice@cs.wpi.edu
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rational offerings on the IBM Cloud

Special offers