SYNGRESS OUTLET Our outlet store at syngress.com features overstocked, out-of-print, or slightly hurt books at significant savings.

Similar documents
CELCAT Room Booker (CELCAT Live)

Extreme MINDSTORMS TM : An Advanced Guide to LEGO MINDSTORMS TM

Bringing an all-in-one solution to IoT prototype developers

Model: HDCMP31. Installation Guide

VideoEase HDMI 3x1 Switcher Kit (110V) Installation Guide

Forward Т Software. SDI option. Revision as of December 19, Installation and Setup Guide. SoftLab-NSK Ltd.

LEGO MINDSTORMS PROGRAMMING CAMP. Robotics Programming 101 Camp Curriculum

Children cannot always recognize potential hazards properly. This 5.1 system is not designed for operation in a heavy industry environment.

IoT Toolbox Mobile Application User Manual

TelePresence Cisco TelePresence Synch with Edge95MXP - Troubleshooting

ivw-fd122 Video Wall Controller MODEL: ivw-fd122 Video Wall Controller Supports 2 x 2 Video Wall Array User Manual Page i Rev. 1.

Activity #5: Reaction Timer Using the PIN and CON commands Real World Testing Chapter 3 Review Links

TEST ANY STANDARD QUICKLY AND COMPLETELY

OPERATING YOUR SYSTEM WITH MX-850

MaxView Cinema Kit Quick Install Guide

THE INSIDER SECRETS TO EBOOK SELF-PUBLISHING

Model: HD41-ARC. Installation Guide

Ableton Live 8 and Suite 8

(Skip to step 11 if you are already familiar with connecting to the Tribot)

What s New in Visual FoxPro 7.0

HDMI 1x8 Distribution Amplifier w/ CAT5e/6 outputs up to 394ft. (120 meters) USER MANUAL

ExtIO Plugin User Guide

LAZER s Sing with Stone Sour Contest

PCI MPEG Frame Grabber. Model 616. August 6, 2002

User Manual for ICP DAS WISE Monitoring IoT Kit -Microsoft Azure IoT Starter Kit-

AABB Trademark Usage Guidelines

Back Beat Bass. from Jazz to Rockabilly

Warranty and Registration. Warranty: One Year. Registration: Please register your product at Port, or. or Windows.

SM-816DT User s Manual. 2.4GHz Digital Wireless Outdoor/Indoor Camera with Night Vision and Audio

Keysight PXA Signal Analyzer

Editing Your Reading List

Buy The Complete Version of This Book at Booklocker.com:

Model: UHD41-ARC. Installation Guide

ivw-fd133 Video Wall Controller MODEL: ivw-fd133 Video Wall Controller Supports 3 x 3 and 2 x 2 Video Wall Array User Manual Page i Rev. 1.

ezcinema Plus Series

FOTS100 User Manual. BIOPAC Systems, Inc. Opsens Inc. 42 Aero Camino, Goleta, CA Tel (805) , Fax (805)

Wireless HDMI Extender. Model

Clean Code.

ForwardT Plugins. AutoDetect (SCTE-35) Automatic Ad insertion using SCTE-35 cue messages. Revision as of. October 28, User s Guide.

Radiology for Undergraduate Finals and Foundation Years

Crescent Walls User Manual

Combination Solder Pad for Single-chip LEDs with P-LCC-2 and P-LCC-4 Housings Application Note

CrystalView DVI Micro-DL Extender

Garmin GC 10 Marine Camera Instructions

HDMI to Composite Converter. User s Guide

EZ-220 Page Turner Owner s Manual

User Manual. Model 1351 DVI Repeater with HDCP

PD18-73/PD18-73LF: GHz Two-Way 0 Power Splitter/Combiner

Operation Manual 1T-TG-PCHD Analog Test Generator 1T-TG-DVI DVI Test Generator

HDSP2X4. HDMI 2 x 4 Splitter with Full HD 1080p

Transvue HDMI 4K2K Scaler

LF-IRX. 12 Month Limited Warranty LF-IRX. Remote Control Extender. Owner s manual. For customer service and technical information::

HawkEye 1500 Series Quick Start Guide V2.4.1, Nov 2008

Xpedition Layout for Package Design. Student Workbook

93.3 KIOA s Gadget Grab

The Phono Box SUMIKO Fifth Street Berkeley, CA sumikoaudio.com

OLED Lighting: A review of the patent landscape Published: 2011-Q3

Move & Store Cart CONTENTS. Assembly Instructions

Cisco TelePresence Synch

Video Processing Equipment

AT&T U-verse Enabled. How to Use the TV UI API. Publication Date: September 9, 2014

