Tải bản đầy đủ (.pdf) (658 trang)

lego mindstorms building robots docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (14.2 MB, 658 trang )

Mario Ferrari
Giulio Ferrari
Ralph Hempel
Technical Editor
The ULTIMATE Tool for Mindstorms Maniacs!
• Discover the Undocumented Secrets behind the Design
of the Mindstorms System
• Become Inspired by the Techniques of World-Class Mindstorms Masters
• Build a Competitive Edge for Your Next
Mindstorms Robotic Competition
LEGO
Mindstorms
Building Robots
with
®

1 YEAR UPGRADE
BUYER PROTECTION PLAN
174_lego_FC 11/11/01 3:45 PM Page 1

With more than 1,500,000 copies of our MCSE, MCSD, CompTIA, and Cisco
study guides in print, we continue to look for ways we can better serve the
information needs of our readers. One way we do that is by listening.
Readers like yourself have been telling us they want an Internet-based ser-
vice that would extend and enhance the value of our books. Based on
reader feedback and our own strategic plan, we have created a Web site
that we hope will exceed your expectations.
is an interactive treasure trove of useful infor-
mation focusing on our book topics and related technologies. The site
offers the following features:


One-year warranty against content obsolescence due to vendor
product upgrades. You can access online updates for any affected
chapters.

“Ask the Author” customer query forms that enable you to post
questions to our authors and editors.

Exclusive monthly mailings in which our experts provide answers to
reader queries and clear explanations of complex material.

Regularly updated links to sites specially selected by our editors for
readers desiring additional reliable information on key topics.
Best of all, the book you’re now holding is your key to this amazing site.
Just go to www.syngress.com/solutions, and keep this book handy when
you register to verify your purchase.
Thank you for giving us the opportunity to serve your needs. And be sure
to let us know if there’s anything else we can do to help you get the
maximum value from your investment. We’re listening.
www.syngress.com/solutions
174_LEGO_FM 11/1/01 9:40 AM Page i
174_LEGO_FM 11/1/01 9:40 AM Page ii
Mario Ferrari
Giulio Ferrari
Ralph Hempel
Technical Editor
The ULTIMATE Tool for MINDSTORMS Maniacs!
Building Robots
with
LEGO
MINDSTORMS

®
174_LEGO_FM 11/1/01 9:40 AM Page iii
Syngress Publishing, 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®, and “Career Advancement Through Skill Enhancement®,” are registered
trademarks of Syngress Media, Inc. “Ask the Author UPDATE™,” “Mission Critical™,”“Hack Proofing™,”
and “The Only Way to Stop a Hacker is to Think Like One™” are trademarks of Syngress Publishing, Inc.
Brands and product names mentioned in this book are trademarks or service marks of their respective
companies.
KEY SERIAL NUMBER
001 B8EL495GK4
002 2NVA4UHBBJ
003 CJGE946M43
004 3BVNAM7L4T
005 D384NSARSD
006 4ZMWAQEKFK
007 FMAPPW8GN9
008 XSLEKRK2FB
009 QMV9DSRUJT
010 5KNAPFRPAR
PUBLISHED BY

Syngress Publishing, Inc.
800 Hingham Street
Rockland, MA 02370
Building Robots with LEGO MINDSTORMS
Copyright © 2002 by Syngress Publishing, 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: 1-928994-67-9
Technical Editor: Ralph Hempel Cover Designer: Michael Kavish
Co-Publisher: Richard Kristof Page Layout and Art by: Shannon Tozier
Acquisitions Editor: Catherine B. Nolan Copy Editor: Michael McGee
Developmental Editor: Kate Glennon Indexer: Robert Saigh
Freelance Editorial Manager: Maribeth Corona-Evans
Distributed by Publishers Group West in the United States and Jaguar Book Group in Canada.
174_LEGO_FM 11/1/01 9:40 AM Page iv
v
Letter from the Publisher
v
When I co-founded Syngress in 1997 with Amorette Pedersen, we decided to forego
the opportunity to include the ubiquitous “Letter from the Publisher” in the front of
Syngress books. Our books are of the highest quality, written by content experts, and
they’ve spoken quite well for themselves without any help from us.
However, the publication of Building Robots with LEGO MINDSTORMS entitles
me to a one-time exemption from our rule. I am lucky enough to be the father of
nine-year-old Sam Williams, who has taught me (among many important things) the
joy of building with LEGO. Since helping Sam put together his first bricks at two

