Lego mindstorms nxt-g programming guide pdf

Monday, February 18, 2019 admin Comments(0)

LEGO MINDSTORMS NXT-G Programming Guide is suitable for young programmers, age 10 and up, as well as parents and teachers Download book PDF. LEGO MINDSTORMS NXT-G Programming Guide, Second Edition. Copyright © by James Floyd For the LEGO MINDSTORMS team, past and present. James Kelly's LEGO MINDSTORMS NXT-G Programming Guide, Second Edition DRM-free; Included format: PDF; ebooks can be used on all reading devices.

Language: English, Spanish, Japanese
Country: Djibouti
Genre: Technology
Pages: 479
Published (Last): 03.04.2016
ISBN: 827-6-73633-184-3
ePub File Size: 17.61 MB
PDF File Size: 18.77 MB
Distribution: Free* [*Regsitration Required]
Downloads: 36977
Uploaded by: LAILA

By combining the power of the LEGO building system with the LEGO MINDSTORMS Education technology, teams of students can design, build, program, and. DOWNLOAD PDF Master the NXT-G language for programming LEGO MINDSTORMS robots. LEGO MINDSTORMS NXT-G Programming Guide, 2nd Edition is the perfect reference for NXT-G, and is now fully updated to cover the very. Power up your mind: learn faster, work smarter / Bill Lucas. p. cm. ways in which you can power up your mind and impr Load more similar PDF files.

SPOT, move forward. Numbers can be positive or negative, and sometimes they are limited to integers only numbers like -3, 0, 4, 8, or 10 and no numbers with decimal points like 4. You next use the Left Clip and Right Clip bars indicated in Figure to edit down your recorded sound to a five-second clip. Exercise Following is one possible solution to the task of instructing your partner to move one object next to another: Next, you need to save the new program and upload it to your Brick. Make Some Noise! If you get stuck, the answers are at the end of this chapter.

Provides programming techniques and easy-to-follow examples for each and every programming block Includes homework-style exercises for use by educators Gives clear instructions on how to build a test robot for use in running the example programs Please note: Show all. Table of contents 26 chapters Table of contents 26 chapters Robots and Programs Pages Program Structure Pages Hello World! Pages Record and Playback Pages Make Some Noise! True or False? Feedback Pages Wait for It! Round and Round Pages Decisions, Decisions Pages Stop It!

Pick a Card, Any Card Pages Apples and Oranges Pages Inside or Out? Basic Text Pages Basic Math Pages The last option in the Duration section is Seconds. When you choose this option, you must specify the number of seconds for the MOVE block to spin a motor or motors.

Like rotations, you can also specify fractional times such as 3. There are two options: Brake and Coast. Braking is useful if you need your robot to stop quickly and accurately at a specific point. However, keep in mind that this takes battery power. You can configure motors to brake or coast. Then choose the Coast option. You definitely want to try this out! Now, when I upload and run this program, SPOT rapidly moves forward 10 rotations about 6 feet and comes to a quick stop.

See Figure for the block programming of the pseudo-code. Program your robot to move forward for 10 rotations at a Power setting of 50, and set it to Brake. Now, run the program, and mark its stopping position with tape as well. Next, run the same program, but change the Brake option to Coast.

How far did it go beyond the previous stopping position? Finally, reduce the Power setting a little bit, and run the program again with the Coast option.

How far did it go beyond the stopping position this time? Keep reducing the Power setting and running the program until the robot stops at the original stopping position. Why am I asking you to do this? Recall that I told you that the Brake option uses up battery power. This test shows you that you can save battery power by reducing the Power setting and keeping the Coast option. Running tests like this will help you to figure out how best to program your robot to save battery power and to correctly perform its programmed actions!

Drive in a Circle Program your robot to roll forward in a circular pattern to the left or right using rotations for the Duration option. The curves of the S can be as large or as short as you like. Exercise Solutions Following are two possible solutions to the exercises. Remember that my solutions may vary somewhat from your own.

Exercise Figures through show the program and the three configuration panels for the three blocks used in this program. Notice that the MOVE block has its steering control dragged slightly to the right but not all the way; when I uploaded this to my robot, it caused the robot to move in a counterclockwise direction. Notice that the first MOVE block has its steering control dragged slightly to the right with a Duration setting of 3 rotations. This will have the robot rolling forward in a counterclockwise direction.

