You are previewing The Art of LEGO MINDSTORMS NXT-G Programming.
O'Reilly logo
The Art of LEGO MINDSTORMS NXT-G Programming

Book Description

The Art of LEGO MINDSTORMS NXT-G Programming teaches you how to create powerful programs using the LEGO MINDSTORMS NXT programming language, NXT-G. You'll learn how to program a basic robot to perform tasks such as line following, maze navigation, and object detection and how to combine programming elements (known as blocks) to create sophisticated programs.

Table of Contents

  1. The Art of LEGO® MINDSTORMS® NXT-G Programming
    1. acknowledgments
    2. introduction
      1. who this book is for
      2. prerequisites
      3. what to expect from this book
      4. how best to use this book
    3. 1. LEGO and robots: a great combination
      1. LEGO MINDSTORMS NXT
      2. the NXT online community
      3. the LEGO MINDSTORMS NXT kit
        1. NXT versions
        2. MINDSTORMS software versions
          1. version 1.0/1.1
          2. education 2.0
          3. retail 2.0
      4. art and engineering
      5. qualities of a good program
      6. software, firmware, and hardware
      7. NXT-G
      8. what you’ll learn from this book
      9. what’s next?
    4. 2. the NXT-G programming environment
      1. a tour through the MINDSTORMS environment
        1. a: work area
        2. b: programming palettes
        3. c: robo center
        4. d: my portal window
        5. e: configuration panel
        6. f: help panel
        7. g: navigation panel
        8. h: controller
      2. writing an NXT-G program
      3. your first program
        1. saving your work
      4. running your program
      5. your second program
      6. debugging
        1. reproduce the bug
        2. simplify the program
        3. look at the parts of the program
        4. fix the bug
      7. the edit-compile-test cycle
      8. comments
        1. adding comments
          1. the program description
          2. the comment tool
        2. rules for working with comments
      9. the configuration panel
        1. general layout
        2. changing panels
        3. disabled items
        4. a block’s configuration icons
      10. conclusion
    5. 3. the test robot
      1. right-side motor
      2. left-side motor
      3. chassis
      4. caster wheel
        1. caster wheel for the NXT 2.0 retail kit
        2. caster wheel for the original NXT retail kit and education set
      5. attach the caster wheel
      6. add the NXT
      7. touch sensor bumper
      8. attach the bumper to the chassis
      9. ultrasonic sensor
      10. sound sensor
      11. color sensor or light sensor
      12. attach the wires
      13. the final beam
      14. alternate placement for the color sensor
      15. alternate placement for the ultrasonic sensor
      16. conclusion
    6. 4. motion
      1. the NXT motor
      2. the move block
        1. the move block’s configuration panel
          1. port
          2. direction
          3. power
          4. duration
          5. steering
          6. next action
        2. the feedback boxes
        3. the NXT intelligent brick view menu
      3. there and back
        1. moving forward
        2. turning around
        3. testing a single block
        4. moving back to the start
      4. around the block
        1. the first side and corner
        2. the other three sides and corners
        3. testing the program
      5. the motor block
      6. brake, coast, and the reset motor block
        1. the CoastTest program
        2. a problem with coasting
          1. observing the problem
      7. the reset motor block
      8. the record/play block
        1. configuration panel
      9. the remote control tool
      10. conclusion
    7. 5. sensors
      1. using the sensors
      2. the touch sensor
        1. configuration panel
        2. feedback box
        3. the NXT’s view menu
      3. the BumperBot program
        1. detecting an obstacle
        2. backing up and turning around
        3. testing
      4. the sound sensor
        1. configuration panel
        2. setting the trigger value
      5. BumperBot with sound
      6. the light and color sensors
        1. light sensor configuration panel
        2. using the color sensor as a light sensor
      7. the RedOrBlue program
        1. determining red and blue values
        2. the switch block
        3. improving the program
          1. using the touch sensor
          2. adding a loop
        4. using color sensor mode
      8. the ultrasonic sensor
        1. configuration panel
      9. door chime
        1. detecting a person
        2. playing a chime
        3. stopping the chime
      10. the rotation sensor
        1. configuration panel
        2. the rotation sensor block
      11. the BumperBot2 program
      12. conclusion
    8. 6. program flow
      1. the sequence beam
      2. the switch block
        1. configuration panel
          1. the control setting
          2. the sensor setting
          3. setting the condition
          4. the display setting
        2. the LineFollower program
          1. the basic program
          2. selecting the light sensor trigger
          3. configuring the move blocks
          4. testing the program
        3. more than two choices
          1. setting the trigger values
          2. testing the program
        4. using tabbed view
        5. comments and tabbed view
      3. the loop block
      4. the keep alive block
      5. the stop block
        1. BumperBot3
      6. conclusion
    9. 7. the WallFollower program: navigating a maze
      1. pseudocode
      2. solving a maze
      3. program requirements
      4. assumptions
      5. initial design
      6. following a straight wall
        1. writing the code
        2. testing
      7. turning a corner
        1. writing the code
        2. testing
      8. going through an opening
        1. writing the code
        2. using sound blocks for debugging
        3. testing
      9. final test
      10. conclusion
    10. 8. data wires
      1. what is a data wire?
      2. the GentleStop program
      3. tips for drawing data wires
      4. the SoundMachine program
        1. controlling the volume
        2. using the math block
        3. adding tone control to the SoundMachine program
      5. understanding data types
      6. using the number to text block
      7. displaying the tone frequency
      8. using the text block
      9. adding labels to the displayed values
      10. dealing with broken wires
      11. conclusion
    11. 9. data wires and the switch block
      1. the switch block’s value option
      2. rewriting the GentleStop program
      3. advantages of using a sensor block
      4. passing data into a switch block
      5. passing data out of a switch block
      6. matching more than two values
        1. adding and removing conditions
        2. the default condition
      7. using numbers with the NXT-G 2.0 switch block
      8. fixing the SoundMachine program’s volume display
        1. calculating the input value using NXT-G 1.1
        2. calculating the input value using NXT-G 2.0
        3. modifying the program
      9. conclusion
    12. 10. data wires and the loop block
      1. the loop count
        1. creating the LoopCountTest program
        2. restarting a loop
        3. setting the final loop count value
        4. setting the loop condition
      2. timers
      3. the timer block
      4. a programmable timer, version 1
      5. the compare block
      6. a programmable timer, version 2
      7. a programmable timer, version 3
      8. conclusion
    13. 11. variables
      1. a place for your data
      2. managing variables
      3. the variable block
      4. the RedOrBlueCount program
        1. creating the variables
        2. initializing the variables
        3. initializing the display
        4. displaying the initial values
        5. counting the red objects
        6. counting the blue objects
      5. grouping common settings
      6. replacing long data wires with variables
      7. the LightPointer program
        1. defining the variables
        2. finding the light source
        3. initializing the values
        4. the LightPointer program, part 1
          1. finding the light source
          2. stopping the motors
        5. the LightPointer program, part 2
      8. constants
        1. managing constants
        2. the constant block
          1. choose from list
          2. custom
          3. working with custom constants
      9. conclusion
    14. 12. the NXT buttons and the display block
      1. the NXT buttons
      2. the NXT button block
      3. the PowerSetting program
        1. defining the variable
        2. the initial value and the loop
        3. displaying the current value
        4. adjusting the power value
        5. testing the program
        6. making the program faster
      4. the display block
        1. displaying an image
        2. power setting with images
          1. displaying the snail and rabbit
          2. display the arrow
        3. drawing on the screen
      5. the NXTSketch program
        1. defining the variables
        2. initialization
        3. drawing the line
        4. saving the new location
        5. testing the program
          1. fixing the dials for NXT-G 2.0
      6. conclusion
    15. 13. my blocks
      1. building bigger blocks
      2. creating a my block
      3. the custom palette
      4. editing a my block
      5. configuring a my block
      6. changing the name of a configuration item
      7. the DisplayNumber block
        1. configuration items
        2. controlling the line setting using a data wire
        3. building the DisplayNumber block
        4. testing
        5. creating the DisplayNumber block
        6. changing the names of the configuration items
      8. using the DisplayNumber block
      9. managing the custom palette
      10. sharing programs with my blocks
        1. copying files
        2. create pack and go
      11. advanced my block topics
        1. variables and my blocks
        2. nesting my blocks
        3. broken my blocks
        4. adding a data plug
      12. conclusion
    16. 14. math and logic
      1. computer math
      2. integer math
        1. range of values
        2. division
          1. order of operations
          2. scaling values
        3. odometer
      3. floating-point math
        1. range
        2. precision
        3. the number to text block
      4. the random block
      5. adding a random turn to BumperBot
      6. the logic block
      7. adding some logic to BumperBot
      8. the range block
      9. improving RedOrBlue
      10. improving RedOrBlueColorMode
      11. conclusion
    17. 15. files
      1. using files
      2. the file access block
        1. the filename
        2. the action setting
        3. the type setting
        4. saving the RedOrBlueCount data
      3. checking for errors
      4. the FileReader program
      5. restoring the RedOrBlueCount data
      6. managing memory
        1. deleting files
        2. transferring files
      7. common problems
      8. conclusion
    18. 16. data logging
      1. data collection and the NXT
      2. the VerifyLightPointer program
        1. collecting the brightness data
        2. running the program
        3. analyzing the data
        4. adding rotation sensor data and a timestamp
        5. gaps in the data
        6. setting the initial file size
      3. controlling the amount of data
      4. data logging using the LEGO MINDSTORMS education NXT software 2.0
        1. the data-logging blocks
        2. the VerifyLightPointer2 program
        3. the NXT data logging application
      5. conclusion
    19. 17. using multiple sequence beams
      1. multitasking
      2. adding a second sequence beam
      3. avoiding a busy loop
      4. adding a sequence beam to a loop block
        1. the crowbar and pin technique
        2. adding the sequence beam
        3. expanding the loop block
        4. making the light flash
      5. understanding program flow rules
        1. starting blocks and data wires
        2. starting a loop or switch block
        3. using values from a loop or switch block
        4. using my blocks
      6. synchronizing two sequence beams
        1. the AroundTheBlock program
        2. the DoorChime program
      7. keeping out of trouble
      8. conclusion
    20. 18. the LineFollower program
      1. following a line
        1. requirements
        2. assumptions
      2. the starting point
      3. selecting the sensor trigger values
        1. building the LineFollowerConfig program
        2. testing the LineFollowerConfig program
        3. changing the LineFollower program
          1. reading the high and low values
          2. calculating the trigger values
          3. using the trigger values
          4. testing the LineFollower program
          5. adding a pause at the beginning of the program
      4. improving the control algorithm
        1. how far from the edge?
          1. understanding the error value
          2. using percent error
          3. setting the range value
          4. calculating the error value
        2. controlling the motors
          1. using the motor block
        3. setting the power values
          1. understanding the process
          2. a few examples
          3. writing the code
          4. initializing the gain and power variables
        4. testing the program
      5. conclusion
    21. A. NXT websites
    22. B. moving from NXT-G 1.0/1.1 to NXT-G 2.0
      1. numbers
      2. block changes
      3. using old programs
      4. side-by-side installation
    23. Index
    24. About the Author
    25. updates