years old to programming our latest MINDSTORMS robot (the optimistically
named “Chore-Doer 3000”), I have derived hundreds of hours of pleasure creating
projects with Sam. Perhaps the most ingenious thing about LEGO products, particu-
larly the MINDSTORMS, is that the same product can be as challenging and enjoy-
able to a 43 year old as it is to a nine year old.
When presented with the chance to publish Mario and Giulio Ferrari’s book, I
jumped at the opportunity.As I read the manuscript, I could sense the authors had
the same passion for creating with LEGO MINDSTORMS that Sam and I have. I
knew immediately that there was a market of at least two people for the book!
I had the opportunity to meet Mario Ferrari at the Frankfurt Book Fair just
weeks prior to this book’s publication. I am American and Mario is Italian, but the
language we spoke was that of two parents who have discovered a common passion
to share with our nine and ten year old sons.
I hope you enjoy reading this book as much as we have enjoyed publishing it.
—Chris Williams
President, Syngress Publishing
FPO
174_LEGO_FM 11/1/01 9:40 AM Page v
Letters from the Authors
October 1998. It was a warm and sunny October and I remember it as if it was just
yesterday. Giovanni, a colleague of mine, returns home to Italy from his honeymoon
in New York. He carries in the office an enormous blue box whose cover reads
“LEGO MINDSTORMS Robotics Invention System.”When Giovanni opens the
box and shows me the contents, I already know I must have one.
Let me go back to the late 70s. I was a high school student and had left my many
years of LEGO play behind me. I was enthusiastically entering the rising personal
computing era. Many of you are probably simply too young to remember that
period, but “using” a computer mainly meant programming it.The computers of that
time had few resources and rather primitive user interfaces; they were essentially mass
storage devices, or something like a large unreliable cassette recorder.We program-

mers had to count and save every single byte, and even the most trivial tasks were
very challenging. But at the same time, of course, it was great fun!
I developed a very strong interest in computer programming, and in Artificial
Intelligence in particular. Machines and mechanical devices had always fascinated me,
and it came quite naturally to me to turn to robotics as an expansion of this interest.
There were some relatively cheap and compact computing devices that could provide
a brain for my creatures, but unfortunately I discovered very soon all the technical
problems involved in building the hardware of even a very simple robot.Where could
I find motors? Which were the right ones? Where could I learn how to control
them? What kind of gearing did I need? Imagine spending months folding aluminum
plates, mounting bearings, assembling electronic circuits, connecting wires… and
assuming you’re able to do all those things, what do you get? A simple tin box that
can run across the room and change direction when it hits an obstacle.The effort was
definitely far greater than the results.Another problem was that constructing a new
project meant starting again from scratch, with new materials. I wasn’t patient
enough, so I decided that a hobby in robotics was not for me.
The dream of robotics remained a dream. Until Giovanni opened that box.As
soon as I got my hands on my first LEGO MINDSTORMS Robotics Invention
System (RIS) set, it proved to be the fast and flexible robotics system that I was
looking for. I found that the microcomputer, called the RCX, was very simple to use
but powerful enough to let me drive complex devices. I became more and more
vi
174_LEGO_FM 11/1/01 9:40 AM Page vi
vii
intrigued by this toy, and through the Internet I soon discovered that I was not alone.
It seemed an entire world of potential robotics fans had just been waiting for this
product, and the LEGO company itself sold much more of them than expected.
From that October on, many things happened: I discovered LUGNET, the fan-
tastic LEGO Users Group Network, the best resource ever for LEGO fans of any
kind. I created a small Web site where I published pictures and information about