After 3 rotations of the motors, the second MOVE block will have the robot roll forward for 3 rotations, but this time the steering control is dragged to the left slightly. This will have the robot rolling forward in a clockwise direction, finishing the S-shaped path. Feel free to do what you like. I have motor A in Port A spinning a small propeller like an airplane on the front of the robot see Figure I know it seems like common sense, but I still need to say it: First, choose the Record option in the Action section.

Next, we need to specify a name for the recorded movement.

Pdf lego mindstorms guide nxt-g programming

I then want motor A to spin the propeller a few times. Give your recorded movement a unique name. The name you type in the Name text box is the name of a file that will be stored on the Brick.

This file must be stored on the Brick in order for you to later play back the movement, so try to make the name memorable and easy to understand. Now, look at Figure The Recording section of the configuration panel is where you will specify which ports should be monitored.

In my example, motors B and C will move my robot around, and motor A will spin the propeller. So I want to select all the ports. Configure the motor ports to monitor and record.

You can type in the number of seconds you want to record or click the up and down arrows with your mouse to select the number in the Time section.

Enter the number of seconds to record in the Time section. You can record anywhere from one second up into the hundreds of minutes. Is this realistic? Not really. And even recording a few minutes of movement will probably not leave much memory for your actual program. Place the robot at its starting position, and press the Run button for your new program. Using your hands, guide the robot through the movements you wish your robot to perform. I then turn the robot to the left and stop. If you come close to the number of seconds you configured, you can simply leave the recording time alone.

Most importantly, if you originally configured too much time, reduce the number of seconds you entered in the Time section; because the recording process will continue to run until the time is over, the file stored on the Brick will be larger than it needs to be.

Now, let me show you how to play back the file. This time, however, select the Play option in the Action section see Figure Rather than type the name of the file, you can select it from the list. If you do not have your NXT Brick connected, you will need to remember the name of the file and type it in the Name section.

Configure your robot to play back the recorded movement. The only other section that can be configured now is the Name section.

Type the name of the file that contains the recorded movements in the Name section see Figure Enter the name of the file you created during the Record process. Next, you need to save the new program and upload it to your Brick. Before you run the program, place your robot in the original starting position or wherever you like , and press the Run button to run the program. The robot will begin to move and will match the movements you recorded earlier.

Configure the times properly, and you can synchronize it to a speech given on the robot and its different components. Record a Cha-cha-cha Movement Record your robot performing a short 3—4 seconds cha-cha-cha movement—just wiggling back and forth in short movements. Roll Forwards and Backwards First Program your robot to roll forwards a few inches and then backwards a few inches using MOVE blocks… and then do a cha-cha-cha movement.

Have your robot perform this set of actions one more time. Chapter 6 will show you how to give your robot the ability to talk and make some noise!

Possible Solutions to Exercises Below are the solutions for the exercises I gave you earlier. Exercise 7 Figure contains the program and the single configuration panel used in this program. Save this program and upload it to your robot. Run the program and perform the back and forth movements for no more than five seconds. Exercise 8 Figures through contain the program and the configuration panels for the blocks used in this program. This instructs the robot to roll forward one rotation and then roll backwards one rotation… and then do the cha-cha-cha movement.

The last three blocks are simply repeats of the first three. Sound can be used to give a bot more personality. Think about how boring R2-D2 would be without all the chirps and whistles.


Action Settings The first section I want to cover is the Action section. You have two options: Sound File or Tone. See the section called File? Click one of the sound files, and if your computer has speakers, you will hear the sound file play.

There are over unique sound files that you can select from the list. The Sound File option allows you to select a sound from the File section. If you follow the instructions carefully, any new sounds you add will appear in the File listing in Figure Tone Now, select the other option, Tone. Notice that the File section changes to a section called Note see Figure The Tone option allows you to specify tones from the Note section.

Note Settings The Note section provides you with a few options. The easiest option is to simply click one of the piano keys. You will hear the tone played if your computer has speakers attached. Notice that when you click on a key, the note you click is displayed in the text box above the keys in the form of a letter: The other option available in the Note section is the ability to specify how long the note will play.

Type a number in the text box for the number of seconds to play the note. Now, let me explain each of these remaining sections. This section has two options: Play and Stop see Figure Select it, and any sound file or tone you selected in the Action section will play. Not too difficult, right?


The Stop option requires a little more explanation. To do this, I need to jump ahead to the Function section see Figure If the box is checked, the Sound File or Tone will continue to play until your program ends, or until another SOUND block is reached with the Stop option selected in the Control section.

