PIC Robotics A Beginner’s Guide to Robotics Projects Using the PICmicro ============== Contents Preface xi Chapter 1. Robot Intelligence 1 What Is a Microcontroller? 1 Why Use a Microcontroller? 1 Designer Computers—So Many Microcontrollers 2 The Compiler 2 PIC Programming Overview 2 Software and Hardware 2 PicBasic and PicBasic Pro Compilers 3 EPIC Programmer 4 Firmware 5 Consumables 5 16F84 PIC Microcontroller 5 Step 1: Writing Code (the Basic Program) 6 Step 2: Using the Compiler 7 Step 3: Installing the Firmware, or Programming the PIC Chip 7 Ready, Steady, Go 8 Parts List 8 Chapter 2. Installing the Compiler 11 Installing the PicBasic Compiler Software 11 Installing the PicBasic Pro Compiler 12 Chapter 3. Installing the EPIC Software 19 Installing the EPIC Software in Windows 19 Installing the EPIC Software, DOS Version 22 Supplemental—Applications Directory 22 Chapter 4. CodeDesigner 23 CodeDesigner Features 23 Software Installation 25 v vi Contents Setting CodeDesigner Options 25 First Program 31 The EPIC Programming Board Software 33 Parts List 35 Chapter 5. Using DOS to Code, Compile, and Program 37 Compile 39 Programming the PIC Chip 43 The EPIC Programming Board Software 44 Using EPIC DOS Version 45 Continuing with the wink.bas Program 45 Chapter 6. Testing the PIC Microcontroller 49 The PIC Microntroller 49 The Solderless Breadboard 49 Three Schematics, One Circuit 50 Wink 53 Troubleshooting the Circuit 54 PIC Experimenter’s Board and LCD Display 54 PIC Experimenter’s Board 56 Use 56 Simple Experiment 58 Builtin LCD 60 Using the LCD: PicBasic and PicBasic Pro Examples 63 Introduction to Binary and the PIC Microcontroller 65 Using TRIS and Port Registers 68 Accessing the Ports for Output 70 Counting Program 71 Counting in Binary by 1 71 Input 72 The button Command 72 A button Example 74 peek 75 peek and PicBasic Pro 76 Basic Input and Output Commands 77 Servomotors 78 Parts List 79 Chapter 7. Intelligence 83 Approaches to Building Intelligence 83 Where’s the Intelligence? 85 Layered Behavioral Responses 85 BehaviorBased Robotics 86 Chapter 8. Walter’s Turtle 87 BehaviorBased Robotics 87 William Grey Walter—Robotics Pioneer 87 Four Modes of Operation 88 Contents vii Observed Behavior 88 89 90 91 97 99 100 101 104 107 109 112 114 115 121 121 121 121 121 123 123 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 125 Neural I/O Relationships 126 126 128 129 131 133 137 139 139 Vehicles Building Vehicles Back Wheels Front Wheels CdS Photoresistor Cells Trimming the Sensor Array PIC 16F84 Microcontroller Testing Second Braitenberg Vehicle (Avoidance Behavior) 141 Parts List 141 Chapter 10. Hexapod Walker 143 Imitation of Life 143 Six Legs—Tripod Gait 143 ThreeServomotor Walker Robot 144 Function 144 Moving Forward 145 Moving Backward 146 Turning Left 147 Turning Right 148 Construction 148 Mounting the Servomotors 151 Leg Positioning 152 Linkage 154 viii Contents Center (Tilt) Servomotor 154 Sensors 155 Electronics 158 Microcontroller Program 159 Parts List 164 Chapter 11. Speech Recognition 165 Applications 167 Software Approach 167 Learning to Listen 167 SpeakerDependent and SpeakerIndependent Recognition 167 Recognition Style 168 Speech Recognition Circuit 168 Circuit Construction 168 Keypad 169 To Train 169 Testing Recognition 172 Error Codes 172 Clearing the Trained Word Memory 172 Independent Recognition System 172 Voice Security System 173 Speech Interface Control Circuit 173 How the Circuit Works 174 PIC 16F84 Microcontroller Program 176 Active High Output 177 SPDT Relay Output 177 Circuit Construction 177 Programming the Speech Recognition Circuit: Training, Testing, and Retraining 177 SRI02 and SRI03 Interfaces 180 Robot Control 180 Parts List 181 Chapter 12. Robotic Arm 185 Servomotor Building Blocks for Robotics 185 Basic Servomotor Bracket Assembly 186 Assembling MultipleServomotor Assemblies 189 Building a FiveServomotor Robotic Arm 192 Servomotors 197 Servomotor Controllers 199 Simple Servomotor Controller 200 Four and FiveServomotor Controllers 204 Increasing the Lifting Capacity of the Robotic Arm 215 Adding a Robotic Arm Base 216 Parts List 223 Chapter 13. Bipedal Walker Robot 225 A Question of Balance? 226 A Little Feedback 227 Servomotors 227 Contents ix Servomotor Brackets 228 Footpads 228 Assembly 230 Schematic 231 Program 233 Subroutines M1, M2, and M3 234 Going Further 241 Turning Right and Left 242 Parts List 242 Chapter 14. Color Robotic Vision System 243 CMU Camera 244 Serial Communication 245 VB Application Program 248 Interfacing the CMU Camera to a Robot 250 PIC 16F84 Runs at 16 MHz 251 Program 1 251 Program 2 254 Incandescent or Fluorescent Lighting 254 Servomotors for Robot 259 Program 3 261 Robot Construction 264 Running the Program 266 Going Further 267 Parts List 267 Suppliers 269 Index 271