ebook img

The Definitive Guide to Building Java Robots PDF

441 Pages·2006·17.626 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview The Definitive Guide to Building Java Robots

Preston_5564Front.fm Page i Friday, October 7, 2005 5:14 AM The Definitive Guide to Building Java Robots ■ ■ ■ Scott Preston Preston_5564Front.fm Page ii Friday, October 7, 2005 5:14 AM The Definitive Guide to Building Java Robots Copyright © 2006 by Scott Preston All rights reserved. No part of this work may be 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: 1-59059-556-4 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Coke®, Pepsi®, and 7 UP® are registered trademarks of The Coca Cola Company, PepsiCo Beverages of North America Inc., and Cadbury Beverages North America, respectively. Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Steve Anglin Technical Reviewer: Simon Ritter Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason Gilmore, Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser Project Manager: Sofia Marchant Copy Edit Manager: Nicole LeClerc Copy Editor: Mike McGee Assistant Production Director: Kari Brooks-Copony Production Editor: Katie Stence Compositor: Susan Glinert Proofreader: April Eddy Indexer: Carol Burbo Artist: April Milne Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com. 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 loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Source Code section. Preston_5564Front.fm Page iii Friday, October 7, 2005 5:14 AM Contents at a Glance About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .ix About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xi Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv ■ CHAPTER 1 A Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 ■ CHAPTER 2 Serial Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 ■ CHAPTER 3 Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 ■ CHAPTER 4 Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 ■ CHAPTER 5 Speech . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 ■ CHAPTER 6 Vision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 ■ CHAPTER 7 Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 ■ CHAPTER 8 Other Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 ■ CHAPTER 9 Sample Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 ■ APPENDIX A The Definitive Guide API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 ■ APPENDIX B Microcontroller Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 ■ APPENDIX C Robot Parts Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 ■ INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 iii Preston_5564Front.fm Page iv Friday, October 7, 2005 5:14 AM Preston_5564Front.fm Page v Friday, October 7, 2005 5:14 AM CCoonntteennttss About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .ix About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xi Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv ■ CHAPTER 1 A Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.0 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 Organizing Your Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.2 Java Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.3 Organizing Your Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 ■ CHAPTER 2 Serial Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.0 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.1 A Simple Serial Port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 2.2 Concurrent Serial Port Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.3 Creating a Web Serial Port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.4 Serial Communications with a Microcontroller . . . . . . . . . . . . . . . . . . 37 2.5 Modeling a Microcontroller with Java . . . . . . . . . . . . . . . . . . . . . . . . 40 2.6 Bluetooth Serial Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.7 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 ■ CHAPTER 3 Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 3.0 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 3.1 Servo Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 3.2 Wheeled Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 3.3 Pan and Tilt Mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 3.4 Advanced Servo Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 3.5 The Robot Arm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 3.6 Legged Robots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 3.7 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 v Preston_5564Front.fm Page vi Friday, October 7, 2005 5:14 AM vi ■ CONTENTS ■ CHAPTER 4 Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 4.0 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 4.1 Orientation Sensors (Compass) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 4.2 Switch Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 4.3 Distance Sensors (IR and Sonar) . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 4.4 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 ■ CHAPTER 5 Speech . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 5.0 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 5.1 Speech Synthesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 5.2 Speech Recognition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 5.3 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 ■ CHAPTER 6 Vision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 6.0 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 6.1 Image Capture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 6.2 Basic Image Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 6.3 Color Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 6.4 Advanced Image Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 6.5 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 ■ CHAPTER 7 Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 7.0 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 7.1 Navigation Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 7.2 Localization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 7.3 Obstacle Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 7.4 Indoor Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 7.5 Outdoor Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 7.6 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 ■ CHAPTER 8 Other Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 8.0 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 8.1 Running Your Java Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 8.2 Scheduling Your Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 8.3 Ant Building and More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 8.4 Database Access with JDBC and MySQL . . . . . . . . . . . . . . . . . . . . 299 8.5 Using and Installing Tomcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 Preston_5564Front.fm Page vii Friday, October 7, 2005 5:14 AM ■ CONTENTS vii 8.6 Java Scripting Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 8.7 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 ■ CHAPTER 9 Sample Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 9.0 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 9.1 Miscellaneous Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 9.2 Webcam Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 9.3 Remote Control Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 9.4 Diagnostic Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362 9.5 Navigation Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 9.6 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382 ■ APPENDIX A The Definitive Guide API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 ■ APPENDIX B Microcontroller Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 ■ APPENDIX C Robot Parts Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 ■ INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 97022d2480fe4a63cfdfa123a6e70098 Preston_5564Front.fm Page viii Friday, October 7, 2005 5:14 AM Preston_5564Front.fm Page ix Friday, October 7, 2005 5:14 AM About the Author ■ SCOTT PRESTON works as a Java architect in Columbus, Ohio, where he resides with his wife, Emily, and dog, Castle. Scott has over 20 years of soft- ware and electrical experience, including positions with the U.S. Navy, Bank One, CompuServe, UUNET, and Covansys Inc., in addition to running his own robotics company, Preston Research LLC. Scott also gives lectures about robotics at COSI (Center of Science and Industry) and manufactures small Java-enabled robots called CubeBots®. Scott is a member of the Java Community Process and an alumnus of The Ohio State University. ix

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.