If the box is unchecked, the sound file or tone will play only one time. Volume Settings OK, now for the Volume section. You can see in Figure that the Volume control can be changed either by using the slider or by typing a value 0 to in the text box. You will have to experiment with the Volume control to determine what works best for your robots, but keep in mind that loud sounds will use up more battery power than sounds played at a lower volume.

When you have selected a sound file or tone to play and the Repeat box in the Function section is not checked, the Wait for Completion checkbox is available. Let me give you an example using pseudo-code: SPOT, play me a C note for ten seconds and then move forward five rotations.

SPOT will first play a C note for ten seconds. Go ahead and create and run this same program on your bot. What happens? Well, I pressed the Run button and the C note started to play. But before the C note stopped, motors B and C started spinning. What happened? Go back to Figure , and notice that the Wait For Completion box is unchecked.

Nxt-g lego programming pdf mindstorms guide

Take a look again at the pseudo-code: SPOT, play a C note for ten seconds and then move forward five rotations. So, I make this change see Figure and run the program again. Now you can add sound files and tones to your robots to give them more personality. But before we finish this chapter, let me also tell you that sounds can be used when testing your robots. For example, in a complex program you can drop in a SOUND block to let you know when the robot has reached a certain portion of the program.

The newest version of NXT-G comes with a built-in tool called Sound Editor, which will allow you to create your own sounds for use with your robots—up to five seconds in length. Click on the Tools menu and select Sound Editor and the new tool will open, as shown in Figure You must connect an external microphone to your computer or laptop if it does not have one already built in. Press the Record button and begin recording your voice or other sound effect. Press the Record button again to stop the recording process.

I can use the Play button to listen to my recording. A recorded sound appears as a waveform in the center of the screen. You next use the Left Clip and Right Clip bars indicated in Figure to edit down your recorded sound to a five-second clip. If the sound wave between the two clip bars is red in color, the sound file is still too long. Continue to drag the left and right clip bars until the sound wave turns green.

Reduce the length of your sound using the clip bars. Click on the Save button and a window will appear, like the one in Figure Give your sound file a name save it to your computer. Give your sound a short but easy-to-remember name and click the Save button. As you can see in Figure , the sound Dangerous appears in the list.

Search for your sound file in the File listing. There are a few more things you can do with the Sound Editor. You can click the Open button and open an existing sound file either one of the pre-configured sounds or one of your own and perform more editing on it by using the left and right clip bars to increase or decrease its length.

RSO file extension. This means you can go out on the Internet and search for sound effects saved in the. RSO format that other NXT owners have created and are sharing; if you find one you like, save it to your hard drive, open Sound Editor, click the Open button, browse to the location of the sound file, and use the controls to edit it as needed.

You can find my solutions at the end of the chapter. Exercise Write a program for your robot that will have it spin in circles at the same time that it plays one sound file over and over. Set a limit for the MOVE block so it will stop after 20 rotations and the program will end.

Now, before we investigate any new blocks, I want to go over the different ways your robots receive input—this includes motors, sensors, timers, and the buttons on the Brick. Possible Solutions to Exercises Following are a couple of possible solutions to the exercises.

Remember, your solutions may not exactly match my own. Exercise Figures and show the program and the two configuration panels used in my solution to Exercise After 15—20 rotations, the program will terminate. Some of the questions I hear the most are related to data hubs and wires—and for good reason! And wires can be just as difficult to figure out.

In this chapter, I want to take a short break from learning about any new NXT-G programming blocks and give you some background and tips on how to use data hubs and wires.

I hope that any confusion you have will be cleared up by the end of this chapter. This block is shown in Figure It can hold one color. This block holds Blue.

It will always hold Blue and nothing else. There is no way to change the color. Think of the solid wall surrounding the block as keeping information from coming into the block or leaving the block. A Simple Solution What would make my color block useful to us? Well, first, it would be nice to be able to change the color.

I might not be able to do anything else with the block at this point, but at least it will contain my favorite color!

LEGO MINDSTORMS NXT-G Programming Guide | James Floyd Kelly | Apress

To do this, I need a way to access the wall surrounding the block. One of the things the block in Figure lacks is a way to get inside the block and change Blue to Green.

This color keyboard is a strange type of keyboard, though; it will only let me type colors. Now I can type Green. Later, if I want to change to Yellow or Red, I can simply type the new color, and the block will change.

