This book can be used with any NXT set and any version of the MINDSTORMS software. To test your programs, youll use a single, general-purpose robot that you can build with any NXT set. There are only a few relevant differences between the NXT software versions, and Ill point them out as appropriate. Almost all the material presented in this book applies to any version of the MINDSTORMS software.
No previous programming experience is required. NXT-G is a great first programming language, and Ill explain how to use the MINDSTORMS software and each of the elements of the NXT-G language.
what to expect from this book
This book focuses on programming NXT robots, rather than on the mechanical aspects of building them. Youll learn how to work with the core parts of the NXT-G language, such as the blocks, data wires, files, and variables, and youll see how these pieces can work together. Youll also learn some good programming practices, bad habits to avoid, and debugging strategies that will help keep your frustration level low so you can have fun while programming. Youll find numerous NXT-G programs with step-by-step instructions and explanations, as well as many small examples designed to help you understand exactly how NXT-G works.
All of the programs in this book will work with the general-purpose robot or the NXT Intelligent Brick alone. This is a book about programming NXT, not about constructing robots. As such, Ive devoted as many pages as possible to in-depth coverage of the most important programming topics.
The book begins with an introduction to the NXT set and the MINDSTORMS software. This is followed by the building instructions for the test robot. The next few chapters cover the basics of the NXT-G language, culminating in a maze-solving program in . Chapters covering the more advanced language features follow, and the book finishes up with a sophisticated line-following program. Heres an overview of the contents of each chapter.
This chapter provides a brief introduction to the LEGO MINDSTORMS NXT set and the NXT-G language. Ill also discuss the general process used for creating programs.
In this chapter youll find an in-depth tour through the features of the MINDSTORMS software. Youll create some simple programs and learn the basic steps for debugging problems.
The building instructions for the test robot are given in this chapter. Youll use this general-purpose robot to test the programs in the remainder of the book.
In this chapter youll learn about the NXT motors and the NXT-G blocks that control them. Youll write several programs to learn how to make your robot move using the Move and Motor blocks.
This chapter covers the NXT sensors: the Touch, Sound, Light, Color, Ultrasonic, and Rotation Sensors. Youll learn common uses for each sensor type, as well as how to use NXT-G to control the sensors. Ive also included example programs that teach you how to use each sensor.
The Switch and Loop blocks are the main focus of this chapter. Youll learn the Switch blocks various options for making decisions and how to use the Loop block to perform repeated actions. Ill also discuss the Keep Alive block and the Stop block, as they also are related to program flow. Youll use the Switch and Loop blocks, as well as some sensor and motor blocks, to write a simple line-following program.
By the time you get to this point in the book, youll have learned the basic features of NXT-G. This chapter walks you through the process of creating a complete program to solve a maze using a wall-following method. This chapter focuses on learning how to design, create, and debug a large program.
Data wires are one of the most powerful features of the NXT-G language. This chapter shows you what data wires are and how to use them effectively. The discussion includes coverage of data types and introduces some blocks that are used exclusively with data wires, including the Math, Number to Text, and Text blocks. To get some practice using data wires, youll write the SoundMachine program, which turns your robot into a sound generator.
In this chapter youll learn how to use a data wire to control a Switch block. Youll also learn about the special rules in NXT-G for moving data between the blocks inside a Switch block and the blocks that come before or after the Switch block.
In this chapter youll learn how to use data wires to control a Loop block. Youll learn about the NXT timers and then use the features of the Loop block to create three different programmable timers, each with its own advantages.
Variables are used for storing values that your program uses. In this chapter youll learn how to create and use variables, and youll see how they relate to data wires. Ill also discuss constants, which are new to NXT-G 2.0.