You are previewing Winning LEGO MINDSTORMS Programming.
O'Reilly logo
Winning LEGO MINDSTORMS Programming

Book Description

Winning LEGO MINDSTORMS Programming is your ticket to successfully programming for fun and competition with LEGO MINDSTORMS and the NXT-G programming language commonly used in FIRST LEGO League events. The book is a companion title to author James Trobaugh's acclaimed book on physical robot design, Winning Design!. This new book focuses squarely on the programming side of working with MINDSTORMS. Together the two books put you on a rock-solid foundation for creating with LEGO MINDSTORMS, whether for fun at home or in competition with a team.

Winning LEGO MINDSTORMS Programming sets the stage by emphasizing the importance of up front planning, and thinking about the challenge to be met. Learn to evaluate possible solutions by sanity-testing their logic before you put the effort into actually writing the code. Then choose your best option and write the code applying the techniques in this book. Take advantage of language features such as MyBlocks to enhance reliability and create easy-to-debug code. Manage your code as you change and improve it so that you can trace what you've done and fall back if needed. Avoid common programming pitfalls. Work powerfully with teammates to conquer competition challenges of all types.

  • Provides solid techniques similar to those used by professional programmers, and optimized for the LEGO MINDSTORMS platform.

  • Addresses key tasks important to competition such as line detection, line following, squaring of corners, motor stall detection, and more.

  • Compliments Winning Design! by tackling the programming side of competition.

What you'll learn

  • Write programs to give your team an edge in competition.

  • Avoid common programming pitfalls that can cost points.

  • Write well-planned code easily adapted as you refine your approach to a challenge.

  • Collaborate with teammates in presenting a clear understanding of your coding solution to competition judges.

  • Improve your ability to wield each of the MINDSTORM NXT sensors.

  • Explore tips & tricks that can be used in robot competitions, and for fun.

  • Plan ahead for debugging and troubleshooting.

Who this book is for

Winning LEGO MINDSTORMS Programming is aimed at those wanting to improve their ability to create and deploy LEGO MINDSTORMS robots that are predictable and reliable at navigating competition challenges, and for fun at home.

Table of Contents

  1. Title
  2. Dedication
  3. Contents at a Glance
  4. Contents
  5. About the Authors
  6. About the Technical Reviewer
  7. Acknowledgments
  8. Introduction
  9. Chapter 1: Meeting the NXT-G Software
    1. Flavors of NXT-G
    2. Connecting the NXT
    3. Summary
  10. Chapter 2: Software Design Process
    1. Choosing the Right Problem
    2. Define the Problem
    3. Write Pseudo code
    4. Identify Possible Solutions
    5. Create the Code
    6. Test the Solution
    7. Summary
  11. Chapter 3: Working with My Blocks
    1. Why use My Blocks?
    2. Starting Off Simple
    3. Editing My Block contents
    4. Using a My Block
    5. My Block Properties
    6. Managing and Sharing My Blocks
    7. Summary
  12. Chapter 4: When Things Go Wrong
    1. Walking the Code
    2. Viewing Values
    3. Breaking the code down
    4. Common Mistakes
    5. Environment
    6. Summary
  13. Chapter 5: Moving Data
    1. Data Wires
    2. Variables
    3. Constants
    4. Summary
  14. Chapter 6: Making Smart Decisions
    1. Switch Block
    2. Logic Block
    3. Compare Block
    4. Range Block
    5. Summary
  15. Chapter 7: Motors and Motion
    1. Wheel Circumference
    2. Programming to Go Straight
    3. Turning the Robot
    4. Stall Detection
    5. Summary
  16. Chapter 8: Light Detection
    1. NXT Light sensor
    2. Calibration
    3. Line Following
    4. Line Detection
    5. Summary
  17. Chapter 9: Touching and Bumping
    1. The Touch Sensor
    2. Using the Touch Sensor
    3. When Is Pressed Not Pressed?
    4. Determining When to Turn
    5. Squaring Up
    6. Remote NXT Orange Button
    7. Limit Switch
    8. Touch Sensor As an Indicator of an Object
    9. Summary
  18. Chapter 10: Seeing with Ultrasonics
    1. How It Works
    2. Making It Work on the Game Field
    3. Finding Nearby Objects
    4. Summary
  19. Chapter 11: Programming Like a Pro
    1. Data Arrays
    2. State Machines
    3. Master Programs
    4. Summary
  20. Chapter 12: Code Management
    1. Single-Computer Scenario
    2. Multiple-Computer Scenario
    3. Online Repositories
    4. Flash Drives
    5. File Naming
    6. Pack and Go
    7. Code Comments
    8. Summary
  21. Chapter 13: Programming Pitfalls
    1. Block and Program Defaults
    2. Port Defaults
    3. The Yellow-Orange Error
    4. Bad Data Wires
    5. Use of Stop Block Instead of Stop Motors
    6. Hardware/Software Mismatches
    7. Changing Units of Measure
    8. Forgetting What You Meant
    9. Conclusion
  22. Chapter 14: Tips and Tricks
    1. Understand Your Program Flow
    2. Manage Your Data Flow
    3. Debugging Tips
    4. Apply Design Patterns
    5. Understand What You Wrote
    6. Know How to Navigate Your Program
    7. Hardware Tips That Help the Software
    8. Consolidate Logic into My Blocks
    9. Keep Your NXT Firmware Updated
    10. Don’t Reinvent the Wheel
    11. Summary
  23. Index