Professional Documents
Culture Documents
Tutorial For Programming The LEGO® MINDSTORMS™ NXT
Tutorial For Programming The LEGO® MINDSTORMS™ NXT
3442 VU Introduction to Artificial Intelligence 06/07, Rolf Pfeifer, Prof., Dr. sc. techn.
2
2.1
2.2
2.3
Hardware
The NXT Brick
The Servo Motors
The Sensors
3
3.1
3.2
3.3
3.4
3.5
3.6
Software
Starting a Program
The Work Space
Creating a Simple Program
Connecting the NXT Brick to the Computer
Downloading a Program to the NXT Brick
Running a Downloaded Program
The next generation of LEGO MINDSTORMS just came on the market. The new NXT (Fig. 2) replaces the old RCX (Fig. 1). You
can create a LEGO agent, in as few as 30 minutes. The new NXT brick, your agent's controller features a 32-bit microprocessor and
more memory, plus support for USB 2.0, Bluetooth and more. But this doesnt mean that the controller has to be very complicated. With
an adequate morphology and exploited physical properties you can leave the controller very simple and get to the same result. A highly
versatile palette of LEGO TECHNIC elements combines with ultrasonic, sound, light and touch sensors in the next generation of
intuitive robotics. Improved light sensors can detect reflected light and calculate the intensity, while the new sound sensor enables
agents to respond to sound patterns and tones. The improved touch sensors can for example be used as collision sensors, while the
ultrasonic sensor measures the distance to obstacles and could be used as proximity sensors. The programming software is now
available both for PC and Macintosh, plus with Bluetooth support, you can even command your agent from your mobile phone.
Hardware
Fig. 2 The new NXT brick with three servo motors and sensors for touch, sound, light and
ultrasound.
Output Ports
(motors)
USB
Sensor Ports
The NXT has four input ports for attaching sensors ports
1, 2, 3 and 4.
USB Port
You can connect a USB cable to the USB port and
download programs from your computer to the NXT (or
upload data from the NXT to your computer). You can also
use the wireless Bluetooth connection for uploading and
downloading.
Loudspeaker
You can make a program with sounds and listen to them
when you run the program or let your agent communicate
with the environment.
NXT Buttons
Orange button: ON / Enter / Run
Light grey arrows: Used for moving left and right in the NXT
menu
Dark grey button: Clear / Go back
Loudspeaker
ON / Enter / Run
Clear / Go back
Input Ports
(sensors)
Fig. 3 The ports and buttons of the NXT brick.
Software
The LEGO MINDSTORMS NXT software enables you to program your NXT robotic invention and upload your programs to the NXT
via USB or Bluetooth connectivity. The intuitive Mac and PC compatible drag and drop software, powered by National Instruments
LabVIEW, comes with building instructions and programming guides to easily begin constructing and programming with
MINDSTORMS NXT.
If you want to create a new program, write its new name into the text-box. If you want to open an already existing program, select the
name of the program in the drop-down-box. Afterwards press the corresponding button Go.
First of all close the Robo Center frame (1) to get more space for your program. Then click on the tab with the three colored squares to
have the complete palette of blocks (2).
The complete palette should look like this. There you have, from top to bottom: common (1), action (output) (2), sensor (input) (3), flow
(4), data (5) and advanced blocks (6).
The arrow Pointer Tool is the default cursor to build your programs. To move the work space, select the second cursor Pan Tool,
drag and drop the work space to the desired point. To write a comment, select the third icon Comment Tool and click somewhere on
the work space.
This is the starting point of the program. Blocks connected to the starting point can be downloaded to the NXT; unconnected blocks
cannot.
The sequence beams control the flow of your program. To have several simultaneously running tasks, you can create parallel sequence
beams by holding down the Shift key and moving the mouse pointer over the starting point (or over a sequence beam), and pressing
and holding your mouse button while you move the mouse.
To build a program that runs endlessly, you have first to put a loop block on the work space. This block can be found under the flow
blocks. To put it on the work space just drag and drop it to the right-hand side of the starting point on the work space. If you put it on the
right place, you will see that the sequence beam will connect automatically the starting point with the loop block.
After having dropped it, click on the newly inserted block (1), if it hasnt already got the focus, so that you can see the control panel in
the bottom left corner (2). There you have to choose Forever in the drop-down-box.
To run a motor, insert the motor block, which is under the action blocks. Drop it into the already inserted loop block.
Once dropped, you can click on the motor block (1) and choose in the control panel (2) the port (which motor), the direction, the power
(velocity). The check-box Motor Power shouldnt be activated. Under Duration choose Unlimited. This is already your first little
program to run a motor forever with a constant velocity.
Now you have to send this program to the LEGO NXT brick. First you should connect the brick with the USB cable to the computer
and turn the brick on. Then you can press the button NXT window in the bottom right corner of the work space.
A small window should appear. If there is no entry in the list-box, click on Scan. If the list-box stays empty, check if the USB cable is
connected correctly. If there is an NXT, but it is unavailable, check if the brick is turned on. If one is available click on Connect. Now
the status should be Connected. On the right side you can see the battery level. Then you can close this window.
Now that the brick is connected, you can press the button Download to send the program to the brick. A small window will open. After
the download is completed this window closes automatically and a beep of the brick can be heard. Then you can remove the USB
cable.
10