Chapter 5. What’s New with the NXT?

Solutions in this chapter:

Introduction

Several changes are introduced in the NXT compared with its predecessor, the RCX. This chapter covers the major new technologies in detail, explains how they work, and provides examples of how people have used them in their robots. Specifically, it covers the new LCD, file system, Bluetooth, and digital interfaces. (We intentionally omitted several improvements, because we cover them elsewhere in the book.)The chapter concludes with a discussion of some novel ways in which you can use the NXT thanks to all of these new technologies.

Notable Enhancements

In this section we’ll discuss some enhancements to the MINDSTORMS NXT, including studless construction, ethical connectors, rechargeable battery packs, and flash memory.

Studless Construction

If you are accustomed to LEGO TECHNIC construction, you will get the hang of NXT robot construction, as the NXT set is almost entirely studless. However, if you primarily did studded construction before, this is a paradigm shift in robot design, and it takes a while to get used to. The MINDSTORMS NXT kit introduces a few new pieces that were specially designed for this kit. For example, as of this writing, the TECHNIC Beam 3 x 3 Bent with Pins (often referred to as a Hassenpin after Steve Hassenplug) is available only with the set. As a matter of fact, this part, which is useful for 90-degree connections, was spurred on by members of the original group of adult fans (MINDSTORMS User Panel) who were part of the NXT project when it was just getting started. Early on, Hassenplug and a few others recognized the need for such a piece to aid in the construction process that was mostly all studless building. This piece is one of the most popular pieces in this set today.

Electrical Connectors

The electrical system of the MINDSTORMS NXT kit introduces a new connector for the sensor and motor cables. The connector is similar to an RJ12 phone jack, but if you look carefully, you will notice that the latch is not in the center. It is offset to the left edge, preventing use of regular phone cables, whether accidental or intentional. You can still connect the new electrical system with the old motors and sensors using a legacy compatibility cable.

Rechargeable Battery Pack

Though the rechargeable battery pack doesn’t come with the retail set, it is a thoughtful addition as an NXT accessory. The battery pack has a socket on the side to attach the charger, which can conveniently recharge the batteries without you having to remove the pack from the NXT. Compared to the original battery cover, the depth of the battery pack is slightly greater, and when connected to the NXT, it protrudes at the bottom. This is something worth noting and you need to account for it in your robot design. One nice addition on the software side in terms of the NXT-G and RobotC is that it is possible for you to detect whether the robot is using a rechargeable battery pack, as well as evaluate the battery’s power level (see Figure 5.1).

Rechargeable Battery Pack

Figure 5.1. Rechargeable Battery Pack

Flash Memory

Another convenience that is worth mentioning is the flash memory. The flash memory of the NXT brick retains firmware and all your files, even when you remove the batteries for an extended period. This is a significant change from the days of the RCX, when you would have to reflash the unit after you replaced the batteries. The NXT flash can store up to 256KB of data. This is a lot more space compared to the RCX. However, as we will discuss later in this chapter, you can create several new types of files, and those files can occupy space quickly.

Multiple Types of Sensors

The NXT system supports two types of sensors: new sensors that use the Inter-Integrated Circuit (I2C) interface, and older analog sensors such as those that came with the RCX kit. There is no specific rotation sensor, as it is now built into the NXT servo motors. The Ultrasonic sensor is a new addition to the sensor family. This sensor communicates with the NXT brick using the new digital interface. The redesigned light sensor is also a major improvement over its predecessor. Chapter 4 provides additional details on these and other third-party sensors.

The NXT File System

The NXT has introduced a file system that stores up to 64 files. The firmware allows users to create and delete files, rename them, and modify their contents. Filenames have a three-character extension, separated from the filename by a period. The name itself can be up to 15 characters long. The extensions start with r, and by this convention, the executable files on the NXT have an extension of .rxe. Table 5.1 lists the recognized file types with their extensions.

Table 5.1. NXT File Types

File Type

Extension(s)

Data files

.rdt

Executable files and

.rxe, .rtm

Try Me programs Icon files

.ric

Hidden menu files

.rms

Program files

.rpg

Sound files

.rso

Hidden system files

.sys

Temporary hidden files

.tmp