ForwardT Software. Teletext. Receiving and Rebroadcasting Video Signal with Teletext. Revision as of February 17, Quick Start.

Workshop III: Analog and Sensors

(Slide1) POD and The Long Tail

Owner s Guide. Model L32C205 TABLE OF CONTENTS

Cyan Sample. Forward T Software. Infotainment Channel Design Sample. Revision as of January 22, 2009 г. Instruction on Installation and Use

8024-DSS-02 Issue 2. DSS-8024 Dual Serial Switch USER MANUAL

MetaLib and Your Resources

This library was designed to make song writing as easy as possible! The loops are arranged into the following sections:

SDI-SDHDXPRO User Manual. Version1.2

AT&T U-verse Enabled

Model PSKIT-H540 Ultrasonic Power Supply Kit 40 khz 500 Watts

Paul M. Gauthier. Lectures on Several Complex

Animation Scripts & Tubular Neon

DA CHANNEL AES AUDIO MIXER/ ROUTER MODULE

Owner s Manual MRX-4SEN. Sensor Extender

STAR s Pick Your Purse

Netzer AqBiSS Electric Encoders

User Manual. Model 1365 Video Scaler

CR-R880-BL: Indoor/Outdoor Proximity Reader with 10cm (4in) read range

Satellite Receiver. Chapter REMOTE CONTROL USING THE MENUS USING TEXT FIELDS. About Your Satellite Receiver. What you ll find in this chapter:

Cisco StadiumVision Content Creation Design and Specification Guide for the Cisco DMP 4310G

INSTRUCTION MANUAL MUSICAL LASER LIGHT SHOW TM

HDBaseT HDMI Extender

INTERNATIONAL TELECOMMUNICATION UNION

Terms of Use and The Festival Rules

Single Station Waterproof Timer

Negotiation Exercises for Journal Article Publishing Contracts and Scholarly Monograph Publishing Contracts

RemotePoint. Navigator. User s Manual VP4150

ivw-ud322 / ivw-ud322f

Setup Guide. Introduction

HD70STP-EX. Installation Guide

RoBoard Panel RP-089 Manual V1.0 The Heart of Robotics. Jul 2010 DMP Electronics Inc

SENSORAY CO., INC. USB MPEG Capture Device. Model 2251 (Rev.A) October, 2007

LogiCORE IP Spartan-6 FPGA Triple-Rate SDI v1.0

WIRING INSTRUCTIONS CROP-LINK Drip Installation

Instruction Manual DV5000 AV/ Component Bi-Directional DV- Video to Analog Converter

Installation and Operation Manual. for the. IPC-2, Twin stereo level matching interface

Installation and Operation Manual. for the. SM-6 Programmable Stereo Mixer

4-to-1 HDMI 1.3 Switch VS410HDMIE

Transcription:

Visit us at www.syngress.com Syngress is committed to publishing high-quality books for IT Professionals and delivering those books in media and formats that fit the demands of our cus tomers. We are also committed to extending the utility of the book you purchase via additional materials available from our Web site. SOLUTIONS WEB SITE To register your book, visit www.syngress.com/solutions. Once registered, you can access our solutions@syngress.com Web pages. There you may find an assortment of valueadded 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@syngress.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 sales@syngress.com for more information.

Owen Bishop

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, Mission Critical, and The Only Way to Stop a Hacker is to Think Like One 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 BAL923457U 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 Programming Lego Mindstorms NXT Copyright 2008 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: 978-1-59749-278-2 Page Layout and Art: SPi Publishing Services Copy Editor: Judy Eby For information on rights, translations, and bulk sales, contact Matt Pedersen, Commercial Sales Director and Rights, at Syngress Publishing; email m.pedersen@elsevier.com.

Author Owen Bishop is the author of over 80 books, mostly on electronics and computing, including the best-selling Commodore 64 Games Book. His most recent publication is the Robot Builder s Cookbook (Elsevier/Newnes, 2007). Owen s talent for introducing the world s of electronics and computing has long been proven fact with his textbooks, professional introductions and hobby guides being chosen by thousands of students, lecturers and enthusiasts. With Owen s clear program descriptions you can get your robot up and running quickly, even if you are a beginner, and have fun whilst doing so. Educated in England, at Bristol University and the University of Oxford, Owen has lived and worked in several countries as a science education adviser for UNESCO and the British Council. He is at present a freelance technical writer, living in Perth, Western Australia. v

