www.electronicbo.com PIC Robotics This page intentionally left blank PIC Robotics A Beginner’s Guide to Robotics Projects Using the PICmicro www.electronicbo.com John Iovine McGrawHill New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto Copyright © 2004 by The McGrawHill Companies, Inc. All rights reserved Manufactured in the United States of America. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or dis tributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher 0071394559 The material in this eBook also appears in the print version of this title: 0071373241 All trademarks are trademarks of their respective owners. Rather than put a trade mark symbol after every occurrence of a trademarked name, we use names in an edi torial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps McGrawHill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs. For more informa tion, please contact George Hoare, Special Sales, at george_hoare@mcgrawhill.com or (212) 9044069 TERMS OF USE This is a copyrighted work and The McGrawHill Companies, Inc. (“McGrawHill”) and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw Hill’s prior consent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms THE WORK IS PROVIDED “AS IS.” McGRAWHILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTIC ULAR PURPOSE. McGrawHill and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGrawHill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGrawHill has no responsi bility for the content of any information accessed through the work. Under no cir cumstances shall McGrawHill and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possi bility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise DOI: 10.1036/0071394559 For more information about this title, click here Preface xi Chapter 1 Robot Intelligence What Is a Microcontroller? Why Use a Microcontroller? Designer Computers—So Many Microcontrollers The Compiler PIC Programming Overview Software and Hardware PicBasic and PicBasic Pro Compilers EPIC Programmer Firmware Consumables 16F84 PIC Microcontroller Step 1: Writing Code (the Basic Program) Step 2: Using the Compiler Step 3: Installing the Firmware, or Programming the PIC Chip Ready, Steady, Go Parts List Chapter 2 Installing the Compiler 1 2 2 5 7 8 11 Installing the PicBasic Compiler Software Installing the PicBasic Pro Compiler 11 12 Chapter 3 Installing the EPIC Software 19 Installing the EPIC Software in Windows Installing the EPIC Software, DOS Version Supplemental—Applications Directory 19 22 22 Chapter 4 CodeDesigner 23 CodeDesigner Features Software Installation 23 25 v www.electronicbo.com Contents vi Contents Setting CodeDesigner Options First Program The EPIC Programming Board Software Parts List Chapter 5 Using DOS to Code, Compile, and Program 25 31 33 35 37 Compile Programming the PIC Chip The EPIC Programming Board Software Using EPIC DOS Version Continuing with the wink.bas Program 39 43 44 45 45 Chapter 6 Testing the PIC Microcontroller 49 The PIC Microntroller The Solderless Breadboard Three Schematics, One Circuit Wink Troubleshooting the Circuit PIC Experimenter’s Board and LCD Display PIC Experimenter’s Board Use Simple Experiment Builtin LCD Using the LCD: PicBasic and PicBasic Pro Examples Introduction to Binary and the PIC Microcontroller Using TRIS and Port Registers Accessing the Ports for Output Counting Program Counting in Binary by 1 Input The button Command A button Example peek peek and PicBasic Pro Basic Input and Output Commands Servomotors Parts List Chapter 7 Intelligence Approaches to Building Intelligence Where’s the Intelligence? Layered Behavioral Responses BehaviorBased Robotics Chapter 8 Walter’s Turtle BehaviorBased Robotics William Grey Walter—Robotics Pioneer Four Modes of Operation 49 49 50 53 54 54 56 56 58 60 63 65 68 70 71 71 72 72 74 75 76 77 78 79 83 83 85 85 86 87 87 87 88 Observed Behavior Building a Walter Tortoise Drive and Steering Motors Modifying the HS425BB Servomotor Sheet Metal Fabrication Shell Finding the Center of Gravity Attaching Bumper to Robot Base Bumper Switch Mounting the Steering Servomotor Photoresistor Trimming the Sensor Array Schematic Program Adding Sleep Mode Power Behavior Fudge Factor Light Intensity Handedness Parts List Chapter 9 Braitenberg Vehicles Neural I/O Relationships Vehicles Building Vehicles Back Wheels Front Wheels CdS Photoresistor Cells Trimming the Sensor Array PIC 16F84 Microcontroller Testing Second Braitenberg Vehicle (Avoidance Behavior) Parts List Chapter 10 Hexapod Walker Imitation of Life Six Legs—Tripod Gait ThreeServomotor Walker Robot Function Moving Forward Moving Backward Turning Left Turning Right Construction Mounting the Servomotors Leg Positioning Linkage vii 88 89 90 91 97 99 100 101 104 107 109 112 114 115 121 121 121 121 121 123 123 125 126 126 128 129 131 133 137 139 139 141 141 143 143 143 144 144 145 146 147 148 148 151 152 154 www.electronicbo.com Contents viii Contents Center (Tilt) Servomotor Sensors Electronics Microcontroller Program Parts List Chapter 11 Speech Recognition Applications Software Approach Learning to Listen SpeakerDependent and SpeakerIndependent Recognition Recognition Style Speech Recognition Circuit Circuit Construction Keypad To Train Testing Recognition Error Codes Clearing the Trained Word Memory Independent Recognition System Voice Security System Speech Interface Control Circuit How the Circuit Works PIC 16F84 Microcontroller Program Active High Output SPDT Relay Output Circuit Construction Programming the Speech Recognition Circuit: Training, Testing, and Retraining SRI02 and SRI03 Interfaces Robot Control Parts List Chapter 12 Robotic Arm Servomotor Building Blocks for Robotics Basic Servomotor Bracket Assembly Assembling MultipleServomotor Assemblies Building a FiveServomotor Robotic Arm Servomotors Servomotor Controllers Simple Servomotor Controller Four and FiveServomotor Controllers Increasing the Lifting Capacity of the Robotic Arm Adding a Robotic Arm Base Parts List Chapter 13 Bipedal Walker Robot A Question of Balance? A Little Feedback Servomotors 154 155 158 159 164 165 167 167 167 167 168 168 168 169 169 172 172 172 172 173 173 174 176 177 177 177 177 180 180 181 185 185 186 189 192 197 199 200 204 215 216 223 225 226 227 227 Contents 228 228 230 231 233 234 241 242 242 Chapter 14 Color Robotic Vision System 243 CMU Camera Serial Communication VB Application Program Interfacing the CMU Camera to a Robot PIC 16F84 Runs at 16 MHz Program 1 Program 2 Incandescent or Fluorescent Lighting Servomotors for Robot Program 3 Robot Construction Running the Program Going Further Parts List 244 245 248 250 251 251 254 254 259 261 264 266 267 267 Suppliers 269 Index 271 www.electronicbo.com Servomotor Brackets Footpads Assembly Schematic Program Subroutines M1, M2, and M3 Going Further Turning Right and Left Parts List ix ...www.electronicbo.com PIC Robotics This page intentionally left blank PIC Robotics A Beginner’s Guide to Robotics Projects Using the PICmicro www.electronicbo.com John Iovine McGrawHill... for a large variety of PIC microcontrollers EPIC Programmer The second item needed is the EPIC Programmer, also made by microEngineering Labs, Inc. The EPIC Programmer consists of software (EPIC) ... It is called PicBasic. (The PicBasic and PicBasic Pro compilers used to write PicBasic programs are products and trademarks of microEngineering Labs, Inc.) PicBasic is similar