This screen is just like my weird keyboard; it will only display a color. Figure shows my new color screen connected to the Green block.

I can change the color the COLOR block holds but only by using this special keyboard, and this keyboard will let me type in only colors. This special screen will display only colors and nothing else, not names or types of food. If I detach the color keyboard, can I still display the color inside? Yes, but only if I keep the color screen attached. If I detach the color screen, can I still change the color inside the block? Yes, again, but only if I keep the color keyboard attached.

There are some programming words for you in that description: When thinking about blocks, always remember that any information that is provided to a block is input. Any information that the block can give out share can be considered output. Take a look at the fake CUP block in Figure The CUP block is a little more complex.

The CUP block can hold three pieces of information: The COLOR block has an easier way for me to provide input to the block and to receive output from the block. The CUP block has a hub for connecting things. You can see in the figure that there are three input ports also called plugs on the left side of the hub and three output ports on the right side. These are where I will plug in keyboards, screens, and other items.

LEGO MINDSTORMS NXT-G Programming Guide - Second Edition

Figure shows three blocks with their hubs expanded. Normally an NXT-G block has its hub closed. Each of those little square plugs you see running down the left side of a hub is an input data port.

The small square plugs running down the right side are output data ports. Some blocks have more data ports than others, but the ports all work the same; they are simply a way to send data into a block and receive data out of a block.

For the Color input plug, I can only connect something that supplies a color. We already know that a color keyboard will work. I could connect a color keyboard and change the color of the cup from Blue to Green. Well, it has a data hub, too; it was just hidden inside the block. The input plug on the left side of the COLOR block is where I can plug in a color keyboard to change the color inside the block.

The output plug on the right can be connected to a color screen, but, in truth, it can be connected to any input plug that can accept a color. Notice the CUP block has an input plug that will accept a color! A logic keyboard is a very special keyboard—it can only be used to provide Yes or No answers not Maybe or Sometimes—only Yes or No. An Example What I would like to do with the CUP block is to connect it to a screen that will display one of two things but not both: To do this, I can use a screen to display the color and height that are provided by the CUP block Figure shows my setup so far.

Everything is hooked up and ready to use. But before I display the color and height, I need another special block that can examine the contents of the cup and determine if it is empty or not empty. It takes a Yes or No answer logic and, depending on the answer, performs action 1 or action 2. Action 1 will occur if the answer is Yes the cup is empty ; action 2 will occur if the answer is No for more information on logic, feel free to jump ahead to Chapter 8.

I can use this block to examine the contents of the CUP block. It will first look at the data plug labeled Empty. It then performs the actions required for a Yes answer.

Both types of data input and output can be provided by you by typing information in or selecting options in a configuration panel , or the data can be provided by other blocks using wires. I could go further and create a bunch of fake types of input. When it comes to NXT-G, you only need to know about three types of data: Letters, words, sentences, and even numbers can be considered text. Numbers can be positive or negative, and sometimes they are limited to integers only numbers like -3, 0, 4, 8, or 10 and no numbers with decimal points like 4.

This can be Yes or No another way to say it is True or False. The good news is that if you ever drag a wire from one plug to an incompatible plug if you try to drag a wire from a Text plug to a Logic plug, for example , the wire will be broken. By that, I mean that the wire will become a dashed gray line, indicating that you made a mistake.

You can see this in Figure That input data port is looking for a number specifically, a value of 1, 2, or 3 where 1 equals Motor A, 2 equals Motor B, and 3 equals Motor C.

This, too, will fail, as that input port is looking for a value of 1, 2, or 3. The Power input data port can receive a value from 0 to anything over is reduced to and anything less than 0 is converted to 0. Now, if you correctly connected a wire, the wire will have a color. This color depends on the type of data being sent over the wire: It takes practice to drag and connect wires from plug to plug.

Sometimes, the wires will do strange things and go off in strange directions. If you hover the mouse pointer over a data plug, it will show you the name of the data plug something like Empty or Height in my examples.

My last bit of good news is that you cannot ruin a program with incorrect wires! No worries! Wires can save you time by allowing you to use existing data over and over again; wires can be split, meaning you can split one wire and provide two different blocks with the same data!

The splitting occurs automatically when NXT-G detects you are dragging a wire from a data plug that already has a wire attached. You can see an example of this in Figure Data wires can be split and provide the same data to more than one port.

You also need to know that the help documentation contains a complete description of every data port, including a picture of each data port, what type of data it can send and receive and any limitations that exist such as a range of numbers or length of text.