Contents Chapter 1 Robots and Programs.................................... 1 Introduction................................................... 2 What is a Program?.............................................. 4 Designing a Robot............................................... 6 Specify the Robot s Environment................................. 7 Intelligent or Smart?........................................... 8 Summary...................................................... 9 Chapter 2 About NXT-G Programs................................. 11 Introduction.................................................. 12 Creating a Program............................................. 13 First Steps.................................................... 16 Out of Memory?............................................... 18 Coming for a Spin?............................................. 19 Tying it Together............................................ 19 Chapter 3 Data................................................. 23 Introduction.................................................. 24 Sources of Data................................................ 24 Variables................................................... 26 A Variable Has a Name, a Type, and a Value....................... 27 Arithmetic Operators......................................... 28 Logical Operators............................................ 28 Flag Variables............................................... 29 Chapter 4 Loops................................................ 31 Introduction.................................................. 32 Outside Events................................................. 33 Time Limit................................................ 34 Counting the Loops.......................................... 34 Dance Some More.............................................. 34 Use Loops to Make Actions Repeat................................. 36 Another Way to Use the Loop Counter............................ 36 Logical Conclusions............................................. 37 Use a Loop (or a Wait Block) to Wait for an Event to Occur............ 38 Nested Loops............................................... 38 The Wait Block............................................. 39 vii

viii Contents Chapter 5 Switches and Other Topics.............................. 41 The Switch Block.............................................. 42 Switch Blocks Direct Execution Along Alternative Pathways............... 44 Simultaneous Processing.......................................... 44 Diagnostic Programming......................................... 46 Chapter 6 Using the Light Sensor................................. 51 Introduction.................................................. 52 Light Sensor Directed Downward.............................. 54 Lined in...................................................... 57 Line Follower................................................. 58 Edge Follower................................................. 59 Light Sensor Directed Upward.................................. 60 Housefly.................................................. 61 Light Sensor Directed Forward..................................... 63 Lightfinder1................................................... 63 LightFinder2.................................................. 64 Almost an Interrupt.......................................... 65 LightFinder3.................................................. 66 LightFinder4.................................................. 67 Summary..................................................... 70 Chapter 7 Using the Touch Sensor and the NXT Buttons............... 71 Introduction.................................................. 72 Waiting for Contact............................................. 73 Bumper................................................... 74 Waiting for Input............................................ 75 Scanning the NXT Buttons....................................... 76 Entering Numbers.............................................. 79 Chapter 8 Using the Ultrasonic Sensor............................. 81 Introduction.................................................. 82 Avoidance Routine for Alpha Rex.................................. 82 Ultrasonic Search............................................... 84 Chapter 9 Sounds Received and Emitted............................ 87 Introduction.................................................. 88 Start and Stop................................................. 88 Start, Stop, and Turn............................................. 89 One Clap or Two?.............................................. 90 Playing a Tune (with a Little Dance)................................. 92 www.syngress.com

Contents ix Choreography................................................. 93 Song Snippets............................................... 94 Dance Snippets.............................................. 94 Chapter 10 The Magnetic Compass Sensor.......................... 95 Introduction.................................................. 96 Heading in the Right Direction.................................... 97 Polygon...................................................... 98 Circle....................................................... 99 Chapter 11 More Mathematics................................... 103 Introduction................................................. 104 Floating Point Arithmetic........................................ 104 Calculating Cosines............................................ 105 Calculating Sines.............................................. 107 Square Root................................................. 108 Factorials.................................................... 110 Combinations................................................ 113 X modulo Y.................................................. 114 Modulo Counting............................................. 116 Chapter 12 Navigation......................................... 119 Introduction................................................. 120 Distance Traveled.............................................. 120 Magnetic Compass............................................. 122 Edge Follower 1............................................ 122 No-go Response to a Line....................................... 125 Steering Alpha Rex............................................ 127 Marching Orders.............................................. 131 Rex On Line................................................. 132 Rex On Edge................................................ 134 Pathfinder................................................... 137 Cosine Rule................................................. 142 Chapter 13 Games Robots Play................................... 147 Introduction................................................. 148 Maze Runner Version 1........................................ 148 Maze Runner Version 2........................................ 153 Maze Runner Version 3........................................ 154 Maze Learner................................................. 157 Scissors, Paper, Stone........................................... 159 www.syngress.com

x Contents Signalling by Semaphore......................................... 166 Magic...................................................... 167 The Program................................................. 170 Chapter 14 Databases for Robots................................. 173 Introduction................................................. 174 Lookup Table for Weekdays...................................... 174 Writable Lookup Table.......................................... 176 Another Way of Using a Lookup Table.............................. 177 Reading Data from a File Access Block.............................. 178 Acknowledgements............................................ 183 Index........................................................ 185 www.syngress.com