The NXT brick user interface shows these files in the form of a menu structure starting with “My Files,” and then branching into “Software files,” “NXT files,” “Sound files,” and so on (see Figure 5.2). Each menu then shows the files stored in NXT memory. The screen sample in Figure 5.2 is from NeXTScreen, a utility developed by John Hansen (see Appendix A for details).

NXT File Menu Navigation

Figure 5.2. NXT File Menu Navigation

File-Handling Functions

The NXT-G and the RobotC software offer functions to work with files. The NXT-G software provides a block to manipulate files on the NXT. This block supports read, write, close, and delete operations on files. For the read and write operations, it supports reading and writing of the data type as “text” or “number.”

The RobotC software has several advanced functions for file handling and manipulation. The read/write functions support data types such as byte, short, float, long, and string. RobotC also supports functions to search files that may be on the NXT.

Using File Space Efficiently

The file space on the NXT is limited, and it’s wise to use that space efficiently, as you never know when you will need to add that extra logic in your program.

You can delete a few files that come installed on the NXT, if you want to reclaim some space in lieu of functionality. For example, you can delete the Try Me programs, sound files, and so on. If you need that functionality at a later date, you can always download those files onto the NXT.

The key to efficient use of the file system is to write small programs. You can do so by reusing code wherever possible. The first time you use a block or function in your program, all the code required for that function needs to be linked into your program, and that increases the program’s size. Any subsequent use of the same block or function does not increase the program’s size much; rather, there is only a minuscule increase to account for the subsequent calls to that function. Lately, LEGO has been publishing mini versions of some popular blocks that are optimized to make smaller programs (for details, see Appendix A).

The LCD Screen

The NXT brick has an LCD screen that is much larger than its predecessor. The screen is a monochrome matrix of 100-by-64 pixels. When you are interacting with the NXT, the user interface on this LCD is your window to the NXT’s internals.

The firmware provides text as well as pixel-level support for drawing on this screen. You can also specify the name of an icon file that is residing on the NXT to draw as a picture. RobotC has several functions for displaying text on the screen. Using these functions, you can choose a large or small font and display text at any position on the screen. RobotC also has several functions for drawing lines, rectangles, circles, ellipses, and images on this screen. Figure 5.3 shows an example of text sizes and lines.

The LCD

Figure 5.3. The LCD

Here is the RobotC program that was used to create the screen image shown in Figure 5.3:

task main()
{
  // Display small font text lines
  nxtDisplayTextLine(l, "Building Robots") ;
  nxtDisplayTextLine(2, "with LEGO") ;
  nxtDisplayTextLine(3, "Mindstorms NXT") ;
  // Display large font text
  nxtDisplayBigStringAt(l, 20, "SYNGRESS") ;
  // Draw the lines
  nxtDrawLine(10, 28, 90, 28) ;
  nxtDrawLine(5, 25, 95, 25) ;
  // wait for a minute before ending the program
  wait10Msec(6000) ;
}

Games

One interesting feature the NXT offers for drawing images is its icon file format. The icon files have an .ric extension on the NXT file system. The file generally contains instructions which define the image. Unlike a bitmap image, this file can contain instructions with parameters for drawing lines, circles, rectangles, and so forth. Of course, the bitmap instruction is also available.

The format for these files is well defined, and the images the NXT software comes with use the same format. You can also create your own files and upload them on the NXT. Moreover, in theory, you could create such files from within your NXT program, and use them. That opens up numerous possibilities for game designers! There is, however, limited support for testing these files outside of the NXT. The NXT-G software can render only the bitmap instruction from this file format. The other instructions must be tested on the NXT itself.

Ross Crawford wrote a Tic-Tac-Toe game to run on the NXT screen (see Figure 5.4). The program uses the buttons on the NXT for choosing location and placing circles, and it uses the NXT features of drawing lines, circles, and text to draw the game board and messages (for details, see Appendix A).

Tic-Tac-Toe on the NXT

Figure 5.4. Tic-Tac-Toe on the NXT

The NXT display functions are also useful for making charts and graphs on the screen. With the NXT file system, as you will see in the next section, data gathering and logging are easy. You can write programs to read these files and, using the display functions, render this data as charts or graphs.

Digital Interfaces and Bluetooth