Consult the Help documentation to discover the type of data a port can accept. Wires can also go in the other direction, so you can send an output wire from the end of your program all the way back to an input plug at the start of your program! Keep your eyes open throughout this book to learn some new ways to use wires.

Up next in Chapter 8 is a short discussion on a method robots use for making decisions, using Yes and No answers. What is the difference between the following two questions? Well, there are a lot of differences: My real point in asking these two questions is to point out that the first question is open-ended; the sky could be blue, or gray, or any number of answers.

The second question, however, has only two possible answers: Yes or No. When it comes to programming your robots, you need to understand that many times your robots can only provide you with those two answers: At other times, your robots can understand only a Yes or No answer.

SPOT, what color is the box in front of you? SPOT, what is the position of your Touch sensor button? SPOT, is the color of the box in front of you blue? Yes [appears on the LCD screen]. SPOT, is your Touch sensor button pressed? No [appears on the LCD screen]. Another way of saying this is that SPOT prefers to communicate using logical responses; a logical response is simply Yes or No.

On or Off! SPOT, is your Ultrasonic sensor detecting an object six inches in front of you? SPOT, is your Right button being pressed? What does all this have to do with programming, though? As an example, take a look at Figure If you are seeing only one data output plug on the data hub, click the data hub again to expand it to its full size.

What this tells you is that this data plug can provide output using a data wire in the form of a Logic data type. But how do you know if the output will be Yes or No? How do you know what it means when a sensor returns one answer or the other? Simple—the answer is based on what you are monitoring with the sensor. As an example, take a look at the new block in Figure Logic, Number, or Text.

Connecting two blocks with a wire When connecting blocks in a program using data wires, always keep in mind that a data wire will work only if it is connected to input and output plugs that expect the same data type Logic, Number, or Text. I also need to point out that many blocks hold either a True or False value as a default setting. The Logic data type can be found in many blocks, especially the sensor blocks see Figure It has been replaced with an extra Touch sensor.

Likewise, the NXT 2. Keep in mind that many blocks use a Yes or No answer to control actions. For the MOVE block, you can configure the direction forward or backward using the configuration panel; you simply click the Up or Down arrow in the Direction section to assign a spin direction.

But the direction of spin can also be controlled by sending a Yes or No signal to the Direction Data Plug see Figure A Yes signal is interpreted as Forward and a No signal is interpreted as Backward. The same concept works for the Next Action section—you can use a Yes signal to indicate that the robot should brake when the spin action is completed or a No signal to tell the robot to coast!

How might you use this? It has the Touch sensor mentioned earlier in this chapter. When I run the program, if I hold down the Touch sensor button the motors will spin in the forward direction for ten seconds before the program ends.

You can see in the Touch sensor configuration panel in Figure that I could have changed the Action to Released by selecting that option. If I had done this, what do you think would happen if I pressed the button when I started the program? A No signal means the motors will spin backwards!

Your robots will be able to interact with objects, avoid walls, detect light or dark rooms, and much more. And many of these abilities hinge on your robot being able to use Yes and No logic responses to make decisions. Examine it and determine what actions the robot will take given the following situation: If the lights are on and bright enough, the reading will usually be around 70—80, meaning the Light sensor will detect a light value greater than 50 and send a Yes or True signal to the MOVE block.

A Yes signal tells the motors to Brake. So, the Yes signal will override the Coast configuration panel setting and have the robot brake instead. What about the Light sensor? So, when the program runs, the motors will spin for three rotations at a Power setting of 50 and then the motors will brake.

The robot will sit for five seconds and then the program will end. Would it surprise you to learn that all of these items are able to provide some sort of feedback to the NXT Brick? The sensors are a little obvious; a sensor is designed to respond to external conditions such as light, touch, color, or sound and report this information to the Brick. But what about motors? And how can a timer be used as input or feedback to the Brick?

All these questions have answers, and this chapter provides them. A traffic light has three conditions: A light switch has two conditions: SPOT, move forward until the traffic light turns red.

The traffic light and light switch could then provide feedback, or input, to SPOT. SPOT, move forward until the Light sensor reports a value of The motors, too, can provide feedback: SPOT, when 20 seconds have elapsed, turn 90 degrees. You program your robot to perform specific actions based on the conditions of these items.