my robotic creatures.Through these channels every day I got in touch with new
people, and with some of them friendships have sprung up that go beyond our
common interests in LEGO robotics.This is really the most special and valuable
thing MINDSTORMS have given to me: Good friends all over the world.
—Mario Ferrari
October 1999.Another warm and sunny October, but on one particular day the
Media Lab at the Massachusetts Institute of Technology (MIT) in Cambridge, MA
has a different look. One large room at the facility is filled with exhibition tables
with piles of colorful LEGO pieces and strange constructions on them and, there are
hundreds of adults and children, LEGO bricks in hand, showing off their robotic cre-
ations and discussing the characteristics of their favorites.This is the world’s biggest
gathering of LEGO MINDSTORMS fans—the Mindfest!
When and how did all this start? It seems only yesterday to me, but a year had
passed since I discovered MINDSTORMS for the first time. My brother Mario
called me on the phone one evening, knowing I was about to leave on a short trip to
New York, and asked me to bring him home a new product from LEGO, a sort of a
programmable brick that could be controlled via a standard computer. I have to say
that I was very curious, but nothing more: I thought it might be a great new toy to
play around with, but I didn’t completely understand its possibilities.When I saw the
Robotics Invention System (RIS) in the toy store, though, I immediately realized
how great it could be, and that I must have one, too. My own addiction to the
LEGO MINDSTORMS began in that moment.
Like nearly everyone under the age of 40, I’d built projects from the many
LEGO theme kits in my childhood. I had the advantage of using the large quantity
of bricks that my older brothers and sisters had accumulated during the years, plus
some new pieces and sets of the 80s. Castles, pirates, trains… hours and hours of pure
174_LEGO_FM 11/1/01 9:40 AM Page vii
viii
fun, creating a large number of any kind of building and adventures.When I was a
little older, I discovered the TECHNIC series, a wonderful world of machines, gears,

mechanical tools, and vehicles, with endless construction possibilities.Then, like many
other people, I abandoned LEGO as a young adult, and it remained out of my life—
until I bought that big blue box in New York that day.
Why do I like LEGO MINDSTORMS so much? For me, it is mainly because it
requires different skills and combines different disciplines: computer programming,
robotics, and hands-on construction.You have to combine theory and practice, and to
coordinate the design, construction, software, and testing processes.You can exercise
your creativity and your imagination, and you have a great tool for doing this—a
tool that is at the same time easy to use and very powerful, and most important, that
doesn’t limit your ideas.
And there’s even more to the rewards of MINDSTORMS than that. Let’s go
back to Mindfest for a moment.Why would such an extraordinary group of people
of different ages, cultures, and nationalities travel from all over the world to spend an
entire weekend playing with LEGO? What exactly do they have in common? Why
do some of the most famous Artificial Intelligence experts seriously discuss every fea-
ture of this product? There must be something really special about this “toy.”
Joining an international community is one of the best things about playing with
LEGO. It is not only a toy, but also a way of thinking and living. Just play with the
MINDSTORMS for a while—you’ll see for yourself!
—Giulio Ferrari
174_LEGO_FM 11/1/01 9:40 AM Page viii
ix
Author Acknowledgements
We would first like to thank Brian Bagnall for suggesting our names to Syngress
Publishing when he heard Syngress was looking for an author to write a book
focused on ideas and techniques for building MINDSTORMS robots.We are very
grateful to Syngress Publishing for having turned this suggestion into a real opportu-
nity, and for having allowed us the great freedom of deciding the shape and content
of the book.
Additional appreciation goes to Jonathan Knudsen, who encouraged us in

embarking upon the adventure of writing a book, and who helped us in under-
standing the world of technical publishing.Another friend, Guido Truffelli, patiently
read every page of the manuscript. Many thanks, Guido—your comments and sug-
gestions were very valuable in making the book more complete and more useful.
When Ralph Hempel accepted the offer to perform the technical edit of the
book, we were really excited. Ralph’s contributions to MINDSTORMS robotics are
impressive, and range from mechanical solutions to extreme programming. His
involvement proved to be even more significant that we had even imagined.
This was our first authoring experience, and all the Syngress staff has been
incredibly patient with us and very supportive. A very special thank you goes to Kate
Glennon, our Developmental Editor, for having taught us how to transform a collec-
tion of concepts and ideas into a book. Mario wants to also thank his employer,
EDIS, which granted him the time to focus more attention on the book.
This book would have not been written without the contributions of the entire
LUGNET MINDSTORMS Robotics community. Its members are incredibly cre-
ative, competent, helpful, and friendly, and they are always willing to share ideas and
solutions with other people.We have attempted to give proper credit to all the
people whose ideas we mentioned in the book, and we apologize in advance for
those people who have been unintentionally left out.
Last but not least, we’d like to express enormous gratitude to our families, who
encouraged and supported us through every moment of these intense months of
writing.
174_LEGO_FM 11/1/01 9:40 AM Page ix
x
Syngress Acknowledgements
We would like to acknowledge the following people for their kindness and support
in making this book possible.
Richard Kristof and Duncan Anderson of Global Knowledge, for their generous
access to the IT industry’s best courses, instructors, and training facilities.
Karen Cross, Lance Tilford, Meaghan Cunningham, Kim Wylie, Harry Kirchner,