To communicate with sensors, motors, and other peripheral devices physically attached to the NXT, the new system introduces I2C and USB interfaces, whereas for wireless communication, the NXT has a Bluetooth interface. The USB interface is used to communicate with a Windows PC or a Macintosh, and I2C is used to communicate with sensors and motors.

The NXT software comes with required USB drivers, making the NXT a Plug and Play device. The USB system consists of a host device connecting multiple peripheral devices, with peripherals being able to connect to only one host. The USB interface on the NXT is a peripheral USB port, and thus it can connect to any computer with a USB host port. At the same time, you can’t attach another USB peripheral device, such as a memory stick, to the NXT and expect it to work.

The I2C interface, also known as IIC, is not a popular household name, but it is used in a wide array of gadgets and devices (and even in some household items). For instance, it is commonly used in electronics devices where space efficiency is key, such as mobile phones and PDAs. For the most part, you won’t have to work with the I2C interface directly, unless you are developing specialized hardware. In any case, this is a very versatile interface in the NXT, and it holds promise for a wide variety of next-generation attachments and extensions to the NXT system. Already a few third-party sensors are available that use the I2C interface, and more are being developed at a rapid pace. For more information on this, refer to Chapter 4, which covers the I2C interface in greater detail.

Bluetooth Communication

In addition to the wired interfaces mentioned previously, the NXT supports a wireless Bluetooth interface. This is a major improvement over the former infrared interface, which the RCX had, in terms of speed, power consumption, and standardization. The NXT can selectively turn this interface on and off through programming functions or on-screen menus, thus further controlling power consumption.

Bluetooth on the NXT can operate in either master or slave mode. While connecting to a PC, it is always in slave mode; however, you can configure it to operate in master mode while connecting to other slave NXTs. You can connect up to four NXTs to each other, with one being the master and the others being slaves.

Each NXT has a unique Bluetooth name, and this name is displayed on the top line of the screen. While referring to each other by this unique name, you can make a convoy of NXT robots that can work as a team!

A Surveillance Robot Using NXT and Bluetooth

The standardized Bluetooth interface also lets the NXT communicate with other Bluetooth-enabled devices. What does this mean? Well, as an example, sending commands to the NXT from a mobile phone is a breeze. You can attach a mobile phone to your NXT robot, send the robot on a surveillance mission, take photos or video, and have the mobile phone transmit the data to a computer!

For instance, Martyn Boogaarts developed a robot (see Appendix A) that has a camera attached for taking pictures (see Figure 5.5). The robot’s head swings around slowly in increments of 5 degrees. Using an ultrasonic sensor, it looks for any objects in its vicinity, and as soon as it spots an object, it sends Bluetooth commands to the camera to take a picture. Then it continues on its mission.

Coco5 by Martyn Boogaarts

Figure 5.5. Coco5 by Martyn Boogaarts

A Bluetooth-Based Remote Controller

Using the Bluetooth interface, the NXT motor, and a Mindsensors acceleration sensor, Philippe “Philo” Hurbain created a remote controller (see Figure 5.6) that transmits spatial information to an NXT robot (see Appendix A). Using the acceleration sensor, the remote controller transmits forward or backward tilt and left or right tilt information to the robot. In addition to this information, you can use your thumb to press the touch sensor on the left side to transmit on/off commands. There is a double-bevel gear on the motor that you also can turn with your thumb. Using this gear, the remote controller can transmit information such as rich motor encoder values, which the robot can use for navigating.

NXTiiMote Remote Controller

Figure 5.6. NXTiiMote Remote Controller

Spatial Motion Controllers

The Wii remote controller by Nintendo, popularly known as the Wiimote, is another amusing device that you can integrate with the NXT (see Figure 5.7). In fact, a few folks have tried to integrate the Wiimote with the NXT directly, with little success. The Wiimote uses the Bluetooth HID profile technology, whereas the NXT supports serial port profile technology. Unfortunately, these two don’t work together, unless you are good at hacking the Wiimote and you know what you are doing. However, it is possible to use a programmable mediation Bluetooth device which communicates on both profiles. A mobile phone running a special-purpose NXT Mobile Java application is a perfect example (see Appendix A for more information on NXT Mobile applications). The application would interpret Wiimote commands on the HID profile, and transmit them as serial commands to the NXT. Jose Bolaños created a robot (see Appendix A) for which he used a computer running a Bluetooth program as a mediation device.

