Winning Design! LEGO MINDSTORMS NXT
James J. Trobaugh
Winning Design! LEGO MINDSTORMS NXT
James J. Trobaugh
Winning Design! LEGO MINDSTORMS NXT Design Patterns for Fun and Competition
■ ■ ■
James J. Trobaugh
Winning Design! LEGO MINDSTORMS NXT Design Patterns Pattern s for Fun and Competition
Copyright © 2010 by James J. Trobaugh All rights reserved. No part of this work may be reproduced reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-2964-3 ISBN-13 (electronic): 978-1-4302-2965-0 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Jonathan Gennick Technical Reviewer: Joni Flynn Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Anita Castro Copy Editor: Heather Lang Compositor: MacPS, LLC Indexer: John Collin Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
[email protected], or visit www.springeronline.com. For information on translations, please e-mail
[email protected], or visit www.apress.com. Apress and friends of ED books may be purchased purchased in bulk for academic, corporate, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work.
Dedicated to Liz, Ian, and Amy for their love, patience and inspiration
Contents at a Glance
Contents ................................................................................................................v About the Author................................................................................................xiv About the Technical Reviewer.............................................................................xv Introduction .......................................................................................................xvi Part 1: Introduction ..................................................................................................1 Chapter 1: Design Considerations .........................................................................3 Chapter 2: Chassis Design...................................................................................23 Part 2: Navigation...................................................................................................45 Chapter 3: Going Straight....................................................................................47 Chapter 4: Consistent Turning.............................................................................69 Chapter 5: Line Following and Detection.............................................................83 Chapter 6: Squaring Up .....................................................................................103 Chapter 7: Collision Detection...........................................................................113 Part 3: Manipulation.............................................................................................123 Chapter 8: Passive Attachments .......................................................................125 Chapter 9: Power Attachments .........................................................................145 Chapter 10: Pneumatics....................................................................................165 Part 4: Programming............................................................................................177 Chapter 11: Master Programs...........................................................................179 Chapter 12: Program Management ...................................................................195 Chapter 13: Documentation and Presentation ..................................................205 Appendix A: Building DemoBot .........................................................................215 Appendix B: Building the Motor Matching Machine..........................................257 Index .................................................................................................................275
iv
Contents
Contents at a Glance ............................................................................................iv About the Author ................................................................................................xiv About the Technical Reviewer.............................................................................xv Introduction........................................................................................................xvi Part 1: Introduction ..................................................................................................1 Chapter 1: Design Considerations .........................................................................3
Understanding the Rules................................................................................................. 3 Knowing the FLL Robot Parts Rules ....................................................................................... ................ 3 Studying the Game Mission Rules ......................................................................................................... 5 Grouping Missions into Zones................................................................................................................ 6
Tasking the Missions ................................................................................................... ...7 Mapping Out the Field..................................................................................................... 8 Working with Constraints and Obstacles ........................................................................ 9 Field Obstacles....................................................................................................................................... 9 Environmental Obstacles ..................................................................................................................... 10
Choosing Software........................................................................................................ 11 Introducing ROBOLAB........................................................................................................................... 13 Introducing NXT-G................................................................................................................................ 14
Understanding the LEGO MINDSTORMS Hardware ....................................................... 15 NXT Intelligent Brick ............................................................................................................................ 16 Touch Sensor ................................................................................................. ...................................... 17
v
■ CONTENTS
Light Sensor......................................................................................................................................... 17 Ultrasonic Sensor................................................................................................................................. 18 Servo Motor.......................................................................................................................................... 19
Beginning the Design Process ...................................................................................... 19 Brainstorming as a Team..................................................................................................................... 19 Presenting Your Design........................................................................................................................ 20 Drawing Your Design ........................................................................................................................... 21
Resource Contention..................................................................................................... 21 Summary....................................................................................................................... 22 Chapter 2: Chassis Design...................................................................................23
Understanding Basic Design Aspects ........................................................................... 23 Size ................................................................................................................... ................................... 23 Power................................................................................................................................................... 24 Speed ...................................................................................................................... ............................. 24 Batteries............................................................................................................................................... 24
Finding the Center of Gravity ........................................................................................ 25 Gearing Up .................................................................................................................... 27 Spur Gears ........................................................................................................................................... 28 Crown Gears......................................................................................................................................... 28 Bevel Gears .................................................................................................................. ........................ 29 Double Bevel Gears.............................................................................................................................. 29 Worm Gears ......................................................................................................................................... 30 Clutch Gears......................................................................................................................................... 31 Pulleys.................................................................................................................................................. 31 Knob Wheel ................................................................................................... ....................................... 32 Gear Ratios........................................................................................................................................... 32
Getting Your Wheels...................................................................................................... 34 Circumference...................................................................................................................................... 35 Mounting.............................................................................................................................................. 35
Treads ....................................................................................................... .................... 37
vi
■ CONTENTS
Exploring the Most Common Chassis............................................................................ 37 Two-Wheeled Robots........................................................................................................................... 37 Three-Wheeled Robots......................................................................................................................... 38 Four-Wheeled Robots........................................................................................................................... 39 Six-Wheeled Robots............................................................................................................................. 40 Tracked Robots .............................................................................................. ...................................... 41
Troubleshooting ........................................................................................................... .42 Summary....................................................................................................................... 43 Part 2: Navigation...................................................................................................45 Chapter 3: Going Straight....................................................................................47
Design Influences ......................................................................................................... 47 Wheelbase ........................................................................................................................................... 47 Weight.................................................................................................................................................. 48 Wheel Circumference........................................................................................................................... 48 Wheel Support...................................................................................................................................... 49
Programming to Go Straight ......................................................................................... 51 Move Block .......................................................................................................................................... 52 Motor Block.......................................................................................................................................... 53 Reset Motor Block................................................................................................................................ 54 Custom MyMove Block......................................................................................................................... 54
Batteries........................................................................................................................ 59 Replaceable Batteries ........................................................................................... ............................... 59 Rechargeable Battery Packs................................................................................................................ 60
Helpers.......................................................................................................................... 60 Wall Following...................................................................................................................................... 60 Base Jigs.............................................................................................................................................. 64
Tips ......................................................................................................... ......................64 Motor Matching.................................................................................................................................... 64 Removing Gear Slack........................................................................................................................... 66 Troubleshooting ................................................................................................................ ................... 66
vii
■ CONTENTS
Summary....................................................................................................................... 67 Chapter 4: Consistent Turning.............................................................................69
Turning Designs ........................................................................................................ ....69 Differential Steering Systems ..................................................................................................... ......... 69 Steering Drive Systems........................................................................................................................ 71
Calculating Turns ......................................................................................................... .72 Single-Wheel Turns.............................................................................................................................. 72 Dual-Wheel Pivot.................................................................................................................................. 74
Programming ............................................................................................................... .76 Move Block .......................................................................................................................................... 76 Motor Blocks .................................................................................................................. ...................... 76 Creating a Custom MyPivot Block ......................................................................................... ............... 77 Creating a Custom MyTurn Block......................................................................................................... 80
Summary....................................................................................................................... 81 Chapter 5: Line Following and Detection.............................................................83
NXT Light Sensor .......................................................................................................... 83 Ambient Light.................................................................................................................. ..................... 84 Reflective Light ............................................................................................................... ..................... 84
Positioning the Light Sensor......................................................................................... 84 Calibrating the Light Sensor ......................................................................................... 86 Making the Calibration......................................................................................................................... 86 Viewing the Calibration ........................................................................................................................ 89 Deleting Calibration Data ....................................................................................................... .............. 90
Shielding the Light Sensor............................................................................................ 90 Line Following............................................................................................................... 92 A Dual-State Example ........................................................................................... ............................... 92 Defining More Than Two States........................................................................................................... 93 Implementing a Proportional Algorithm ................................................................................. .............. 94 Using Dual Light Sensors ......................................................................................................... ............ 96
viii
■ CONTENTS
Line Detection ........................................................................................................... ....98 Finding a Line....................................................................................................................................... 98 Detecting Color in Lines..................................................................................................................... 100
Summary..................................................................................................................... 101 Chapter 6: Squaring Up .....................................................................................103
Squaring Up with Walls............................................................................................... 103 Passive Wall Squaring........................................................................................................................ 104 Interactive Wall Squaring................................................................................................................... 108
Aligning with Lines and Edges .................................................................................... 110 Summary..................................................................................................................... 112 Chapter 7: Collision Detection...........................................................................113
Touch Sensor ......................................................................................................... .....113 Monitoring the Pressed State............................................................................................................. 113 Detecting the Released State............................................................................................................. 116 Achieving the Bumped State........................................................................................................ ...... 118
Light Sensor................................................................................................................ 119 Ultrasonic Sensor........................................................................................................ 121 Summary..................................................................................................................... 122 Part 3: Manipulation.............................................................................................123 Chapter 8: Passive Attachments .......................................................................125
Types of Passive Attachments .................................................................................... 126 Pushing ............................................................................................... ........................126 Bumper .............................................................................................................................................. 126 Plow .................................................................................................................. ................................. 127 Delivery Box ................................................................................................................. ...................... 128
Hooking....................................................................................................................... 129 Simple Hook....................................................................................................................................... 130 Fish Hook ................................................................................................................... ........................ 131 Carabineers........................................................................................................................................ 132
ix
■ CONTENTS
Fork. ................................................................................................................................................... 133
Dumping...................................................................................................................... 134 Collecting .................................................................................................................... 136 One-Way Box. ..................................................................................................................................... 136 Sweeper. ............................................................................................................................................ 138
Spring-Loaded Attachments ....................................................................................... 139 Attachment Interfaces................................................................................................. 141 Snapping Pins . ................................................................................................................................... 142 Nonsnapping Pins . ............................................................................................................................. 142 Magnets . ............................................................................................................................................ 143
Summary..................................................................................................................... 144 Chapter 9: Power Attachments .........................................................................145
Power Attachment Locations . ..................................................................................... 145 Adding an Attachment to the Front . ................................................................................................... 145 Adding an Attachment to the Center . ................................................................................................. 146 Adding an Attachment to the Rear . .................................................................................................... 148
Types of Attachments ................................................................................................. 149 Attachments That Grab . ..................................................................................................................... 149 Attachments That Lift. ........................................................................................................................ 153 Attachments That Push . ..................................................................................................................... 156
Power Interfaces. ........................................................................................................ 160 Direct Connections. ............................................................................................................................ 161 Gears. ................................................................................................................................................. 162 Driveshaft. .......................................................................................................................................... 163
Summary..................................................................................................................... 164 Chapter 10: Pneumatics....................................................................................165
Operation of Pneumatic Parts ..................................................................................... 165 Available Pneumatic Parts .......................................................................................... 166 Pumps. ............................................................................................................................................... 167
x
■ CONTENTS
Air Tank................................................................................................................ .............................. 168 Pneumatic Switches .......................................................................................................................... 169 Pneumatic Actuators.......................................................................................................................... 171 T-Joints and Air Hoses....................................................................................................................... 172 Air Gauges..................................................................................................................................... ..... 173
Integrating Pneumatics with the NXT Robot ............................................................... 173 Starting Out........................................................................................................................................ 174 Triggering the Attachment .......................................................................................................... ....... 174 Building Attachments......................................................................................................................... 174
Summary..................................................................................................................... 176 Part 4:Programming.............................................................................................177 Chapter 11: Master Programs...........................................................................179
My Blocks ................................................................................................................... 179 Defined Start and End Events ............................................................................................................ 179 Example Mission Code....................................................................................................................... 180
Simple Sequencer Program ........................................................................................ 181 The Setup........................................................................................................................................... 181 Creating My Blocks ............................................................................................. ............................... 182 Creating the Sequencer ..................................................................................................................... 182 Looking at the Code ............................................................................................. .............................. 183
Creating a Better Sequencer....................................................................................... 184 Program Navigation ........................................................................................................................... 184 Sequence Rollover ................................................................................................ ............................. 185
Creating an Advanced Sequencer............................................................................... 190 Program Display................................................................................................................................. 190 Saving State....................................................................................................................................... 192
Summary..................................................................................................................... 193
xi