Kevin Votel, Kent Anderson, and Frida Yara of Publishers Group West for sharing
their incredible marketing experience and expertise.
Mary Ging, Caroline Hird, Simon Beale, Caroline Wheeler,Victoria Fuller, Jonathan
Bunkell, and Klaus Beran of Harcourt International for making certain that our
vision remains worldwide in scope.
Anneke Baeten and Annabel Dent of Harcourt Australia for all their help.
David Buckland,Wendi Wong, Daniel Loh, Marie Chieng, Lucy Chong, Leslie Lim,
Audrey Gan, and Joseph Chan of Transquest Publishers for the enthusiasm with
which they receive our books.
Kwon Sung June at Acorn Publishing for his support.
Ethan Atkin at Cranbury International for his help in expanding the Syngress
program.
A special thanks to Sam Williams, who comes to the office every week with a
backpack full of LEGOs.Watching the look on his face when he opens a new kit is a
joyous event.
174_LEGO_FM 11/1/01 9:40 AM Page x
xi
Contributors
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 4.
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 and estimates he owns over
60,000 LEGO pieces.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. Mario has been a very
active member of the online MINDSTORMS community from the
beginning and has pushed LEGO robotics to its limits. Mario is

Managing Director at EDIS, a leader in finishing and packaging solutions
and promotional packaging. He 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 posi-
tions as an IT manager and as a project supervisor. Mario works in
Modena, Italy, where he lives with his wife Anna and his children
Sebastiano and Camilla.
Giulio Ferrari is a student in Economics at the University of Modena
and Reggio Emilia, where he also studied Engineering. He is fond of
computers and has developed utilities, entertainment software, and Web
applications for several companies. Giulio discovered robotics in 1998,
with the arrival of MINDSTORMS, and held an important place in the
creation of the Italian LEGO community. He shares a love for LEGO
bricks with his oldest brother Mario, and a strong curiosity for the phys-
ical and mathematical sciences. Giulio also has a collection of 1200 dice,
including odd-faced dice and game dice. He studies, works, and lives in
Modena, Italy.
174_LEGO_FM 11/1/01 9:40 AM Page xi
xii
Technical Editor
Ralph Hempel (BASc.EE, P.Eng) is an Independent Embedded Systems
Consultant. He provides systems design services, training, and program-
ming to clients across North America. His specialty is in deeply
embedded microcontroller applications, which include alarm systems,
automotive controls, and the LEGO RCX system. Ralph provides
training and mentoring for software development teams that are new to
embedded systems and need an in-depth review of the unique require-
ments of this type of programming. Ralph holds a degree in Electrical
Engineering from the University of Waterloo and is a member of the

Ontario Society of Professional Engineers. He lives in Owen Sound,
Ontario with his family, Christine, Owen, Eric, and Graham.
174_LEGO_FM 11/1/01 9:40 AM Page xii
Contents
xiii
Foreword xxv
Preface xxvii
Part I Tools 1
Chapter 1 Understanding LEGO
®
Geometry 3
Introduction 4
Expressing Sizes and Units 4
Squaring the LEGO World:Vertical Bracing 6
Tilting the LEGO World: Diagonal Bracing 10
Expressing Horizontal Sizes and Units 12
Bracing with Hinges 14
Summary 15
Chapter 2 Playing with Gears 17
Introduction 18
Counting Teeth 18
Gearing Up and Down 19
Riding That Train:The Geartrain 21
Worming Your Way:The Worm Gear 23
Limiting Strength with the Clutch Gear 24
Placing and Fitting Gears 26
Using Pulleys, Belts, and Chains 31
Pulleys and Belts 32
Chains 35
Making a Difference:The Differential 36