Just like you know a light switch has two conditions, on and off, you need to know the various conditions that the sensors, buttons, timers, and motors possess and can report to the Brick. Please note that I am also providing information on the so-called legacy items: If you are running the retail version, you may download NXT programming blocks for the RCX motors and sensors by visiting http: Click on the Patches option along the left side of the screen and download the files from the Legacy Block section for your specific language English, German, French, Japanese, and Dutch are the only options currently available.

First, sensors detect a change in a condition. The condition could be a change in light level, a change from seeing a blue ball to a red ball, a change in volume sound , or maybe a change in position movement. The Light sensor, for example, can detect changes in the level of lighting in the room. The Ultrasonic sensor is detecting changes in distance from an object or wall in front of it. Second, sensor programming blocks can respond only to one condition at a time.

When you drop a sensor block into an NXT-G program, it has to be configured to test one condition. A single Light sensor, for example, cannot be configured to respond to whether the light in a room is below 80 and greater than In order to test both conditions, you would need to use two Light sensor blocks in your program. In Chapter 8, we learned how logic values can be sent and received between NXT-G blocks using data plugs. Well, sensors can provide a Logic type response, True or False, depending on the conditions that their respective configuration panels are programmed to detect.

These light sensors are programmed to examine the conditions of the traffic light. Cars will move while the light is green and stop when the light is red.

If the light is yellow, the car will slow down. For example, a Light sensor can provide a numeric value related to the light level in a room.

The Sound sensor can provide a decibel level. These traffic light sensors, then, can detect one of three possible conditions: An NXT sensor can check only one condition, so if this were an NXT traffic light sensor, each car would require three traffic light sensors: Notice that only one condition can be true at any given time; the light cannot be green and red at the same time.

So when the sensor detecting green is triggered, yellow and red cannot be triggered. The default port for the Touch sensor is Port 1. In the Action section, you can select Pressed, Released, or Bumped. Remember that Bumped means quickly pressing and releasing the button—less than.

This value can also be used as output by dragging a data wire out of the output Port data plug. The Action data plug can use a Number data type with an input value of 0 for Pressed, 1 for Released, or 2 for Bumped.

It can send and receive a Logic data type. The Raw Value data plug can provide an output Number value with a range of 0— The Logical Number data plug provides a 1 for pressed and a 0 for released.

Mindstorms nxt-g pdf lego programming guide

Instead of a logic value, however, this data is a Number data type. This comes only with the 2. You can always consult this Help documentation to determine the data types for the various data plugs Number, Logic, or Text. Data hub details for the Touch sensor are described. The default port for the Sound sensor is Port 2.

In the Compare section, you must configure the sound value 0— as well as whether the sensor will monitor for sounds less than or greater than the configured value. You can use the drag bar to select the value or enter a numeric value in the range of 0— in the text box. Select the less-than option from the drop-down menu or click the left or right radio button to configure this option.

The default port for the Light sensor is Port 3. In the Compare section, you must configure the light value 0— as well as whether the sensor will monitor for a light value less than or greater than the configured value.

Select the less-than option from the drop-down menu, or click on the left or right radio button to configure this option. If you uncheck the box, the Light sensor will detect only ambient light levels—that is, normal light conditions.

Select the less-than option from the drop-down menu, or click the left or right radio button to configure this option. The default port for the Ultrasonic sensor is Port 4. In the Compare section, you must configure the Distance value as well as whether the sensor will monitor for a distance value less than or greater than the configured value. You can use the drag bar to select the value in the range of 0—, or you may type a value in the text box with a lower limit of 0 but an upper value greater than Using the drag bar limits you to a range of 0—, but you are able to type in a value greater than In the Show section, select either Centimeters or Inches from the drop-down menu.

The default port for the Rotation sensor is Port A. In the Action section, you should select the Read option if you want the built-in rotation sensor to monitor the value count returned by the sensor. Select the Reset option to set the sensor count back to zero.

Select Degrees or Rotations from the bottom drop-down menu, and enter a numeric value in the text box. You must also decide whether the sensor will monitor for a value less than or greater than the configured value by selecting the option in the other drop-down menu. With NXT-G 2. Its configuration panel is shown in Figure The default port for the Color sensor is Port 3. In the Action section, you can select the Light Sensor option, which will allow you to use the Color sensor as a Light sensor.

If the Color Sensor selection is left in the Action section, click the drop-down menu for the Compare section and select either Inside Range or Outside Range. You then use the two small drag bars to define a single color or a range of colors to check. I select the Outside Range for the comparison so the Color sensor can report a True signal if a detected color falls outside that range. The NXT Color sensor can detect ranges of colors. The default port for the Temperature sensor is Port 4.

