VISIT US AT Syngress is committed to publishing high-quality books for IT Professionals and deliv- ering those books in media and formats that fit the demands of our customers. We are also committed to extending the utility of the book you purchase via additional mate- rials available from our Web site. SOLUTIONS WEB SITE To register your book, visit www.syngress.com/solutions. Once registered, you can access our [email protected] Web pages. There you may find an assortment of value- added features such as free e-books related to the topic of this book, URLs of related Web sites, FAQs from the book, corrections, and any updates from the author(s). ULTIMATE CDs Our Ultimate CD product line offers our readers budget-conscious compilations of some of our best-selling backlist titles in Adobe PDF form. These CDs are the perfect way to extend your reference library on key topics pertaining to your area of expertise, including Cisco Engineering, Microsoft Windows System Administration, CyberCrime Investigation, Open Source Security, and Firewall Configuration, to name a few. DOWNLOADABLE E-BOOKS For readers who can't wait for hard copy, we offer most of our titles in downloadable Adobe PDF form. These e-books are often available weeks before hard copies, and are priced affordably. SYNGRESS OUTLET Our outlet store at syngress.com features overstocked, out-of-print, or slightly hurt books at significant savings. SITE LICENSING Syngress has a well-established program for site licensing our e-books onto servers in corporations, educational institutions, and large organizations. Contact us at sales@syn- gress.com for more information. CUSTOM PUBLISHING Many organizations welcome the ability to combine parts of multiple Syngress books, as well as their own content, into a single volume for their own internal use. Contact us at [email protected] for more information. s ',' N R E s s* This Page Intentionally Left Blank "~ ii!!iiii¸li ll :i!:!iii: :::! ::!ii!:~¸ !~ iiii '¸'~¸¸~¸~,~'~.,~. . . "~' iii!iii!iii!i!iii!i!i!i!iiii~!i!i!i!i!i!i!i!i!!i~!;~,,,,~ i~l!!!!!!T: ..... , ......................................... BUILDI NG ROBOTS WITH ~'~!. ..... ~i:: / ' ...... ~iii~:~,i,~~.. .. ,~ii~~ ~,,!~ " ~::'~'i~i~:~ ~ ! ~ ~i!~i~' ~,~. ................................................~.... .... ............ iii ii ........ ...............,~..... ..... ~!~'i~.. ............................~..,.~..i.~..,. .~..i.~. !~.. ........: '~i~iii~ ~ ".. ....... iiii!i!~ ~,.:.~.. ......................i.i..i..~. :~i~,~ ii~, ~ i~, . , ............................ ~:~ ~!i! .........i.~...i.~ ~'~ ~ ........ iii .............................. !iii~~I ............. ~':~:'"~'~J ::,~,~:::.~.:.~... .................... ~.. ...................~..:,.~ .:~.... ......................................................~..... ........................................ . ....... L ......... Elsevier, Inc., the author(s), and any person or firm involved in the writing, editing, or production (collectively "Makers") of this book ("the Work") do not guarantee or warrant the results to be obtained from the Work. There is no guarantee of any kind, expressed or implied, regarding the Work or its contents. The Work is sold AS IS and WITHOUT WARRANTY.You may have other legal rights, which vary from state to state. In no event will Makers be liable to you for damages, including any loss of profits, lost savings, or other incidental or consequential damages arising out from the Work or its contents. Because some states do not allow the exclusion or limitation of liability for consequential or incidental damages, the above limitation may not apply to you. You should always use reasonable care, including backup and other appropriate precautions, when working with computers, networks, data, and files. Syngress Media| Syngress| "Career Advancement Through Skill Enhancement| "Ask the Author UPDATE| and "Hack Proofing| are registered trademarks of Elsevier, Inc. "Syngress: The Definition of a Serious Security Library ''TM, "Mission CriticalTg, '' and "The Only Way to Stop a Hacker is to Think Like One TM'' are trademarks of Elsevier, Inc. Brands and product names mentioned in this book are trademarks or service marks of their respective companies. KEY SERIAL NUMBER 001 HJIRTCV764 002 PO9873D5FG 003 829KM8NJH2 004 BPOQ48722D 005 CVPLQ6WQ23 006 VBP965T5T5 007 HJJJ863WD3E 008 2987GVTWMK 009 629MP5SDJT 010 IMWQ295T6T PUBLISHED BY Syngress Publishing, Inc. Elsevier, Inc. 30 Corporate Drive Burlington, MA 01803 Building Robots with LEGO Mindstorms NXT Copyright (cid:14)9 2007 by Elsevier, Inc. All rights reserved. Printed in the United States of America. Except as permitted under the Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher, with the exception that the program listings may be entered, stored, and executed in a computer system, but they may not be reproduced for publication. Printed in the United States of America 1 2 3 4 5 6 7 8 9 0 ISBN-13:9781597491525 Publisher: Amorette Pedersen Project Manager: Gary Byrne Acquisitions Editor: Andrew Williams Page Layout and Art: Patricia Lupien Technical Editor: Dave Astolfo Copy Editor: Audrey Doyle Cover Designer: Michael Kavish Indexer: J. Edmund Rush For information on rights, translations, and bulk sales, contact Matt Pedersen, Commercial Sales Director and Rights, at Syngress Publishing; email Dave Astolfo (GIS A.S.) is a Project Manager/Business Analyst with the technical arm of a North American environmental consulting company. He currently provides project management, technical consulting, database design, and software architecture with a focus on geographic information systems ranging from desktop mapping software to Web mapping portals and mobile software applications. His specialties include database modeling and software design/architecture. Dave is a key contributor to the business development and implementation of products and services. As such, he develops enterprisewide technology solutions and methodologies focused on client organizations. Dave holds a bachelor's degree from Trent University and is a certified Geographic Information Systems Applications Specialist holding a certifi- cate from Sir Sandford Fleming College. In early 2006, Dave was invited by LEGO to participate in the LEGO MINDSTORMS Developer Program (MDP) to help LEGO beta test the prerelease of the LEGO MIND- STORMS NXT robotics system. After the release of the NXT, Dave was invited back to participate in the LEGO MINDSTORMS Community Partner Program (MCP) to work with LEGO in developing the product further while providing an ear to the community. Dave has been involved with LEGO all of his life, and he has been working with the MIND- STORMS product since the initial release of the LEGO MINDSTORMS Robotics Invention System (RIS) in 1998. Dave is well known for building a MINDSTORMS domino-placing robot that was published in a previous Syngress book (10 Cool Leg o Ultimate Builders Leg,o Mindstorms Robots, ISBN" 1-931-836-60-4). Since then, he has created newer versions with a more recent NXT version being used by LEGO marketing staff in Europe. Visit Dave's Web site, www.plastibots.com, for more information on his work. Called the "DaVincis of LEGOS," Mario and Giulio Ferrari are world- renowned experts in the field of LEGO MINDSTORMS robotics. Mario Ferrari received his first LEGO box around 1964, when he was four. LEGO was his favorite toy for many years, until he thought he was too old to play with it. In 1998, the LEGO MINDSTORMS RIS set gave him reason to again have LEGO become his main addiction. Mario believes LEGO is the closest thing to the perfect toy. He is Managing Director at EDIS, a leader in finishing and packaging solutions and promotional pack- aging. The advent of the MINDSTORMS product line represented for him the perfect opportunity to combine his interest in IT and robotics with his passion for LEGO bricks, which started during his early childhood. Mario has been a very active member of the online MINDSTORMS community from the beginning and has pushed LEGO robotics to its limits. Mario holds a bachelor's degree in Business Administration from the University of Turin and has always nourished a strong interest for physics, mathematics, and computer science. He is fluent in many programming languages, and his background includes positions as an IT manager and as a project super- visor. Mario estimates he owns more than 60,000 LEGO pieces. Mario works in Modena, Italy, where he lives with his wife, Anna, and his children, Sebastiano and Camilla. Giulio Ferrari is Sales Manager at EDIS, a company that specializes in premiums and promotional packaging. He studied economics and engi- neering at the University of Modena and Reggio Emilia. He is fond of computer programming and mathematical sciences, as well as puzzles and games in general. He has a collection of 1,500 dice of all kinds and shapes. Giulio coauthored the bestselling Building, Robots with LEGO Mindstorms (Syngress Publishing, ISBN: 1-928994-67-9) with his brother Mario and Ralph Hempel. The book has quickly become a fundamental reference and source of ideas for many LEGO robotics fans. He is also a contributor to vi Programming LEGO MINDSTOKMS with Java (Syngress Publishing, ISBN: 1-928994-55-5) and LEGO MINDSTORMS Masterpieces (Syngress Publishing, ISBN" 1-931836-75-2). Giulio has been playing with LEGO bricks since he was very young, and his passion for robotics started in 1998, with the arrival of the MINDSTO1KMS series. From that moment on, he held an important place in the creation of the Italian LEGO com- munity, ItLUG, now one of the most important LEGO user groups world- wide. He works in Modena, where he lives with his girlfriend, Claire, and his son, Zeno. Bryan Bonahoom is a LEGO MINDSTORMS enthusiast. He is a member of the Lafayette LEGO Robotics Club and one of the original team that developed the Great Ball Contraption. Bryan is also cofounder of Brickworld TM. Bryan was selected by LEGO in 2006 as a member of the MDP and later as a member of the MINDSTORMS Community Partners (MCP). Bryan was also awarded the Best Robot Design Trophy at the 2005 AFOL Tournament at LEGO headquarters as a member of Team Hassenplug. Bryan is possibly most well known for the creation of an NXT- based robot that plays tic-tac-toe with a human opponent. John Brost had a passion for LEGO and all things mechanical at an early age. However, the interest waned, and like most adult LEGO fans, John went through his "dark ages" in high school and while attending Purdue University. The release of the Star Wars LEGO sets brought a renewed interest in LEGO to John. But it was a chance encounter with an announcement of a LEGO Robotic Sumo competition being held locally that brought John back to LEGO 100 percent. It took only this event to get John hooked. Less than two weeks later, John had his first MIND- STORMS RIS kit, and he has been busily building robots and all sorts of mechanical LEGO contraptions ever since then. vii John has participated in all types of MINDSTORMS competitions, winning a few here and there. He has also been a coach for LafLRC's (Lafayette LEGO Robotics Club) FIRST LEGO League team for the past five years. In 2006, John was lucky enough to become a member of the LEGO MINDSTORMS Developer Program to test the MINDSTORMS NXT. Currently, John is a moderator on LEGO's NXTlog Web site and a coordinator for the 2007 Brickworld convention being held in Chicago. Rebeca Dunn-Krahn is a member of a working group at the University of Victoria dedicated to increasing awareness and understanding of com- puter science among children and young adults. She is currently producing a short documentary film about these outreach efforts that include flee robotics festivals using LEGO MINDSTORMS. Rebeca has also worked in quality assurance and as a Java developer. Rebeca holds a bachelor's degree in computer science and biochemistry from the University of Victoria and lives in Victoria, Canada, with her family. Rebeca would like to thank her husband, Tobias, and her children, Sophia and Sebastian, for their support. Richard Li is one of two nonadult contributors to Building Robots with LEGO MINDSTORMS NXT. He is currently a seventh-grader at Beck Academy and heads two award-winning FIRST LEGO League (FFL) teams. They have been honored with the Champion's Award on several occasions and are ranked as two of the top teams yearly. When not working with his FLL teams, he experiments with his own robots at home. He would like to thank his parents, Lin and Liang-Hong, for buying him his LEGOs and dealing with him as he stayed up late several nights to meet his deadline for this book. Richard currently resides in Simpsonville, SC. Christopher Dale Minamyer (Bachelor of Science in Mechanical Engineering, University of Arizona, 2007) began studying mechanical engi- neering during the fall of 2002 and graduated from the University of Arizona in May 2007. A lifelong LEGO fan, Chris has been building with LEGO for 20 years. viii For the past four years Chris was an instructor of LEGO Robotics at Ventana Vista Elementary School in Tucson, AZ. During this time he instructed more than 300 students in grades one through five in LEGO MINDSTORMS RCX and NXT. In addition Chris is a founding member of the Tucson LEGO Club Masters Group and the head coach. Chris has been a FIRST LEGO League coach for the past four years. In that time the teams he coached have won the Robot Performance award (2004) and the Research Quality award (2005) for the state of Arizona. In addition Chris received the Adult Coach/Mentor award (2005) and the Appreciation award (2006). Chris would like to thank his mother, Martha, and father, Rodger, for always supporting his LEGO building, and giving him his first set at the age of three. In addition he would like to thank Misha Chernobelskiy of the Tucson LEGO Club for providing an ideal environment for the instruction of LEGO enthusiasts. Finally, Chris would like to thank Caryl Jones of Ventana Vista Elementary School for her support and her continuing dedi- cation to teaching LEGO robotics. Deepak Patil developed interest in LEGO robotics when the original LEGO MINDSTORMS kit was introduced in 1998. Since then Deepak has coached FLL teams and has conducted several robotics workshops with LEGO MINDSTORMS. Deepak has a master's degree in Industrial Design from liT Bombay and has designed user interfaces for diverse products, including pro- grammable logic controllers, telephony software, and multimedia systems. Deepak has worked for Cisco and other leading technology companies, and he has led technology projects with globally interspersed teams of engineers. Deepak lives in Richmond, VA, with his wife, Priti, daughter, Vibha, and son, Uday, an avid LEGO Robotics fan. Mac Ruiz is a retired construction superintendent. His work entailed problem solving and coordinating of off-site engineers and subcontractors with the projects' realities. He also has experience in fabrication of farm equipment from his family's dealership. This included steel fabrication and mechanicals. ix