Summary 39
Learn about Lego Gears
174_LEGO_TOC 10/30/01 2:54 PM Page xiii
xiv Contents
Chapter 3 Controlling Motors 41
Introduction 42
Pacing,Trotting, and Galloping 43
Mounting Motors 46
Wiring Motors 49
Controlling Power 52
Braking the Motor 53
Coupling Motors 55
Summary 56
Chapter 4 Reading Sensors 57
Introduction 58
Touch Sensor 58
Light Sensor 64
Measuring Reflected Light 66
Line Following 67
Proximity Detection 70
Rotation Sensor 71
Temperature Sensor 74
Sensor Tips and Tricks 75
Emulating a Touch Sensor 75
Emulating a Rotation Sensor 75
Connecting Multiple Sensors to the
Same Port 78
Other Sensors 80
Summary 81
Chapter 5 Building Strategies 83

Introduction 84
Locking Layers 84
Maximizing Modularity 87
Loading the Structure 88
Putting It All Together: Chassis, Modularity,
and Load 90
Summary 94
Explore LEGO Sensors
LEGO sensors come in two
families: active and
passive sensors. Passive
simply means they don't
require any electric supply
to work. The touch and
temperature sensors
belong to the passive
class, while the light and
rotation sensors are
members of the active
class.
174_LEGO_TOC 10/30/01 2:54 PM Page xiv
Contents xv
Chapter 6 Programming the RCX 97
Introduction 98
What Is the RCX? 98
A Small Family of Programmable Bricks 100
Using LEGO RCX Code 101
Using the NQC Language 102
Using Other Programming Languages 103
Using legOS 104

Using pbForth 104
Using leJOS 105
Using Other Programming Tools and
Environments 105
Divide and Conquer: Keeping Your
Code Organized 106
Running Independent Tasks 113
Summary 114
Chapter 7 Playing Sounds and Music 117
Introduction 118
Communicating through Tones 118
Playing Music 119
Converting MIDI files 122
Converting WAV Files 124
Summary 124
Chapter 8 Becoming Mobile 127
Introduction 128
Building a Simple Differential Drive 128
Keeping a Straight Path 130
Using Sensors to Go Straight 130
Using Gears to Go Straight 131
Using Casters to Go Straight 134
Building a Dual Differential Drive 136
Building a Skid-Steer Drive 138
Building a Steering Drive 140
Building a Tricycle Drive 144
Building a Synchro Drive 146
Understand the
Benefits of Designing
Modular Code


Readability

Reusability

Testability
174_LEGO_TOC 10/30/01 2:54 PM Page xv
xvi Contents
Other Configurations 150
Summary 151
Chapter 9 Expanding Your Options
with Kits and Creative Solutions 153
Introduction 154
Acquiring More Parts 154
Introducing Some Specialized Components 155
Buying Additional Parts 161
Creating Custom Components 163
Building Custom Sensors 164
Solving Port Limitations 170
Creative Solutions When
More RCX Ports Are Needed 172
Summary 177
Chapter 10 Getting Pumped: Pneumatics 179
Introduction 180
Recalling Some Basic Science 180
Pumps and Cylinders 181
Controlling the Airflow 187
Building Air Compressors 190
Building a Pneumatic Engine 194
Summary 198

Chapter 11 Finding and Grabbing Objects 199
Introduction 200
Operating Hands and Grabbers 200
Transferring Motion Using Tubing 203
Understanding Degrees of Freedom 205
Finding Objects 209
Summary 212
Chapter 12 Doing the Math 213
Introduction 214
Multiplying and Dividing 215
Averaging Data 218
Simple Averages 218
Weighted Averages 223
Create Custom
Components
Explore extra parts,
custom sensors, and tricks
for using the same motor
for more than one task:

Extra parts come from
either sets or service
packs.

Custom sensors are a
new frontier, and
reveal a whole new
world of possibilities.

Mechanical tricks

enable you to use the
same motor to power
multiple mechanisms.
174_LEGO_TOC 10/30/01 2:54 PM Page xvi
Contents xvii
Using Interpolation 226
Understanding Hysteresis 229
Summary 232
Chapter 13 Knowing Where You Are 233
Introduction 234
Choosing Internal or External Guidance 234
Looking for Landmarks:Absolute Positioning 236
Following the Beam 239
Measuring Movement: Relative Positioning 243
Summary 246
Part II Projects 247
Chapter 14 Classic Projects 249
Introduction 250
Exploring Your Room 250
Detecting Edges 253
Variations on Obstacle Detection 255
Following a Line 256
Further Optimization of Line Following 264
Modeling Cars 265
Front-Wheel and Four-Wheel Drives 270
Switching Gears 274
Using the Gear Switch 276
Summary 277
Chapter 15 Building Robots That Walk 279
Introduction 280

The Theory behind Walking 280
Building Legs 287
Building a Four-Legged Robot 289
Building a Six-Legged Steering Robot 293
Designing Bipeds 299
Interlacing Legs 299
COG Shifting 302
Ankle Bending 306
Making Bipeds Turn 309
Summary 310
Use Ankle Bending
Techniques
174_LEGO_TOC 10/30/01 2:54 PM Page xvii
xviii Contents
Chapter 16 Unconventional Vehicles 311
Introduction 312
Creating Your Own SHRIMP 312
Building a SHRIMP 320
Creating a Skier 321
Creating Other Vehicles 328
Elevator 328
Train 328
Cable Railway or Gondola 329
Boat 329
Sailing Tricycle 330
Summary 331
Chapter 17 Robotic Animals 333
Introduction 334
Creating a Mouse 334
Improvements Upon the Mouse’s

Construction 338
Creating a Turtle 339
Improvements Upon the Turtle’s
Construction 344
Creating Other Animals 345
Summary 346
Chapter 18 Replicating Renowned Droids 349
Introduction 350
Building an R2-D2-Style Droid 350
Programming the Droid 356
Variations on the Construction 359
Building a Johnny Five-Style Droid 361
Variations on the Construction 366
Summary 368
Chapter 19 Solving a Maze 371
Introduction 372
Finding the Way Out 373
Using the Left Side—Right Side Strategy 374
Applying Other Strategies 376
Use Angle Connectors
There are currently six
types of angle connectors
in the LEGO line,
numbered 1 to 6. In case
you’re wondering how the
numbers relate to angles,
here are the correspond-
ences: 1 = 0°, 2 = 180°,
3 = 157.5°, 4 = 135°,
5 = 112.5°, 6 = 90°. They

go by increments of 22.5°,
a quarter of a right angle.
174_LEGO_TOC 10/30/01 2:54 PM Page xviii
Contents xix
Building a Maze Runner 377
Constructing the Maze Runner 377
Programming the Runner 380
Creating the Maze 381
Variations on the Maze Runner 381
Building a Maze Solver 382
Constructing the Maze Solver 383
Programming the Solver 387
Summary 389
Chapter 20 Board Games 391
Introduction 392
Playing Tic-Tac-Toe 392
Building the Hardware 393
Writing the Program 394
Improving Your Game 396
Playing Chess 396
Building a Visual Interface 397
Building a Mechanical Interface 400
Connecting and Programming
Broad Blue 406
Variations on the Construction 408
Playing Other Board Games 409
Summary 410
Chapter 21 Playing Musical Instruments 411
Introduction 412
Creating a Drummer 412

Building the Drummer 413
Programming the Drummer 416
Variations 417
Creating a Pianist 417
Building the Pianist 417
Programming the Pianist 422
Changes and Improvements 423
Other Suggestions 424
Summary 424
Build a Pianist
This robot requires a lot of
extra parts, mainly beams
and plates used to make
the structure solid enough
to withstand the forces
involved in the
performance.
174_LEGO_TOC 10/30/01 2:54 PM Page xix
xx Contents
Chapter 22 Electronic Games 425
Introduction 426
Creating a Pinball Machine 426
Building the Pinball Machine 426
Programming the Pinball Machine 431
Improvements on the Construction 432
Creating a Simon-Says Game 432
Building a Simon-Says Game 432
Programming the Simon-Says Game 434
Variations 438
Other Electronic Game Suggestions 438

Summary 439
Chapter 23 Drawing and Writing 441
Introduction 442
Creating a Logo Turtle 442
Building the Turtle 443
Programming the Turtle 448
Choosing the Proper Language 453
Variations 454
Tape Writer 455
Building the Writer 455
Programming the Writer 462
What to Write 462
Variations 463
Further Suggestions 464
Copying 464
Emulating Handwriting 464
Learning by Example 465
Summary 465
Chapter 24 Simulating Flight 467
Introduction 468
Introducing the Forces Involved in Flight 468
Designing the Simulator Project 471
Building the Hardware 473
Programming the Simulator 480
Understand Infrared
Communication
Infrared (IR) light is of the
same nature as visible
light, but its frequency is
below that perceivable by