In the Compare section, you must enter a numeric Temperature value in the text box or use the drag bar to set a value. The value for Celsius must be in the range of negative 20 to The value for Fahrenheit must be in the range of -4 negative 4 to In the Show section, select either Fahrenheit or Celsius from the drop-down menu.

The value ranges the sensor can monitor are determined by this selection. When that condition is met, the block is capable of sending a True or Yes signal to another block via a data wire.

If the condition is not met, the block can be programmed, once again using a data wire, to send a False or No signal. How would you, for example, take the Intensity value of the Light sensor 0— and have that value control the speed of the motors? Thus, a brightly lit room would make your robot move faster, vs. Left, Right, Enter orange , and Cancel. The Cancel button cannot be used as input; its function is simply to cancel a running program, or if you are navigating around the on-screen LCD tools, it can be used to move back to a previous screen.

That leaves the Left, Right, and Enter buttons—any program you create can use these three buttons to provide input. The NXT buttons are configured here. In the Button section, select the button Enter, Left, or Right from the drop-down menu. The default selection is the Enter button. In the Action section, select Pressed, Released, or Bumped. These work just like the Touch sensor, by the way.

The NXT Brick also has three built-in timers. These timers begin counting the moment you press the Enter button to begin running a program. The NXT Timer configuration panel In the Timer section, select 1, 2, or 3 from the drop-down menu to select the timer you wish to use. The default selection is Timer 1. In the Action section, select the Read option to obtain the current value of the timer.

If you select Reset, the timer will be reset to zero when this block is executed. The Compare section allows you to specify a value in seconds as a trigger that can be tested. For example, if you configure the TIMER block for greater than ten seconds for Timer 1, the Logic data plug will provide a False response until Timer 1 exceeds ten seconds.

After that, the data plug will provide a True response. When the condition is not met, a False or No logic signal will be sent. But what about all those other data plugs in a sensor block? Glad you asked. Take a look at Figures through A program using data plugs for control and the configuration panel for the Touch sensor Figure Notice first that when the program is executed the Touch sensor will send a Yes signal to the MOVE block via a wire if the button is Pressed.

At the same time, if it detects the light level is greater than 50, it will send a Yes signal via a logic data wire to the Direction data plug on the MOVE block and have the motors spin in a Forward direction a No signal will spin the motors backward.

In a slightly darker room with an Intensity value greater than 0 but less than 50 , the robot will not only roll slower but it will also roll backwards!

Finally, after the motors complete their movement, the program will pause for ten seconds before ending. Are you beginning to see how each data plug in a block can be used to control other blocks? Sensors are the best for doing this because they have so many different data plugs that can supply different signals.

With some experimenting, you can easily program your robots so they make left turns when the Sound sensor detects a loud CLAP! Easy—just program its Light or Color sensor block to detect a bright light hitting its surface and tell the robot to roll backwards, away from the light.

With the various sensors available to you, you have the ability to give your robot some real decisionmaking skills. Run from a light or loud sound? Move closer and inspect? Shut down and hibernate? Detect a nearby wall? Move closer or farther away? Your creativity and skill with using data wires is your only limit.

Now, before leaving this chapter, try your hand at creating a small program that satisfies the requirement specified in Exercise Exercise Create a small program that takes the Sound level range of 0 to detected when the program first executes and uses it to control the Power of the motors. The robot should also use its Ultrasonic sensor to see if anything is directly in front of it and no closer than five inches. If something is five inches or closer, it needs to roll away from the obstacle instead of closer to it.

This chapter showed you only how to configure a handful of blocks using the configuration panel and perform some small tricks with data wires. Chapter 11 will show you how to use the LOOP block to repeat certain tasks. When using a LOOP block, you can have the block loop forever, that is, perform the tasks over and over again until you cancel the program. Your other option is to configure the LOOP block to stop looping when a certain condition is met—for example, if the Light sensor detects a light level below 20, the Sound sensor detects a noise over level 80, or maybe a motor spins more than 20 degrees Rotation sensor.

Exercise Solution Figures to display the blocks and the three configuration panels used in this program. One of the most useful things your robots will be doing is waiting. Yep, you heard me right—waiting. Okay, think about it this way: Your robots will probably always be waiting for something to happen. It may be as simple as waiting for you to press the Enter button on the Brick or something similar to the preceding examples. The WAIT block will stop waiting when a specific condition is met.