Wiimote Integration

Figure 5.7. Wiimote Integration

I2C for Spatial Motion Controllers

Spatial motion interpretation on the NXT is not an unattainable ambition, though. Paul Tingey created a controller to steer and control the RobotArm-56 (see Appendix A). He used the Mindsensors compass and acceleration sensors for the motion sensing, and wired them to the NXT with a smart algorithm (see Figure 5.8).

Wii-like Controller

Figure 5.8. Wii-like Controller

Future Possibilities

If you could peer into a crystal ball to see future scenarios for using the NXT, what would you see? In this section we’ll describe some of them.

An NXT Robot Controlled from a Web Server

Imagine a robot to be sent on a mission to explore uncharted territory—say, a dark closet. You are the mission controller and you have all the computing power to design the control station. You want to see where the robot is going, and control and steer him in the right direction. At the same time, you want to let the robot have sufficient autonomy to do things on its own, such as negotiating its path to advance farther. And you may not be anywhere near the robot.

You can do this in several ways, and one of them is to create a Web-based application, which you can access from anywhere and anyplace, using any browser. The application would communicate with the NXT robot using Bluetooth and gather pictures from the robot, which would then be displayed on your browser. The steering controls that you design for the Web page would transmit the commands to the NXT in real time as you operate the controls.

While designing such a robot, you have choices for the Web application architecture, too. For example, if you were to go with the Internet Information Server (IIS), you would have plenty of support in .NET. If you chose to go with the Apache server, you would have adequate scripting support for Bluetooth communications. In fact, NXT-specific Bluetooth functions are available now for Perl, too.

NXT Puppet Show

Now imagine a stage designed for puppet shows; one similar in size to a LEGO theme—say, a meadow. In that meadow, a boy, made out of an NXT, is guarding his sheep, again made out of an NXT. The boy plays his flute for a while and falls asleep ... a feat which is now possible thanks to the sound capability on the NXT. The sheep is grazing around happily. From the edge of the table, the show performer places an NXT wolf in the meadow, and turns it on. As soon as the wolf comes to life, the sheep is scared and starts to scurry around. The wolf pounces at the sheep and knocks her down. The sheep is screaming, and all that sound wakes up the boy. The boy looks around, and finds the wolf and chases him away.

Okay, back to the drawing board. What do you need to make this kind of puppet show? The Bluetooth identifiers of NXTs can clearly differentiate the boy from the sheep or the wolf. As soon as the NXT is turned on, the Bluetooth identifier of the wolf can broadcast itself and the programs in the sheep can choose to respond to scurry around, whereas the programs in the boy ignore it. One hurdle in a story like this is locating other puppet, if the puppets are not predictably placed on the stage, or if they have moved around to a random location. To see things in the area, therefore, a third-party camera for the NXT would be great! As you can see, the possibilities for stories are limitless.

GPS and the NXT

Wouldn’t it be nice to let your robot wander around the neighborhood and let it know where it is? A distinct possibility: a robot that could deliver flowers at the other end of town, if it only knew the coordinates of the house! A GPS would come in handy here. A Bluetooth-enabled one.

Several Bluetooth GPS modules are available today. These modules are designed to connect to mobile devices, such as PDAs or laptops, and they provide location information. The actual mapping is done in the software running on the PDA or laptop. You can use the same concept in the NXT robot. There are a few hurdles, however. First, the GPS unit needs to be facing a clear sky, so your robot arena needs to be outdoors. Second, the GPS resolution, at best, is half a meter. Therefore, a small robot would be left on its own to position itself within that zone.

Summary

In this chapter, we covered several new introductions in the MINDSTORMS NXT system as compared with its predecessor, the RCX. Most of these introductions represent the latest technologies made available for your robot to play with.

For instance, the LCD screen provides a better user interface for the NXT, and allows users to create interactive games and other screen applications. The NXT file system is simple and provides several functions for manipulating files and their contents. And I2C and Bluetooth have opened up possibilities for integrating your robot with several other standardized gadgets and sensors.

As you can see, plenty of creative possibilities are within your reach. You just need to put your mind and your NXT to work!

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.249.174