the human eye. Provided
the intensity is high
enough, we usually feel IR
radiation as heat.
174_LEGO_TOC 10/30/01 2:54 PM Page xx
Contents xxi
Operating the Simulator 488
Downsizing the Project 489
Upsizing the Project 491
Summary 492
Chapter 25 Constructing Useful Stuff 493
Introduction 494
Building a Floor Sweeper 494
Constructing the Sweeper 494
Programming the Sweeper 497
Improvements on the Floor Sweeper 497
Building a Milk Guard 498
Making the Milk Guard 499
Programming and Using the Milk Guard 501
Improvements on the Milk Guard 502
Building a Plant Sprinkler 502
Making the Sprinkler 503
Programming and Using the Sprinkler 504
Improvements on the Plant Sprinkler 505
Designing Other Useful Robots 508
Summary 509
Part III Contests 511
Chapter 26 Racing Against Time 513
Introduction 514
Hosting and Participating in Contests 514

Optimizing Speed 516
Drag Racing 516
Combining Speed with Precision 518
Line Following 519
Wall Following 520
Other Races 522
Summary 523
Chapter 27 Hand-to-Hand Combat 525
Introduction 526
Building a Robotic Sumo 526
Setting the Rules 527
Design Other Useful
Robots

Alarm Clock

Baby Entertainer

Pet Feeder

Dog Trainer
174_LEGO_TOC 10/30/01 2:54 PM Page xxi
xxii Contents
Maximizing Strength and Traction 528
Attack Strategies 530
Finding the Enemy 530
Using Speed 532
Using a Transmission 533
Other Sumo Tricks 533
Getting Defensive 534

Testing Your Sumo 535
Summary 536
Chapter 28 Searching for Precision 537
Introduction 538
Precise Positioning 538
Finding and Collecting Things 540
Maxwell’s Demons 540
Stealing the Cube 541
Variations on Collecting 543
Playing Soccer 543
Summary 545
Chapter 28 Searching for Precision 537
Introduction 538
Precise Positioning 538
Finding and Collecting Things 540
Maxwell’s Demons 540
Stealing the Cube 541
Variations on Collecting 543
Playing Soccer 543
Summary 545
Appendix A Resources 547
Introduction 548
Bibliography 548
General Interest Sites 549
Chapter 1 Understanding LEGO
Geometry 551
Chapter 2 Playing with Gears 551
Chapter 3 Controlling Motors 551
Chapter 4 Reading Sensors 552
Find Useful Lego Sites


www.brickshelf.com


.media.mit.edu/people/
fredm/mindstorms/
index.html

www.crynwr.com/
lego-robotics/

www.bvandam.net
174_LEGO_TOC 10/30/01 2:54 PM Page xxii
Contents xxiii
Chapter 5 Building Strategies 552
Chapter 6 Programming the RCX 553
Chapter 7 Playing Sounds and Music 556
Chapter 8 Becoming Mobile 556
Chapter 9 Expanding Your Options with
Kits and Creative Solutions 557
Chapter 10 Getting Pumped: Pneumatics 559
Chapter 11 Finding and Grabbing
Objects 559
Chapter 12 Doing the Math 560
Chapter 13 Knowing Where You Are 560
Chapter 14 Classic Projects 561
Chapter 15 Building Robots That Walk 562
Chapter 16 Unconventional Vehicles 562
Chapter 17 Robotic Animals 563
Chapter 18 Replicating Renowned

Droids 563
Chapter 19 Solving a Maze 564
Chapter 20 Board Games 564
Chapter 21 Playing Musical Instruments 565
Chapter 22 Electronic Games 565
Chapter 23 Drawing and Writing 565
Chapter 24 Simulating Flight 566
Chapter 25 Building Useful Stuff 566
Chapter 26 Racing Against Time 566
Chapter 27 Hand-to-Hand Combat 567
Chapter 28 Searching for Precision 567
Appendix B Matching Distances 569
Appendix C Note Frequencies 575
Appendix D Math Cheat Sheet 577
Sensors 578
Averages 578
Interpolation 578
Gears,Wheels, and Navigation 579
Index 581
174_LEGO_TOC 10/30/01 2:54 PM Page xxiii
174_LEGO_TOC 10/30/01 2:54 PM Page xxiv

×