Until the condition is met, the WAIT block will essentially pause the program and keep it from executing any more blocks. So, to show you how this works, let me give SPOT some more pseudo-code: SPOT, keep moving forward until something happens. Well, it can be anything: Do you get the idea?

I want SPOT to keep moving forward until a special condition is met. Open the NXT-G software, and start a new program. The WAIT block is our answer. When you move your mouse pointer over the WAIT block, a fly-out menu appears with six options see Figure There are six WAIT blocks that can be selected. The first is a drop-down menu in the Control section.

Go ahead and save the program, upload it to your bot, and then run it. Did the motors run for ten seconds and then stop? To get started, let me give you a shortcut for changing the type of the WAIT block. When you change to Sensor, you now have a new configuration panel section called Sensor with another drop-down menu.

Click the drop-down menu, and take a look at your options shown in Figure Owners of the 1. Refer to Chapter 9 for details on the configuration panels for the sensors, NXT buttons, and timers.

LEGO MINDSTORMS NXT-G Programming Guide (eBook, PDF)

When this occurs, the motors will stop spinning, and SPOT will stop moving forward. In this example, the WAIT block has been configured to wait until the Sound sensor detects a sound level below All timers start counting immediately when you run a program.

Now you can configure your robots to wait for a variety of different conditions. Exercise SPOT needs to navigate a cluttered floor. When the program starts by selecting the program and pressing the Enter button , have SPOT wait until the Touch sensor button is pressed and released bumped before beginning to roll forward.

When the red tape is detected, have SPOT stop, turn left 90 degrees , and then roll forward towards the wall. SPOT should continue to roll forward until the Ultrasonic sensor detects the wall is three inches in front of the robot. You know how to make your robot wait and wait and wait—but do you know how to make your robot do something else over and over again?

Exercise Solution Figures through show the complete program and configuration panels for Exercise You will also need to experiment with the value for Degrees in the second and fourth MOVE blocks to get your robot to make a good degree turn. Do It Again and Again and Again. SPOT, I want you to move forward six rotations, stop, and turn right 90 degrees. SPOT, move forward six rotations, stop, and turn right 90 degrees. I then repeat this pattern three more times, for a total of eight MOVE blocks.

But it seems like a lot of work just to make SPOT drive around in a square and return to his starting position. Is there a better way? SPOT, I want you to repeat my first set of instructions three more times. I only had to tell him the instructions one time and ask him to do them again three more times. You should be able to find the commands for SPOT: But what is a condition? Remember, a condition is simply a rule your robot SPOT must follow and meet before the program can continue or end.

Instead of telling him to repeat it three times, could I have used a different condition? Sure—here are some examples: SPOT, I want you to repeat my first set of instructions until your internal timer goes over 45 seconds.

SPOT, I want you to repeat my first set of instructions forever. He is executing a loop! A programming loop is very similar. It just circles back on itself, either forever or until you program an escape from the loop. Let me give you an example. This continues until I get tired of watching him, and I cancel the program.

Remember, the condition is a rule that the bot must follow. The rule for this program is for the LOOP to continue forever, so it runs again and again and again—you get the picture.

The Control section has a drop-down menu. Let me start with one of the easiest of the bunch: Select Time from the drop-down menu in the Control section, and the configuration panel will change see Figure This is the amount of time that any programming blocks inside the LOOP block will run. Earlier I mentioned that a loop will cycle forever until you program an escape. And that escape goes by another term—loop break. A loop break occurs when the loop stops. After the loop breaks, your program will continue with the next programming block, or it will stop if the LOOP block is the last block in your program.

The loop can break if you cancel the program, but it can also be configured to break when a specific condition is met. I need to make one important point: So if you configure your LOOP block to run for 25 seconds and the blocks inside take 40 seconds to finish one run, the second time limit will expire before the internal blocks are finished, so the LOOP block will not loop again.

What happens if the blocks inside take 15 seconds to run? Well, when the LOOP block starts, the timer begins counting down from After the blocks inside have completed their first run, there are still ten seconds left on the timer. So the program jumps back to the start of the LOOP block and runs the inner blocks again. But this time, the timer will run down to zero before the blocks have completed. When the blocks have finished executing, the LOOP block checks the timer, sees that time has expired, and breaks the loop.

The other section, Show, has one option: