Robotics with the Boe-Bot Student Guide VERSION 3.
WARRANTY Parallax warrants its products against defects in materials and workmanship for a period of 90 days from receipt of product. If you discover a defect, Parallax will, at its option, repair or replace the merchandise, or refund the purchase price. Before returning the product to Parallax, call for a Return Merchandise Authorization (RMA) number. Write the RMA number on the outside of the box used to return the merchandise to Parallax.
Table of Contents Preface.........................................................................................................................5 About Version 3.0 ...........................................................................................................6 Audience .........................................................................................................................6 Support Forums ..........................................................................................
Chapter 5 : Tactile Navigation with Whiskers ..................................................... 143 Tactile Navigation .......................................................................................................143 Activity #1 : Building and Testing the Whiskers ..........................................................144 Activity #2 : Field Testing the Whiskers ......................................................................152 Activity #3 : Navigation with Whiskers ...................
Preface · Page 5 Preface Robots are used in the auto, medical, and manufacturing industries, in all manner of exploration vehicles, and, of course, in many science fiction films. The word "robot" first appeared in a Czechoslovakian satirical play, Rossum's Universal Robots, by Karel Capek in 1920. Robots in this play tended to be human-like. From this point onward, it seemed that many science fiction stories involved these robots trying to fit into society and make sense out of human emotions.
Page 6 · Robotics with the Boe-Bot and calibration of the Boe-Bot. After that, you will program the Boe-Bot for basic maneuvers, and then proceed to adding sensors and writing programs that make it react to its surroundings and perform autonomous tasks. ABOUT VERSION 3.0 This is the first revision of this title since 2004.
Preface · Page 7 SUPPORT FORUMS Parallax maintains free, moderated forums for our customers, covering a variety of subjects: Propeller Chip: for all discussions related to the multicore Propeller microcontroller and development tools product line. BASIC Stamp: Project ideas, support, and related topics for all of the Parallax BASIC Stamp models. Sensors: Discussion relating to Parallax’s wide array of sensors, and interfacing sensors with Parallax microcontrollers.
Page 8 · Robotics with the Boe-Bot RESOURCES FOR EDUCATORS We have a variety of resources for this text designed to support educators. Stamps in Class “Mini Projects” To supplement our texts, we provide a bank of projects for the classroom. Designed to engage students, each “Mini Project” contains full source code, “How it Works” explanations, schematics, and wiring diagrams or photos for a device a student might like to use.
Preface · Page 9 FOREIGN TRANSLATIONS Many of our Stamps in Class texts have been translated into other languages; these texts are free downloads and subject to the same Copyright Permissions for Educational Use as our original versions. To see the full list, click on the Tutorials & Translations link at www.parallax.com/Education. These were prepared in coordination with the Parallax Volunteer Translator program.
Page 10 · Robotics with the Boe-Bot
Your Boe-Bot’s Brain · Page 11 Chapter 1: Your Boe-Bot’s Brain Parallax, Inc’s Boe-Bot® robot is the focus of the activities, projects, and contests in this book. The Boe-Bot and a close-up of its BASIC Stamp® 2 programmable microcontroller brain are shown in Figure 1-1. The BASIC Stamp 2 module is both powerful and easy to use, especially with a robot.
Page 12 · Robotics with the Boe-Bot What’s a Microcontroller? It’s a programmable device that is designed into your digital wristwatch, cell phone, calculator, clock radio, etc. In these devices, the microcontroller has been programmed to sense when you press a button, make electronic beeping noises, and control the device’s digital display.
Your Boe-Bot’s Brain · Page 13 Downloading the Software from the Internet It is important to always use the latest version of the BASIC Stamp Editor software if possible. The first step is to go to the Parallax web site and download the software. Using a web browser, go to www.parallax.com/basicstampsoftware. Figure 1-2: BASIC Stamp Editor download page at www.parallax.com/basicstampsoftware Use the “Click Here to Download” button to get the latest version of the software.
Page 14 · Robotics with the Boe-Bot A File Download window will open, asking you if you want to run or to save this file (Figure 1-3). Click Save. Figure 1-3 File Download Window Click Save, then save the file to your computer. Follow the prompts that appear. When the download is complete, click Run. You may see messages from your operating system asking you to verify that you wish to continue with installation. Always agree that you want to continue. Figure 1-4 Download Complete Message Click Run.
Your Boe-Bot’s Brain · Page 15 The BASIC Stamp Editor Installer window will open (Figure 1-5). Click Next and follow the prompts, accepting all defaults. Figure 1-5 BASIC Stamp Editor Installer Window Click Next. IMPORTANT: When the “Install USB Driver” message appears (Figure 1-6), leave the checkmark in place for the Automatically install/update driver (recommended) box, and then click Next. Figure 1-6 Install USB Driver Message Leave the box checked, and click Next.
Page 16 · Robotics with the Boe-Bot When the “Ready to Install the Program” message appears, click the Install button. A progress bar may appear, and this could take a few minutes. At this point, an additional window may appear behind the current window while the USB drivers are updating. This window will eventually close on its own when the driver installation is complete. If you don’t see this window, it does not indicate a problem. About USB drivers.
Your Boe-Bot’s Brain · Page 17 ACTIVITY #2: USING THE HELP FILE FOR HARDWARE SETUP In this section you will run the BASIC Stamp Editor’s Help file. Within the Help file, you will learn about the different BASIC Stamp programming boards available for the Stamps in Class program, and determine which one you are using. Then, you will follow the steps in the Help to connect your hardware to your computer and test your BASIC Stamp programming system.
Page 18 · Robotics with the Boe-Bot Figure 1-10: BASIC Stamp Editor Help Click on the Getting Started with Stamps in Class link on the bottom of the Welcome page, as shown in the lower right corner of Figure 1-10.
Your Boe-Bot’s Brain · Page 19 Following the Directions in the Help File From here, you will follow the directions in the Help file to complete these tasks: Identify which BASIC Stamp development board you are using Connect your development board to your computer Test your programming connection Troubleshoot your programming connection, if necessary Write your first PBASIC program for your BASIC Stamp Power down your hardware when you are done When you have completed the activities in the He
Page 20 · Robotics with the Boe-Bot A brief introduction to ASCII code How to disconnect the power to your Board of Education or HomeWork Board when you’re done Questions 1. What device will be the brain of your Boe-Bot? 2. When the BASIC Stamp sends a character to your PC/laptop, what type of numbers are used to send the message through the programming cable? 3. What is the name of the window that displays messages sent from the BASIC Stamp to your PC/laptop? 4.
Your Boe-Bot’s Brain · Page 21 Solutions Q1. A BASIC Stamp 2 microcontroller module. Q2. Binary numbers, that is, 0’s and 1’s. Q3. The Debug Terminal. Q4. DEBUG and END E1. It multiplies the two operands 7 and 11, resulting in a product of 77. The asterisk is the multiply operator. E2. The Debug Terminal would display: 18 E3. To fix the problem, add a carriage return using the CR control character and a comma. DEBUG DEC 7 * 11 DEBUG CR, DEC 7 + 11 P1.
Page 22 · Robotics with the Boe-Bot This output is the same as it was with the previous code. This is an example of using commas to output a lot of information, using only one DEBUG command with multiple elements in it.
Your Boe-Bot’s Servo Motors · Page 23 Chapter 2: Your Boe-Bot’s Servo Motors This chapter will guide you through connecting, adjusting, and testing the Boe-Bot’s motors. In order to do that, you will need to understand certain PBASIC commands and programming techniques that will control the direction, speed, and duration of servo motions. Therefore, Activities #1, #2, and #5 will introduce you to these programming tools, and then Activities #3, #4, and #6 will show you how to apply them to the servos.
Page 24 · Robotics with the Boe-Bot Standard Servos vs. Continuous Rotation Servos: Standard servos are designed to receive electronic signals that tell them what position to hold. These servos control the positions of radio controlled airplane flaps, boat rudders, and car steering. Continuous rotation servos receive the same electronic signals, but instead of holding certain positions, they turn at certain speeds and directions. Continuous rotation servos are ideal for controlling wheels and pulleys.
Your Boe-Bot’s Servo Motors · Page 25 A second is abbreviated “s.” In this text, when you see 1 s, it means one second. A millisecond is one thousandth of a second, and it is abbreviated “ms.” The command PAUSE 1000 delays the program for 1000 ms, which is 1000/1000 of a second, which is one second, or 1 s. Got it? Example Program: TimedMessages.bs2 There are lots of different ways to use the PAUSE command.
Page 26 · Robotics with the Boe-Bot Your Turn – Different Pause Durations You can change the delay between messages by changing the PAUSE commands’ Duration arguments. Try changing the PAUSE Duration arguments from 1000 and 2000 to 5000 and 10000, for example: DEBUG "Start timer..." PAUSE 5000 DEBUG CR, "Five seconds elapsed..." PAUSE 10000 DEBUG CR, "Fifteen seconds elapsed..." Run the modified program.
Your Boe-Bot’s Servo Motors · Page 27 ' Robotics with the Boe-Bot - HelloOnceEverySecond.bs2 ' Display a message once every second. ' {$STAMP BS2} ' {$PBASIC 2.5} DO DEBUG "Hello!", CR PAUSE 1000 LOOP Your Turn – A Different Message You can modify your program so that part of it executes once, and another part executes over an over again.
Page 28 · Robotics with the Boe-Bot Introducing the LED and Resistor A resistor is a component that “resists” the flow of electricity. This flow of electricity is called current. Each resistor has a value that tells how strongly it resists current flow. This resistance value is called the ohm, and the sign for the ohm is the Greek letter omega: Ω. The resistor you will be working with in this activity is the 470 Ω resistor shown in Figure 2-2.
Your Boe-Bot’s Servo Motors · Page 29 labeled with a minus-sign (-), and on the schematic symbol, the cathode is the line across the point of the triangle. Figure 2-3 LED Part Drawing and Schematic Symbol Part drawing (above) and schematic symbol (below) _ The LED part drawings in later pictures will have a + next to the anode leg. + LED When you start building your circuit, make sure to check it against the schematic symbol and part drawing.
Page 30 · Robotics with the Boe-Bot LED Test Circuits If you completed the What’s a Microcontroller? text, you are no doubt very familiar with the circuit shown in Figure 2-4. The left side of this figure shows the circuit schematic, and the right side shows a wiring diagram example of the circuit built on your board’s prototyping area. Build the circuit shown in Figure 2-4. Make sure that the shorter pins on each LED (the cathodes) are plugged into black sockets labeled Vss.
Your Boe-Bot’s Servo Motors · Page 31 Figure 2-5 shows what you will program the BASIC Stamp to do to the LED circuit. Imagine that you have a 5 volt (5 V) battery. Although a 5 V battery is not common, the Board of Education has a device called a voltage regulator that supplies the BASIC Stamp with the equivalent of a 5 V battery. When you connect a circuit to Vss, it’s like connecting the circuit to the negative terminal of the 5 V battery.
Page 32 · Robotics with the Boe-Bot Programs that Control the LED Test Circuits The HIGH and LOW commands can be used to make the BASIC Stamp connect an LED alternately to Vdd and Vss. The Pin argument is a number between 0 and 15 that tells the BASIC Stamp which I/O pin to connect to Vdd or Vss. HIGH Pin LOW Pin For example, if you use the command: HIGH 13 ...it tells the BASIC Stamp to connect I/O pin P13 to Vdd, which turns the LED on. Likewise, if you use the command LOW 13 ...
Your Boe-Bot’s Servo Motors · Page 33 How HighLowLed.bs2 Works Figure 2-6 shows how the BASIC Stamp can connect an LED circuit alternately to Vdd and Vss. When it’s connected to Vdd, the LED emits light. When it’s connected to Vss, the LED does not emit light. The command HIGH 13 instructs the BASIC Stamp to connect P13 to Vdd. The command PAUSE 500 instructs the BASIC Stamp to leave the circuit in that state for 500 ms. The command LOW 13 instructs the BASIC Stamp to connect the LED to Vss.
Page 34 · Robotics with the Boe-Bot If the LED blinked on and off only once and then stopped, you have a computer with a non-standard serial port design. If you disconnect the programming cable from your board and press the Reset button, the BASIC Stamp will run the program properly without freezing. In programs you write yourself, you should add a single command: DEBUG "Program Running!" ...right after the compiler directives. This will open the Debug Terminal and keep the COM port open.
Your Boe-Bot’s Servo Motors · Page 35 Your Turn – Blink the Other LED Blinking the other LED (connected to P12) is a simple matter of changing the Pin argument in the HIGH and LOW commands and re-running the program. Modify the program so that the commands look like this: DO HIGH 12 PAUSE 500 LOW 12 PAUSE 500 LOOP Run the modified program and verify that it makes the other LED blink on/off. You can also make both LEDs blink at the same time.
Page 36 · Robotics with the Boe-Bot Viewing a Servo Control Signal with an LED The high and low signals you will program the BASIC Stamp to send to the servo motors must last for very precise amounts of time. That’s because the servo motors measure the amount of time the signal stays high, and use it as an instruction for where to turn. For accurate servo motor control, the time these signals stay high must be much more precise than you can get with a HIGH and a PAUSE command.
Your Boe-Bot’s Servo Motors · Page 37 The largest value you can use in a PULSOUT Duration argument is 65535. Example Program: PulseP13Led.bs2 This timing diagram in Figure 2-8 shows the pulse train you are about to send to the LED with this new program. This time, the high signal lasts for 0.13 seconds, and the low signal lasts for 2 seconds. This is 100 times slower than the signal that the servo will need to control its motion. 0.13 s 0.13 s Vdd (5 V) Figure 2-8 Timing Diagram for PulseP13Led.
Page 38 · Robotics with the Boe-Bot Example Program: PulseBothLeds.bs2 This example program sends a pulse to the LED connected to P13, and then it sends a pulse to the LED connected to P12 as shown in Figure 2-9. After that, it pauses for two seconds. 0.13 s 0.13 s P13 Figure 2-9 Timing Diagram for PulseBothLeds.bs2 0.13 s 0.13 s P12 The LEDs emit light for 0.13 second while the signal is high. 2.26 s The voltages (Vdd and Vss) in this timing diagram are not labeled.
Your Boe-Bot’s Servo Motors · Page 39 ' Robotics with the Boe-Bot – PulseBothLeds.bs2 ' Send a 0.13 second pulse to P13 and P12 every 2 seconds. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" DO PULSOUT 13, 65000 PULSOUT 12, 65000 PAUSE 2000 LOOP Your Turn – Viewing the Full Speed Servo Signal Remember the servo signal is 100 times as fast as the program you just ran. First, let’s try running the program ten times as fast. That means divide all the Duration arguments (PULSOUT and PAUSE) by 10.
Page 40 · Robotics with the Boe-Bot Run the modified program and verify that it makes both LEDs about the same brightness. Try substituting 850 in the Duration argument for the P13 PULSOUT command. DO PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 LOOP Run the modified program and verify that the P13 LED now appears slightly brighter than the P12 LED. You may have to cup your hands around the LEDs and peek inside to see the difference.
Your Boe-Bot’s Servo Motors · Page 41 Finding the Connection Instructions for Your Carrier Board There are different revisions of the Board of Education and BASIC Stamp HomeWork Board. Furthermore, there are several variations to the Board of Education, based on programming interface. In Chapter 1, you used the BASIC Stamp Editor Help file to determine the type and revision of your board, and special instructions for older boards.
Page 42 · Robotics with the Boe-Bot Connecting the Servos to the Board of Education Turn off the power by setting the 3-position switch on your Board of Education to position-0 (see Figure 2-11). Reset 0 1 Figure 2-11 Turn Off Power 2 Figure 2-12 shows the servo header on the Board of Education. This board features a jumper that you can use to connect the servo’s power supply to either Vin or Vdd.
Your Boe-Bot’s Servo Motors · Page 43 15 14 Vdd 13 12 Red Black X4 X5 Vin Select Vdd if you are using a DC supply that plugs into an AC outlet (AC adapter). Figure 2-12 Selecting Your Servo Ports’ Power Supply on the Board of Education 15 14 Vdd 13 12 Red Black Select Vin if you are using the battery pack that comes with the Boe-Bot kits. X4 X5 Vin All examples and instructions in this book will use the battery pack.
Page 44 · Robotics with the Boe-Bot Figure 2-14 Board of Education with Servos and Battery Pack Connected If you removed the LED circuits after Activity #2, make sure to rebuild them as shown in Figure 2-15. They will be your servo signal monitoring circuits.
Your Boe-Bot’s Servo Motors · Page 45 Connecting the Servos to the BASIC Stamp HomeWork Board If you are connecting your servos to a BASIC Stamp HomeWork Board, you will need the parts listed below and shown in Figure 2-16: Parts List: (1) Battery pack with tinned leads (not included, see Appendix A) (2) Parallax Continuous Rotation Servos (2) 3-pin male-male headers (not included, see Appendix A) (4) Jumper wires (4) AA batteries – 1.
Page 46 · Robotics with the Boe-Bot Vbp White Red Black P13 Figure 2-17 Servo Connection Schematic for the BASIC Stamp HomeWork Board Vss Vbp White Red Black P12 Note: Vbp stands for Voltage Battery Pack. See the i-box below. Vss Remove the two LED/resistor circuits, and save the parts. Build the servo ports shown on the left side of Figure 2-18. Double-check to make sure the black wire with the white stripe is connected to Vbp, and the solid black wire should be connected to Vss.
Your Boe-Bot’s Servo Motors · Page 47 Figure 2-18: Servo Connection Wiring Diagram for the BASIC Stamp HomeWork Board Black wire with white stripe Solid Black Wire (916) 624-8333 www.parallaxinc.com www.stampsinclass.com Vdd Vin (916) 624-8333 www.parallaxinc.com www.stampsinclass.
Page 48 · Robotics with the Boe-Bot Rebuild the LED circuit as shown in Figure 2-20. (916) 624-8333 www.parallaxinc.com www.stampsinclass.com Vdd X3 P13 470 P12 470 LED Vss LED Vss Vin + Rev B Vss Vss + P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0 X2 Figure 2-20 LED Servo Signal Monitor Circuit © 2002 HomeWork Board When all your connections are made and double-checked, load the battery pack with batteries and reconnect the 9 V battery to the HomeWork Board’s battery clip.
Your Boe-Bot’s Servo Motors · Page 49 ACTIVITY #4: CENTERING THE SERVOS In this activity, you will run a program that sends the servos a signal, instructing them to stay still. Because the servos are not pre-adjusted at the factory, they will instead start turning. You will then use a screwdriver to adjust them so that they stay still. This is called centering the servos. After the adjustment, you will test the servos to make sure they are functioning properly.
Page 50 · Robotics with the Boe-Bot argument has to be for 1.5 ms pulses. 1.5 ms is 1.5 thousandths of a second, or 0.0015 s. Remember whatever number is in the PULSOUT command's Duration argument, multiply that number by 2 μs (2 millionths of a second = 0.000002 s), and you will know how long the pulse will last. You can also figure out what the PULSOUT command's Duration argument has to be if you know how long you want the pulse to last. Just divide 2 μs into the time you want the pulse to last.
Your Boe-Bot’s Servo Motors · Page 51 Example Program: CenterServoP12.bs2 ' Robotics with the Boe-Bot - CenterServoP12.bs2 ' This program sends 1.5 ms pulses to the servo connected to ' P12 for manual centering. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" DO PULSOUT 12, 750 PAUSE 20 LOOP If the servo has not yet been centered, its horn will start turning, and you will be able to hear the motor inside making a whining noise.
Page 52 · Robotics with the Boe-Bot If the servo has already been centered, it will not turn. It is unlikely, but a damaged or defective servo would also not turn. Activity #6 will rule out this possibility before the servos are installed on your Boe-Bot chassis. If the servo does not turn, go to the Your Turn section so that you can test and center the other servo that’s connected to P13. What's a Potentiometer? A potentiometer is kind of like an adjustable resistor.
Your Boe-Bot’s Servo Motors · Page 53 ACTIVITY #5: HOW TO STORE VALUES AND COUNT This activity introduces variables, which are used in PBASIC programs to store values. Boe-Bot programs later in this book will rely heavily on variables. The most important thing about being able to store values is that the program can use them to count. As soon as your program can count, it can both control and keep track of the number of times something happens.
Page 54 · Robotics with the Boe-Bot Default Value - If you do not initialize a variable, the program will automatically start by storing the number zero in that variable. That’s called the variable's default value. The “=” sign in value = 500 is an example of an operator. You can use other operators to do math with variables. Here are a couple of multiplication examples: value = 10 * value anotherValue = 2 * value Example Program: VariablesAndSimpleMath.
Your Boe-Bot’s Servo Motors · Page 55 These commands are examples of initializing variables to values that you determine. After these two commands are executed, value will store 500, and anotherValue will store 2000. value = 500 anotherValue = 2000 ' Initialize variables These DEBUG commands help you see what each variable stores after you initialize them.
Page 56 · Robotics with the Boe-Bot Replace it with the following: value = value - anotherValue ' Answer = -1500 DEBUG "value = ", SDEC value, CR ' Display values again Run the modified program and verify that value changes from 500 to -1500. Counting and Controlling Repetitions The most convenient way to control the number of times a piece of code is executed is with a FOR…NEXT loop. Here is the syntax: FOR Counter = StartValue TO EndValue {STEP StepValue}…NEXT The three dots “...
Your Boe-Bot’s Servo Motors · Page 57 ' Robotics with the Boe-Bot – CountToTen.bs2 ' Use a variable in a FOR...NEXT loop. ' {$STAMP BS2} ' {$PBASIC 2.5} myCounter VAR Word FOR myCounter = 1 TO 10 DEBUG ? myCounter PAUSE 500 NEXT DEBUG CR, "All done!" END Your Turn – Different Start and End Values and Counting in Steps You can use different values for the StartValue and EndValue arguments.
Page 58 · Robotics with the Boe-Bot ACTIVITY #6: TESTING THE SERVOS There’s one last thing to do before assembling your Boe-Bot, and that’s testing the servos. In this activity, you will run programs that make the servos turn at different speeds and directions. By doing this, you will verify that your servos are working properly before you assemble your Boe-Bot. This is an example of subsystem testing.
Your Boe-Bot’s Servo Motors · Page 59 What’s RPM? Revolutions Per Minute. It’s the number of full circles something turns in a minute. What’s a pulse train? Just as a railroad train is a series of cars, a pulse train is a series of pulses. ServoP13Clockwise.bs2 sends this pulse train to the servo connected to P13. Enter, save, and run ServoP13Clockwise.bs2. Verify that the servo’s horn is rotating between 50 and 60 RPM clockwise. ' Robotics with the Boe-Bot – ServoP13Clockwise.
Page 60 · Robotics with the Boe-Bot DEBUG "Program Running!" DO PULSOUT 12, 650 PAUSE 20 LOOP Example Program: ServoP12Counterclockwise.bs2 You probably guessed that making the PULSOUT command’s Duration argument greater than 750 causes the servo to rotate counterclockwise. A Duration of 850 will send 1.7 ms pulses. This will make the servo turn full speed counterclockwise as shown in Figure 2-26. 1.7 ms 1.7 ms Vdd (5 V) standard servo www.parallax.com Vss (0 V) Figure 2-26 A 1.
Your Boe-Bot’s Servo Motors · Page 61 Pulse Width Modulation. A voltage that spends certain amounts of time in two different states can be considered as a series of resting states and a pulses. Here is a list of different pulse signals that control your servo speed and direction: Figure 2-22 on page 49: 1.5 ms high makes the servo hold still. Figure 2-25 on page 58: 1.3 ms high makes the servo turn clockwise. Figure 2-26 on page 60: 1.7 ms high makes the servo turn counterclockwise.
Page 62 · Robotics with the Boe-Bot ' Robotics with the Boe-Bot - ServosP13CcwP12Cw.bs2 ' Run the servo connected to P13 at full speed counterclockwise ' and the servo connected to P12 at full speed clockwise. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" DO PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 LOOP This will be important soon.
Your Boe-Bot’s Servo Motors · Page 63 Table 2-1: PULSOUT Duration Combinations Durations P13 P12 850 650 650 850 850 850 650 650 750 850 650 750 750 750 760 740 770 730 850 700 800 650 Description Full speed, P13 servo counterclockwise, P12 servo clockwise. Both servos should stay still because of the centering adjustments made in Activity #4.
Page 64 · Robotics with the Boe-Bot FOR…NEXT to Control Servo Run Time Hopefully, by now you fully understand that pulse width controls the speed and direction of a Parallax Continuous Rotation servo. It’s a pretty simple way to control motor speed and direction. There is also a simple way to control the amount of time a motor runs, and that’s with a FOR…NEXT loop.
Your Boe-Bot’s Servo Motors · Page 65 ' ' ' ' ' Robotics with the Boe-Bot - ControlServoRunTimes.bs2 Run the P13 servo at full speed counterclockwise for 2.3 s, then run the P12 servo for twice as long. {$STAMP BS2} {$PBASIC 2.5} DEBUG "Program Running!" counter VAR Byte FOR counter = 1 TO 100 PULSOUT 13, 850 PAUSE 20 NEXT FOR counter = 1 TO 200 PULSOUT 12, 850 PAUSE 20 NEXT END Let’s say you want to run both servos, the P13 servo at a pulse width of 850 and the P12 servo at a pulse width of 650.
Page 66 · Robotics with the Boe-Bot Now, you can use the value 122 in the EndValue of the FOR…NEXT loop, and it will look like this: FOR counter = 1 TO 122 PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT Example Program: BothServosThreeSeconds.bs2 Here’s an example of making the servos turn in one direction for three seconds, then reversing their direction. Enter, save, and run BothServosThreeSeconds.bs2. ' Robotics with the Boe-Bot - BothServosThreeSeconds.
Your Boe-Bot’s Servo Motors · Page 67 Your Turn – Predict Servo Run Time Pick a time (six seconds or less), that you want your servos to turn. Divide the number of seconds by 0.024. Your answer is the number of loops you will need. Modify BothServosThreeSeconds.bs2 so that it makes both servos run for the amount of time you selected. Compare your predicted run time to the actual run time. Remember to disconnect power from your system (board and servos) when you are done.
Page 68 · Robotics with the Boe-Bot Questions 1. How do the Parallax Continuous Rotation servos differ from standard servos? 2. How long does a millisecond last? How do you abbreviate it? 3. What PBASIC commands can you use to make other PBASIC commands execute over and over again? 4. What command causes the BASIC Stamp to internally connect one of its I/O pins to Vdd? What command makes the same kind of connection, but to Vss? 5.
Your Boe-Bot’s Servo Motors · Page 69 Solutions Q1. Instead of holding a certain position like a standard servo, the Parallax Continuous Rotation servos turn a certain direction at a certain speed. Q2. A millisecond lasts one thousandth of a second, and "ms" is the abbreviation. Q3. The DO…LOOP command is used to make other PBASIC commands execute over and over. Q4. HIGH connects I/O pin to Vdd, LOW connects I/O pin to Vss. Q5. The variable sizes are bit, nib, byte, and word.
Page 70 · Robotics with the Boe-Bot P1. The key to solving this problem is to send a pulse train to the LED as well as the servo. ' Robotics with the Boe-Bot - Ch02Prj01_DimlyLitLED.bs2 ' Run servo and send same signal to dimly light the LED on P14. '{$STAMP BS2} '{$PBASIC 2.5} DEBUG "Program Running!" DO PULSOUT 12, 650 PULSOUT 14, 650 PAUSE 20 LOOP ' P12 servo clockwise ' P14 LED lights dimly P2.
Your Boe-Bot’s Servo Motors · Page 71 Now write four FOR…NEXT loops, using the number of pulses calculated for the EndValue argument. Include the correct PULSOUT arguments for the combination of rotation. ' Robotics with the Boe-Bot - Ch02Prj02_4RotationCombinations.bs2 ' Move servos through 4 clockwise/counterclockwise rotation ' combinations. '{$STAMP BS2} '{$PBASIC 2.
Page 72 · Robotics with the Boe-Bot
Assemble and Test Your Boe-Bot · Page 73 Chapter 3: Assemble and Test Your Boe-Bot This chapter contains instructions for building and testing your Boe-Bot. It’s especially important to complete the testing portion before moving on to the next chapter. By doing so, you can help avoid a number of common mistakes that lead to mystifying Boe-Bot behavior in later chapters. Here is a summary of what you will do in each of the activities in this chapter: Activity 1 2 3 4 Summary Build the Boe-Bot.
Page 74 · Robotics with the Boe-Bot Mounting the Topside Hardware Start by gathering this list of parts. Then, follow the accompanying instructions. Parts List: See Figure 3-2. (1) (4) (4) (1) Boe-Bot chassis 1″ Standoffs Pan head screws, 1/4″ 4-40 Rubber grommet, 13/32″ Instructions: Insert the 13/32″ rubber grommet into the hole in the center of the Boe-Bot chassis. Make sure the groove in the outer edge of the rubber grommet is seated on the edge of the hole in the chassis.
Assemble and Test Your Boe-Bot · Page 75 Removing the Servo Horns Disconnect the power from your BASIC Stamp and servos. Remove all of the AA batteries from the battery pack. Disconnect the servos from your board. Parts List: Instructions: See Figure 3-3. (2) Parallax Continuous Rotation servos, previously centered Use a Phillips screwdriver to remove the screws that hold the servo control horns on the output shafts. Pull each horn upwards and off the servo output shaft.
Page 76 · Robotics with the Boe-Bot Mounting the Servos on the Chassis Servo Mounting Options - Agile Maneuvers vs. Potentiometer & Maintenance Access The photographs in this text show the servos mounted from the inside, and oriented so the potentiometer access port is facing the center of the chassis. This positions the axles close to the center of the Boe-Bot, allowing for agile maneuvering. If you are diligent about centering your servos before building your Boe-Bot, this causes no problems.
Assemble and Test Your Boe-Bot · Page 77 Mounting the Battery Pack Figure 3-5 shows two different sets of parts. Use the parts on the left if you have a Board of Education, and the parts on the right if you have a HomeWork Board. Parts List for Boe-Bot with a Board of Education: Parts List for Boe-Bot with a HomeWork Board: See Figure 3-5 (left side). See Figure 3-5 (right side).
Page 78 · Robotics with the Boe-Bot As shown on the right side of Figure 3-6, pull the battery pack’s power cord through the hole with the rubber grommet in the center of the chassis. Pull the servo lines through the same hole. Arrange the servo lines and supply cable as shown.
Assemble and Test Your Boe-Bot · Page 79 Line the hole in the tail wheel up with the holes in the tail portion of the chassis. Run the cotter pin through all three holes (chassis left, tail wheel, chassis right). Bend the ends of the cotter pin apart so that it can’t slide back out of the hole. The right side of Figure 3-8 shows the Boe-Bot’s drive wheels mounted on the servos. Stretch each rubber band tire and seat it on the outer edge of each wheel.
Page 80 · Robotics with the Boe-Bot Attaching the Board to the Chassis Parts List for Boe-Bot with a Board of Education: Parts List for Boe-Bot with a HomeWork Board: See left side of Figure 3-9. See right side of Figure 3-9.
Assemble and Test Your Boe-Bot · Page 81 White Red Black White Red Black White Stripe (916) 624-8333 www.parallaxinc.com www.stampsinclass.com 15 14 Vdd 13 12 Vdd Red Black X4 X5 On Board of Education Vin SolidB Rev Black Vss X3 P15 P14 P13 P12 P11 P10 P9 P8 Figure 3-10 Servo Ports Reconnecte d P13 - White Vbp - Red Vss - Black Vbp - Red P12 - White On HomeWork Board Figure 3-11 shows the Boe-Bot chassis with their respective boards attached.
Page 82 · Robotics with the Boe-Bot From the underside of the chassis, pull any excess servo and battery cable through the hole with the rubber grommet. Tuck the excess cable lengths between the servos and the chassis. Figure 3-12 Assembled Boe-Bot Robots With Board of Education With HomeWork Board ACTIVITY #2: RE-TEST THE SERVOS In this activity, you will test to make sure that the electrical connections between your board and the servos are correct.
Assemble and Test Your Boe-Bot · Page 83 Testing the Right Wheel The next example program will test the servo connected to the right wheel, shown in Figure 3-14. The program will make this wheel turn clockwise for three seconds, then stop for one second, then turn counterclockwise for three seconds. Clockwise 3 seconds Stop 1 second Figure 3-14 Testing the Right Wheel Counterclockwise 3 seconds Example Program: RightServoTest.
Page 84 · Robotics with the Boe-Bot FOR counter = 1 TO 40 PULSOUT 12, 750 PAUSE 20 NEXT ' Stop one second. FOR counter = 1 TO 122 PULSOUT 12, 850 PAUSE 20 NEXT ' Counterclockwise three seconds. END Your Turn – Testing the Left Wheel Now, it’s time to run the same test on the left wheel as shown in Figure 3-15. This involves modifying RightServoTest.bs2 so that the PULSOUT commands are sent to the servo connected to P13 instead of the servo connected to P12.
Assemble and Test Your Boe-Bot · Page 85 Servo Troubleshooting: Here is a list of some common symptoms and how to fix them. The servo doesn’t turn at all. If you are using a Board of Education, make sure the 3-position switch is set to position-2. You can then re-run the program by pressing and releasing the Reset button. If you are using a BASIC Stamp HomeWork Board, make sure the battery pack has fresh batteries, all oriented properly in the case.
Page 86 · Robotics with the Boe-Bot ACTIVITY #3: START/RESET INDICATOR CIRCUIT AND PROGRAM When the voltage supply drops below the level a device needs to function properly, it’s called brownout. The BASIC Stamp protects itself from brownout by making its processor and program memory chips go dormant until the power supply voltage returns to normal levels. A drop below 5.2 V at Vin results in a drop below 4.3 V at the BASIC Stamp’s internal voltage regulator output.
Assemble and Test Your Boe-Bot · Page 87 This exercise will introduce a device called a piezoelectric speaker (piezospeaker) that you can use to generate tones. This speaker can make different tones depending on the frequency of high/low signals it receives from the BASIC Stamp. The schematic symbol and part drawing for the piezoelectric speaker are shown in Figure 3-16.
Page 88 · Robotics with the Boe-Bot Building the Start/Reset Indicator Circuit Figure 3-17 shows piezospeaker alarm circuit schematics for both the Board of Education and BASIC Stamp HomeWork Board. Figure 3-18 shows a wiring diagram for each board. Always disconnect power before building or modifying circuits! If you have a Board of Education, set the 3-position switch to position-0.
Assemble and Test Your Boe-Bot · Page 89 To Servos To Servos 15 14 Vdd 13 12 (916) 624-8333 Rev B www.parallax.com www.stampsinclass.
Page 90 · Robotics with the Boe-Bot Frequency can be measured in hertz (Hz). The hertz is a frequency measurement of how many times per second something happens. One hertz is simply one time-per-second, and it’s abbreviated 1 Hz. One kilohertz is one-thousand-times-per-second, and it’s abbreviated 1 kHz. FREQOUT digitally synthesizes tones. The FREQOUT command applies high/low pulses of varying durations that make a piezospeaker’s vibration more closely resemble natural vibrations of music strings.
Assemble and Test Your Boe-Bot · Page 91 DEBUG CLS, "Beep!!!" FREQOUT 4, 2000, 3000 ' Display while speaker beeps. ' Signal program start/reset. DO ' ' ' ' DEBUG CR, "Waiting for reset…" PAUSE 500 LOOP DO...LOOP Display message every 0.5 seconds until hardware reset. How StartResetIndicator.bs2 Works StartResetIndicator.bs2 starts by displaying the message “Beep!!!” Then, immediately after printing the message, the FREQOUT command plays a 3 kHz tone on the piezoelectric speaker for 2 s.
Page 92 · Robotics with the Boe-Bot ACTIVITY #4: TESTING SPEED CONTROL WITH THE DEBUG TERMINAL In this activity, you will graph servo speed vs. pulse width. One thing that can make this process go much more quickly is the Debug Terminal’s Transmit windowpane, which is shown in Figure 3-19. You can use the Transmit windowpane to send the BASIC Stamp messages. By sending messages that tell the BASIC Stamp what pulse width to deliver to the servo, you can test the servo speed at various pulse widths.
Assemble and Test Your Boe-Bot · Page 93 The DEBUGIN command places the value you type in the Transmit windowpane into a variable. In the next example program, a word variable named pulseWidth will be used to store the values the DEBUGIN command receives. pulseWidth VAR Word Now, the DEBUGIN command can be used to capture a decimal value that you enter into the Debug Terminal’s Transmit windowpane and store it in pulseWidth: DEBUGIN DEC pulseWidth You can then program the BASIC Stamp to use this value.
Page 94 · Robotics with the Boe-Bot Use the Debug Terminal to test how far the wheel turns for each of these pulse widths: 650, 660, 670, 680, 690, 700, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850 For each pulse width, multiply the number of turns by 10 to get the RPM. For example, if the wheel makes 3.65 full turns, it was rotating at 36.5 RPM. Explain in your own words how you can use pulse width to control Continuous Rotation servo speed.
Assemble and Test Your Boe-Bot · Page 95 The FREQOUT command is used to signal that the program has started. FREQOUT 4,2000,3000 The remainder of the program is nested within a DO…LOOP, so it will execute over and over again. The Debug Terminal’s operator (that's you) is asked to enter a pulse width. The DEBUGIN command stores this value in the pulseWidth variable. DEBUG "Enter pulse width: " DEBUGIN DEC pulseWidth To make the measurement more accurate, two PULSOUT commands have to be sent.
Page 96 · Robotics with the Boe-Bot velocity in RPM. In this graph, clockwise is negative and counterclockwise is positive. This particular servo’s transfer curve ranges from about -48 RPM to 48 RPM over the range of test pulse widths that range from 1.3 ms to 1.7 ms. Rotational Velocity vs. Pulse Width for Servo 60 Rotational Velocity, RPM 40 20 Figure 3-20 Transfer Curve Example for Parallax Continuous Rotation Servo 0 -20 -40 -60 1.300 1.350 1.400 1.450 1.500 1.550 1.600 1.650 1.
Assemble and Test Your Boe-Bot · Page 97 Table 3-1: Pulse Width and RPM for Parallax Continuous Rotation Servo Pulse Width (ms) Rotational Velocity (RPM) Pulse Width (ms) Rotational Velocity (RPM) Pulse Width (ms) Rotational Velocity (RPM) Pulse Width (ms) 1.300 1.400 1.500 1.600 1.310 1.410 1.510 1.610 1.320 1.420 1.520 1.620 1.330 1.430 1.530 1.630 1.340 1.440 1.540 1.640 1.350 1.450 1.550 1.650 1.360 1.460 1.560 1.660 1.370 1.470 1.570 1.670 1.380 1.480 1.580 1.
Page 98 · Robotics with the Boe-Bot SUMMARY This chapter covered Boe-Bot assembly and testing. This involved mechanical assembly, such as connecting the various moving parts to the Boe-Bot chassis. It also involved circuit assembly, connecting the servos and piezospeaker. The testing involved retesting the servos after they were disconnected to build the Boe-Bot. The concept of brownout was introduced along with what this condition does to a program running on the BASIC Stamp.
Assemble and Test Your Boe-Bot · Page 99 Questions 1. 2. 3. 4. 5. What are some of the symptoms of brownout on the Boe-Bot? How can a piezospeaker be used to detect brownout? What is a reset? What is an initialization routine? What are three (or more) possible mistakes that can occur when disconnecting and reconnecting the servos? 6. What command do you have to change in RightServoTest.bs2 to test the left wheel instead of the right wheel? Exercises 1.
Page 100 · Robotics with the Boe-Bot Solutions Q1. Symptoms include erratic behavior such as going in unexpected directions or doing a confused dance. Q2. A FREQOUT command at the beginning of all Boe-Bot programs causes the piezospeaker to play a tone. This tone will therefore occur every time an accidental reset happens due to brownout conditions. Q3. A reset is when the power is interrupted and the BASIC Stamp program starts running again from the beginning of the program. Q4.
Assemble and Test Your Boe-Bot · Page 101 PULSOUT 12, 750 PAUSE 20 NEXT FOR counter = 1 TO 122 PULSOUT 12, 850 PAUSE 20 NEXT ' Counterclockwise three seconds. FREQOUT 4, 500, 3500 ' Signal end of program END P2. To solve this problem, TestServoSpeed.bs2 must be expanded to receive three pieces of data: left servo pulsewidth, right servo pulsewidth, and number of pulses. Then, a FOR…NEXT loop with two servo PULSOUT commands must be added to actually move the servo motors.
Page 102 · Robotics with the Boe-Bot
Boe-Bot Navigation · Page 103 Chapter 4: Boe-Bot Navigation The Boe-Bot can be programmed to perform a variety of maneuvers. The maneuvers and programming techniques introduced in this chapter will be reused in later chapters. The only difference is that in this chapter, the Boe-Bot will blindly perform the maneuvers. In later chapters, the Boe-Bot will perform similar maneuvers in response to conditions it detects with its sensors.
Page 104 · Robotics with the Boe-Bot Left Turn Backward Forward Figure 4-1 Your Boe-Bot and Driving Directions Right Turn Moving Forward Here’s a funny thing: to make the Boe-Bot go forward, the Boe-Bot’s left wheel has to turn counterclockwise, but its right wheel has to turn clockwise. If you haven’t already grasped this, take a look at Figure 4-2 and see if you can convince yourself that it’s true. Viewed from the left, the wheel has to turn counterclockwise for the Boe-Bot to move forward.
Boe-Bot Navigation · Page 105 the same amount of time, the EndValue argument also controls the time the servo runs. Here’s an example program that will make the Boe-Bot roll forward for about three seconds. Example Program: BoeBotForwardThreeSeconds.bs2 Make sure power is connected to the BASIC Stamp and servos. Enter, save, and run BoeBotForwardThreeSeconds.bs2. ' Robotics with the Boe-Bot - BoeBotForwardThreeSeconds.bs2 ' Make the Boe-Bot roll forward for three seconds. ' {$STAMP BS2} ' {$PBASIC 2.
Page 106 · Robotics with the Boe-Bot This FOR…NEXT loop sends 122 sets of pulses to the servos, one each to P13 and P12, pausing for 20 ms after each set and then returning to the top of the loop. FOR counter = 1 TO 122 PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT PULSOUT 13, 850 causes the left servo to rotate counterclockwise while PULSOUT 12, 650 causes the right servo to rotate clockwise. Therefore, both wheels will be turning toward the front end of the Boe-Bot, causing it to drive forward.
Boe-Bot Navigation · Page 107 Moving Backward, Rotating, and Pivoting All it takes to get other motions out of your Boe-Bot are different combinations of the PULSOUT Duration arguments.
Page 108 · Robotics with the Boe-Bot FOR counter = 1 TO 64 ' Forward PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT PAUSE 200 FOR counter = 1 TO 24 ' Rotate left - about 1/4 turn PULSOUT 13, 650 PULSOUT 12, 650 PAUSE 20 NEXT PAUSE 200 FOR counter = 1 TO 24 ' Rotate right - about 1/4 turn PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT PAUSE 200 FOR counter = 1 TO 64 ' Backward PULSOUT 13, 650 PULSOUT 12, 850 PAUSE 20 NEXT END Your Turn – Pivoting You can make the Boe-Bot turn by pivoting around one
Boe-Bot Navigation · Page 109 If you want to pivot forward and to the right, simply stop the right wheel, and make the left wheel turn counterclockwise (forward). PULSOUT 13, 850 PULSOUT 12, 750 These are the PULSOUT commands for pivoting backwards and to the right. PULSOUT 13, 650 PULSOUT 12, 750 Finally, these are the PULSOUT commands for pivoting backwards and to the left. PULSOUT 13, 750 PULSOUT 12, 850 Save ForwardLeftRightBackward.bs2 as PivotTests.bs2.
Page 110 · Robotics with the Boe-Bot Example Program: BoeBotForwardTenSeconds.bs2 Open BoeBotForwardThreeSeconds.bs2. Rename and save it as BoeBotForwardTenSeconds.bs2. Change the EndValue of the FOR counter from 122 to 407, so it reads like this: ' Robotics with the Boe-Bot - BoeBotForwardTenSeconds.bs2 ' Make the Boe-Bot roll forward for ten seconds. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" counter VAR Word FREQOUT 4, 2000, 3000 ' Signal program start/reset.
Boe-Bot Navigation · Page 111 to 750. If the Boe-Bot is only just a little off course, maybe PULSOUT 12,663 will do the trick. If the servos are severely mismatched, maybe it needs to be PULSOUT 12,690. It will probably take several tries to get the right value. Let’s say that your first guess is that PULSOUT 12,663 will do the trick, but it turns out not to be enough because the BoeBot is still turning slightly to the left. So try PULSOUT 12,670.
Page 112 · Robotics with the Boe-Bot Here’s the left turn routine from ForwardLeftRightBackward.bs2: FOR counter = 1 TO 24 ' Rotate left - about 1/4 turn PULSOUT 13, 650 PULSOUT 12, 650 PAUSE 20 NEXT Let’s say that the Boe-Bot turns just a bit more than 90° (1/4 of a full circle). Try FOR counter = 1 TO 23, or maybe even FOR counter = 1 TO 22.
Boe-Bot Navigation · Page 113 You might remember asking your parents this question, over and over again, while on your way to a vacation destination or relatives’ house: “Are we there yet?” Perhaps when you got a little older, and learned division in school, you started watching the road signs to see how far it was to the destination city. Next, you checked the speedometer in your car. By dividing the speed into the distance, you got a pretty good estimate of the time it would take to get there.
Page 114 · Robotics with the Boe-Bot Enter, save, and run ForwardOneSecond.bs2. Place your Boe-Bot next to a ruler as shown in Figure 4-3. Make sure to line up the point where the wheel touches the ground with the 0 in/cm mark on the ruler.
Boe-Bot Navigation · Page 115 You can also think about the distance you just recorded as your Boe-Bot’s speed, in units per second. Let’s say that your Boe-Bot traveled 9 in (23 cm). Since it took one second for your Boe-Bot to travel that far, it means your Boe-Bot travels at around 9 in/s (23 cm/s). Now, you can figure out how many seconds your Boe-Bot has to travel to go a particular distance.
Page 116 · Robotics with the Boe-Bot 40 .65 pulses s 90.24 ... pulses 90 pulses pulses 2 .22 s The calculations in this example took two steps. First, figure out how long the servos have to run to make the Boe-Bot travel a certain distance, then figure out how many pulses it takes to make the servos run for that long. Since you know you have to multiply by 40.65 to get from run time to pulses, you can reduce this to one step. pulses Boe Bot dis tan ce 40.
Boe-Bot Navigation · Page 117 Modify BoeBotForwardOneSecond.bs2 so that it delivers the number of pulses you determined for your distance. Run the program and test to see how close you got. This technique has sources of error. The activity you just completed does not take into account the fact that it took a certain number of pulses for the Boe-Bot to get up to full speed. Nor did it take into account any distance the Boe-Bot might coast before it comes to a full stop.
Page 118 · Robotics with the Boe-Bot Recall from Chapter 2, Activity #5 that FOR…NEXT loops can also count downward from a higher number to a lower number. You can use this to ramp the speed back down again by using FOR pulseCount = 100 TO 1. Here is an example program that uses FOR…NEXT loops to ramp up to full speed, then ramp back down. Example Program: StartAndStopWithRamping.bs2 Enter, save, and run StartAndStopWithRamping.bs2.
Boe-Bot Navigation · Page 119 ' Ramp down from going forward to a full stop. FOR pulseCount = 100 TO 1 PULSOUT 13, 750 + pulseCount PULSOUT 12, 750 - pulseCount PAUSE 20 NEXT ' ' ' ' Loop ramps down for 100 pulses. Pulse = 1.5 ms + pulseCount. Pulse = 1.5 ms - pulseCount. Pause for 20 ms. END ' Stop until reset. Your Turn You can also create routines to combine ramping up or down with the other maneuvers. Here’s an example of how to ramp up to full speed going backward instead of forward.
Page 120 · Robotics with the Boe-Bot ' Ramp down right rotate FOR pulseCount = 30 TO 0 PULSOUT 13, 750 + pulseCount PULSOUT 12, 750 + pulseCount PAUSE 20 NEXT Open ForwardLeftRightBackward.bs2 from Activity #1, and save it as ForwardLeftRightBackwardRamping.bs2. Modify the new program so your Boe-Bot will ramp into and out of each maneuver. Hint: you might use the code snippets above, and similar snippets from StartAndStopWithRamping.bs2.
Boe-Bot Navigation · Page 121 your Debug Terminal. PAUSE 1000 causes a one second pause. Then, when the program gets to the RETURN command, arrow (2) shows how it jumps back to the command immediately after the GOSUB command. In this case, it’s a DEBUG command that displays the message “After subroutine.
Page 122 · Robotics with the Boe-Bot Here’s an example program that has two subroutines. One subroutine makes a highpitched tone while the other makes a low-pitched tone. The commands between DO and LOOP call each of the subroutines in turn. Try this program and note the effect. Example Program – TwoSubroutines.bs2 Enter, save, and run TwoSubroutines.bs2. ' Robotics with the Boe-Bot - TwoSubroutines.bs2 ' This program demonstrates that a subroutine is a reusable block of commands.
Boe-Bot Navigation · Page 123 ' ' ' ' Robotics with the Boe-Bot - MovementsWithSubroutines.bs2 Make forward, left, right, and backward movements in reusable subroutines. {$STAMP BS2} {$PBASIC 2.
Page 124 · Robotics with the Boe-Bot You should recognize the pattern of movement your Boe-Bot makes; it is the same one made by ForwardLeftRightBackward.bs2. Clearly there are many different ways to structure a program that will result in the same movements. A third approach is given in the example below. Example Program – MovementsWithVariablesAndOneSubroutine.
Boe-Bot Navigation · Page 125 counter pulseLeft pulseRight pulseCount VAR VAR VAR VAR Word Word Word Byte FREQOUT 4, 2000, 3000 ' Signal program start/reset.
Page 126 · Robotics with the Boe-Bot ACTIVITY #6: ADVANCED TOPIC—BUILDING COMPLEX MANEUVERS IN EEPROM When you download PBASIC program to your BASIC Stamp, the BASIC Stamp Editor converts your program to numeric values called tokens. These tokens are what the BASIC Stamp uses as instructions for executing the program. They are stored in one of the two smaller black chips on top of your BASIC Stamp.
Boe-Bot Navigation · Page 127 Figure 4-6 BASIC Stamp Editor Memory Map While we are here, note also that the counter variable we declared as a word is visible in Register 0 of the RAM Map. This program might have seemed large while you were typing it in, but it only takes up 136 of the available 2048 bytes of program memory. There currently is enough room for quite a long list of instructions. Since a character occupies a byte in memory, there is room for 1912 one-character direction instructions.
Page 128 · Robotics with the Boe-Bot Each of the basic maneuvers is given a single letter code that will correspond to its subroutine: F for Forward, B for Backward, L for Left_Turn, and R for Right_Turn. Complex Boe-Bot movements can be quickly choreographed by making a string of these code letters. The last letter in the string is a Q, which will mean “quit” when the movements are over.
Boe-Bot Navigation · Page 129 CASE "R": GOSUB Right_Turn CASE "L": GOSUB Left_Turn ENDSELECT Here are these concepts, all together in a single program. Example Program: EepromNavigation.bs2 Carefully read the code instructions and comments in EepromNavigation.bs2 to understand what each part of the program does. Enter, save, and run EepromNavigation.bs2. ' ' ' ' Robotics with the Boe-Bot - EepromNavigation.bs2 Navigate using characters stored in EEPROM. {$STAMP BS2} ' Stamp directive. {$PBASIC 2.
Page 130 · Robotics with the Boe-Bot END ' Stop executing until reset. ' -----[ Subroutine - Forward ]----------------------------------------------Forward: FOR pulseCount = 1 TO 64 PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT RETURN ' ' ' ' ' Forward subroutine. Send 64 forward pulses. 1.7 ms pulse to left servo. 1.3 ms pulse to right servo. Pause for 20 ms. ' Return to Main Routine loop.
Boe-Bot Navigation · Page 131 Your Turn With EepromNavigation.bs2 active in the BASIC Stamp Editor, click Run and select Memory Map. Your stored instructions will appear highlighted in blue at the beginning of the Detailed EEPROM Map as shown in Figure 4-7. The numbers shown are the hexadecimal ASCII codes that correspond to the characters you entered in your DATA statement.
Page 132 · Robotics with the Boe-Bot This program stored a total of 10 characters in EEPROM. These ten characters were accessed by the READ command’s address variable. The address variable was declared as a byte, so it can access up to 256 locations, well over the 10 we needed. If the address variable is re-declared to be a word variable, you could theoretically access up to 65535, far more locations than are available.
Boe-Bot Navigation · Page 133 ' addressOffset Pulses_Count DATA Pulses_Left DATA Pulses_Right DATA 0 Word 64, Word 850, Word 650, 2 Word 24, Word 650, Word 650, 4 Word 24, Word 850, Word 850, 6 8 Word 64, Word 0 Word 650 Word 850 Each of the three DATA statements begins with its own label. The Word modifier goes before each data item, and the items are separated by commas. These three strings of data will be stored in EEPROM one after another.
Page 134 · Robotics with the Boe-Bot Do you recognize the basic maneuver generated by this code block? Look at the other columns of the code snippet on page 133 and anticipate what the FOR…NEXT code block will look like on the second, third, and fourth times through the loop. Look at the LOOP UNTIL (pulseCount = 0) statement in the program below. The <> operator stands for “not equal to.” What will happen on the fifth time through the loop? Enter, save, and run EepromNavigationWithWordValues.bs2.
Boe-Bot Navigation · Page 135 FOR counter = 1 TO pulseCount PULSOUT 13, pulseLeft PULSOUT 12, pulseRight PAUSE 20 NEXT LOOP UNTIL (pulseCount = 0) END ' Stop executing until reset. Did your Boe-Bot perform the familiar forward-left-right-backwards movements? Are you thoroughly bored with it by now? Do you want to see your Boe-Bot do something else, or to choreograph your own routine? Your Turn – Making Your Own Custom Navigation Routines Save EepromNavigationWithWordValues.bs2. under a new name.
Page 136 · Robotics with the Boe-Bot SUMMARY This chapter introduced the basic Boe-Bot maneuvers: forward, backward, rotating in place to turn to the right or left, and pivoting. The type of maneuver is determined by the PULSOUT commands’ Duration arguments. How far the maneuver goes is determined by the FOR…NEXT loop’s StartValue and EndValue arguments. Chapter 2 included a hardware adjustment, physically centering the Boe-Bot’s servos with a screwdriver.
Boe-Bot Navigation · Page 137 by default, but adding the Word modifier to each data item allows you to store values up to 65535 in two bytes’ worth of EEPROM memory space. You can read values back out of EEPROM using the READ command. If you are retrieving a word-sized variable, make sure to place a Word modifier before the variable that will receive the value that READ fetches.
Page 138 · Robotics with the Boe-Bot Projects 1. It is time to fill in column 3 of Table 2-1 on page 63. To do this, modify the PULSOUT Duration arguments in the program BoeBotForwardThreeSeconds.bs2 using each pair of values from column 1. Record your Boe-Bot’s resultant behavior for each pair in column 3. Once completed, this table will serve as a reference guide when you design your own custom Boe-Bot maneuvers. 2. Figure 4-9 shows two simple courses.
Boe-Bot Navigation · Page 139 Q5. The FOR…NEXT loop's pulseCount variable can be used as an offset (plus or minus) to 750 (the center position) in the Duration argument. FOR pulseCount = 1 to 100 PULSOUT 13, 750 + pulseCount PULSOUT 12, 750 – pulseCount PAUSE 20 NEXT Q6. The DATA directive. Q7. The READ command Q8. SELECT...CASE...ENDSELECT. Q9. UNTIL and WHILE. E1. FOR counter = 1 to 350 ' Backward PULSOUT 13, 650 PULSOUT 12, 850 PAUSE 20 NEXT E2.
Page 140 · Robotics with the Boe-Bot FOR counter = 0 TO 30 ' Ramping pivot turn PULSOUT 13, 750 + counter PULSOUT 12, 750 PAUSE 20 NEXT FOR counter = 30 TO 0 PULSOUT 13, 750 + counter PULSOUT 12, 750 PAUSE 20 NEXT FOR counter = 1 to 100 PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT ' Forward P1.
Boe-Bot Navigation · Page 141 pulseCount VAR Word FREQOUT 4, 2000, 3000 ' Pulse count to servos ' Signal program start/reset. ' -----[ Main Routine ]-----------------------------------------------Main: DO PULSOUT 13, 850 ' Veer right PULSOUT 12, 716 PAUSE 20 LOOP To make the triangle, first calculate the number of pulses required for a one meter or yard straight line, as in Question 4. Then fine-tune your distances to match your Boe-Bot and particular surface.
Page 142 · Robotics with the Boe-Bot Right_Rotate120: FOR pulseCount = 1 TO 21 PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT RETURN ' Rotate right 120 degrees
Tactile Navigation with Whiskers · Page 143 Chapter 5: Tactile Navigation with Whiskers Many types of robotic machinery rely on a variety of tactile switches. For example, a tactile switch may detect when a robotic arm has encountered an object. The robot can be programmed to pick up the object and place it elsewhere. Factories use tactile switches to count objects on a production line, and also for aligning objects during industrial processes.
Page 144 · Robotics with the Boe-Bot Figure 5-1 Boe-Bot with Whiskers ACTIVITY #1: BUILDING AND TESTING THE WHISKERS Before moving on to programs that make the Boe-Bot navigate based on what it can touch, it’s essential to build and test the whiskers first. This activity will guide you through building and testing the whiskers. Whisker Circuit and Assembly Gather the whiskers hardware shown in Figure 5-2. Disconnect power from your board and servos.
Tactile Navigation with Whiskers · Page 145 Parts List (2) Whisker wires (2) 7/8″ pan head 4-40 Phillips screws (2) ½″ round spacer (2) Nylon washers, size #4 (2) 3-pin m/m headers (2) Resistors, 220 Ω (red-red-brown) (2) Resistors, 10 kΩ (brown-black-orange) Figure 5-2 Whiskers Hardware Building the Whiskers Remove the two front screws that hold your board to the front standoffs. Refer to Figure 5-3 while following the remaining instructions.
Page 146 · Robotics with the Boe-Bot The next step is add the whiskers circuit shown in Figure 5-4 to the piezospeaker and servo circuits you built and tested in Chapter 2 and Chapter 3. If you have a Board of Education, build the whiskers circuit shown in Figure 5-4 using the wiring diagram in Figure 5-5 on page 147 as a reference. If you have a HomeWork Board, build the whiskers circuit shown in Figure 5-4 using the wiring diagram in Figure 5-6 on page 148 as a reference.
Tactile Navigation with Whiskers · Page 147 Figure 5-5: Whisker Wiring Diagram for the Board of Education Left Whisker To Servos 15 14 Vdd 13 12 Red Black X4 Vdd X5 Vin Vss X3 P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0 X2 + Board of Education Rev C © 2000-2003 Right Whisker Use the 220 Ω resistors (red-red-brown color codes) to connect P5 and P7 to their corresponding 3-pin headers. Use the 10 kΩ resistors (brown-black-orange color codes) to connect Vdd to each 3-pin header.
Page 148 · Robotics with the Boe-Bot Figure 5-6: Whisker Wiring Diagram for the HomeWork Board Left Whisker To Servos (916) 624-8333 Rev B www.parallax.com www.stampsinclass.com Vdd Vin Vss X3 P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0 X2 + HomeWork Board Right Whisker Use the 220 Ω resistors (red-red-brown color codes) to connect P5 and P7 to their corresponding 3-pin headers. Use the 10 kΩ resistors (brown-black-orange color codes) to connect Vdd to each 3-pin header.
Tactile Navigation with Whiskers · Page 149 Testing the Whiskers Take a second look at the whiskers schematic (Figure 5-7). Each whisker is both the mechanical extension and the ground electrical connection of a normally open, singlepole, single-throw switch. The reason the whiskers are connected to ground (Vss) is because the plated holes at the outer edge of the board are all connected to Vss. This is true for both the Board of Education and the BASIC Stamp HomeWork Board.
Page 150 · Robotics with the Boe-Bot How do you get the BASIC Stamp to tell you whether it’s reading a 1 or 0? Because the circuit is connected to P7, this 1 or 0 value will appear in a variable named IN7. IN7 is called an input register. Input register variables are built-in and do not have to be declared in the beginning of your program. You can see the value this variable is storing by using the command DEBUG BIN1 IN7.
Tactile Navigation with Whiskers · Page 151 DEBUG "WHISKER STATES", CR, "Left Right", CR, "-----------" DO DEBUG CRSRXY, 0, 3, "P5 = ", BIN1 IN5, " P7 = ", BIN1 IN7 PAUSE 50 LOOP Note the values displayed in the Debug Terminal; it should display that both P7 and P5 are equal to 1. Check Figure 5-5 on page 147 (or Figure 5-6 on page 148) so you know which r is the “left whisker” and which is the “right whisker.
Page 152 · Robotics with the Boe-Bot ACTIVITY #2: FIELD TESTING THE WHISKERS Assume that you may have to test the whiskers at some later time away from a computer. Since the Debug Terminal won’t be available, what can you do? One solution would be to program the BASIC Stamp so that it sends an output signal that corresponds to the input signal it’s receiving. This can be done with a pair of LED circuits and a program that turns the LEDs on and off based on the whisker inputs.
Tactile Navigation with Whiskers · Page 153 Figure 5-10 Whisker Plus LED Wiring Diagram for the Board of Education Left Whisker To Servos 15 14 Vdd 13 12 This lead is the anode Red Black X4 Vdd X5 Vin Vss Flat spot on plastic case indicates cathode. X3 P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0 X2 + Board of Education Rev C © 2000-2003 This lead is the anode.
Page 154 · Robotics with the Boe-Bot Figure 5-11 Whisker Plus LED Wiring Diagram for the HomeWork Board Left Whisker To Servos (916) 624-8333 Rev B www.parallax.com www.stampsinclass.com Vdd Vin Vss X3 Connect P15 P14 the P13 anode P12 to the P11 P10 220 Ω P9 resistor. P8 P7 P6 P5 P4 P3 P2 P1 P0 + Flat spot on plastic case indicates cathode X2 HomeWork Board The anode connects to the 220 Ω resistor. Right Whisker Programming the LED Whisker Testing Circuits Reconnect power to your board.
Tactile Navigation with Whiskers · Page 155 IF (IN5 = 0) THEN HIGH 10 ELSE LOW 10 ENDIF These are called IF…THEN statements, and they will be more fully introduced in the next activity. These statements are used to make decisions in PBASIC. The first of the two IF…THEN statements sets P1 high, which turns the LED on when the whisker connected to P7 is pressed (IN7 = 0). The ELSE portion of the statement makes P1 go low, which turns the LED off when the whisker is not pressed.
Page 156 · Robotics with the Boe-Bot The “…” means you can place a code block (one or more commands) between the keywords. The next example program makes decisions based on the whisker inputs, and then calls subroutines to make the Boe-Bot take action. The subroutines are similar to the ones you developed in Chapter 4. Here is how IF…THEN is used.
Tactile Navigation with Whiskers · Page 157 ' -----[ Main Routine ]------------------------------------------------------DO IF (IN5 = 0) AND (IN7 = 0) THEN GOSUB Back_Up GOSUB Turn_Left GOSUB Turn_Left ELSEIF (IN5 = 0) THEN GOSUB Back_Up GOSUB Turn_Right ELSEIF (IN7 = 0) THEN GOSUB Back_Up GOSUB Turn_Left ELSE GOSUB Forward_Pulse ENDIF LOOP ' Both whiskers detect obstacle ' Back up & U-turn (left twice) ' Left whisker contacts ' Back up & turn right ' Right whisker contacts ' Back up & turn left ' Both w
Page 158 · Robotics with the Boe-Bot How Roaming with Whiskers Works The IF...THEN statements in the Main Routine section first check the whiskers for any states that require attention. If both whiskers are pressed (IN5 = 0 and IN7 = 0), a U-turn is executed by calling the Back_Up subroutine followed by calling the Turn_Left subroutine twice in a row. If just the left whisker is pressed (IN5 = 0), then the program calls the Back_Up subroutine followed by the Turn_Right subroutine.
Tactile Navigation with Whiskers · Page 159 Forward_Pulse, it gets to LOOP, which sends the program back up to DO. What happens then? The IF…THEN statement checks the whiskers all over again. Your Turn The FOR...NEXT loop EndValue arguments in the Back_Right and Back_Left routines can be adjusted for more or less turn, and the Back_Up routine can have its EndValue adjusted to back up less for navigation in tighter spaces. Experiment with the FOR...
Page 160 · Robotics with the Boe-Bot ACTIVITY #4: ARTIFICIAL INTELLIGENCE AND DECIDING WHEN YOU’RE STUCK You may have noticed that the Boe-Bot gets stuck in corners. As the Boe-Bot enters the corner, its whisker touches the wall on the left, so it turns right. When the Boe-Bot moves forward again, its right whisker bumps the wall on the right, so it turns left. Then it turns and bumps the left wall again, and the right wall again, and so on, until somebody rescues it from its predicament.
Tactile Navigation with Whiskers · Page 161 Enter, save, and run EscapingCorners.bs2. Test this program by pressing alternate whiskers as the Boe-Bot roams. Depending on which whisker you started with, the Boe-Bot should execute its UTurn maneuver after either the fourth or fifth consecutive whisker press. ' ' ' ' ' -----[ Title ]-------------------------------------------------------------Robotics with the Boe-Bot - EscapingCorners.
Page 162 · Robotics with the Boe-Bot ' --- Same navigation routine from RoamingWithWhiskers.
Tactile Navigation with Whiskers · Page 163 How EscapingCorners.bs2 Works Since this program is a modified version of RoamingWithWhiskers.bs2, only new features related to detecting and escaping corners are discussed here. Three extra variables are created for detecting a corner. The nibble variable counter can store a value between 0 and 15. Since our target value for detecting a corner is 4, the size of the variable is reasonable. Remember that a bit variable can store a single bit, either a 1 or a 0.
Page 164 · Robotics with the Boe-Bot IF (old7 <> IN7) AND (old5 <> IN5) THEN counter = counter + 1 old7 = IN7 old5 = IN5 If it turns out that this is the fourth consecutive whisker contact, then it’s time to reset counter to 1 and execute a U-turn. IF (counter > 4) THEN counter = 1 GOSUB Back_Up GOSUB Turn_Left GOSUB Turn_Left This ENDIF ends the code block that is executed if counter > 4. ENDIF This ELSE statement is connected to the IF (old7 <> IN7) AND (old5 <> IN5) THEN statement.
Tactile Navigation with Whiskers · Page 165 SUMMARY In this chapter, instead of navigating from a pre-programmed list, the Boe-Bot was programmed to navigate based on sensory inputs. The sensory inputs used in this chapter were whiskers, which served as normally open contact switches. When properly wired, these switches can show one voltage (5 V) at the switch’s contact point when it’s open and a different voltage (0 V) when it’s closed.
Page 166 · Robotics with the Boe-Bot Exercises 1. Write a DEBUG command for TestWhiskers.bs2 that updates each whisker state on a new line. Adjust the PAUSE command so that it is 250 instead of 50. 2. Using RoamingWithWhiskers.bs2 as a reference, write a Turn_Away subroutine that calls the Back_Up subroutine once and the Turn_Left subroutine twice. Write down the modifications you will have to make to the Main Routine section of RoamingWithWhiskers.bs2 Projects 1. Modify RoamingWithWhiskers.
Tactile Navigation with Whiskers · Page 167 ' ' ' ' Robotics with the Boe-Bot - TestWhiskers_UpdateEaOnNewLine.bs2 Update each whisker state on a new line. {$STAMP BS2} ' Stamp directive. {$PBASIC 2.5} ' PBASIC directive. DEBUG "WHISKER STATES", CR, "Left Right", CR, "-----------" DO DEBUG CRSRXY, 0, 3, "P5 = ", BIN1 IN5 DEBUG CRSRXY, 9, 3, "P7 = ", BIN1 IN7 PAUSE 250 LOOP ' Print in Column 0,Row 3 ' Print in Column 9,Row 3 ' Change from 50 to 250 E2.
Page 168 · Robotics with the Boe-Bot ELSEIF (IN7 = 0) THEN FREQOUT 4, 100, 4000 GOSUB Back_Up GOSUB Turn_Left ELSE GOSUB Forward_Pulse ENDIF LOOP ' Right whisker contacts ' 4 kHz beep for 100 ms ' Back up & turn left ' ' ' ' Both whiskers 1, no contacts Apply a forward pulse and check again P2. We found from Chapter 4 Projects that a 1 yard circle can be achieved with PULSOUT 13, 850 and PULSOUT 12, 716.
Light-Sensitive Navigation with Phototransistors · Page 169 Chapter 6: Light-Sensitive Navigation with Phototransistors Should I save this chapter for last? Many classes skip to Chapter 7 and 8, and then return here if time permits. Chapter 7 is the best “next step” after navigation with whiskers because it introduces a sensor that the Boe-Bot can use to detect obstacles without bumping into them. Chapter 8 uses that same sensor for distance detection and following objects.
Page 170 · Robotics with the Boe-Bot Figure 6-1 shows the schematic and part drawing of the phototransistor in your Boe-Bot Robot kit. The brightness of the light shining on the phototransistor’s base (B) terminal determines how much current it will allow to pass into its collector (C) terminal, and out through its emitter (E) terminal. Brighter light results in more current; less-bright light results in less current.
Light-Sensitive Navigation with Phototransistors · Page 171 Figure 6-2 Wavelengths and their Corresponding Colors For a better view, download a full-color PDF of this book from www.parallax.com/go/ Boe-Bot.
Page 172 · Robotics with the Boe-Bot If stopping under a bright light is your Boe-Bot’s only light-seeking task, there’s a simple circuit you can use that lets the BASIC Stamp know it detected bright light with a binary-1, or ambient light with a binary-0. Ambient According to Merriam Webster’s Dictionary, the word ambient means existing or present on all sides. For the light level in a room, think about ambient light as the overall level of brightness.
Light-Sensitive Navigation with Phototransistors · Page 173 Figure 6-4 Phototransistor Voltage Output Circuit Wiring Diagrams Board of Education (left); HomeWork Board (right) Flat Spot, Shorter Pin Flat Spot, Shorter Pin
Page 174 · Robotics with the Boe-Bot Example Program: TestBinaryPhototransistor.bs2 This program should make the Debug Terminal display a value of 0 in a room with fluorescent lights, and no direct sunlight. When you shine a bright light on the phototransistor, the program should display a value of 1. Figure 6-5 shows an example. Figure 6-5: Debug Terminal Displays TestBinaryPhototransistor.
Light-Sensitive Navigation with Phototransistors · Page 175 ' Robotics with the Boe-Bot - TestBinaryPhototransistor.bs2 ' Display 1 when the phototransistor circuit applies more than 1.4 V to P6 ' or 0 when it applies less than 1.4 V. ' {$STAMP BS2} ' {$PBASIC 2.5} PAUSE 1000 DEBUG CLS DO DEBUG HOME, "IN6 = ", BIN IN6 PAUSE 100 LOOP Your Turn – Make the Boe-Bot Halt Under the Bright Light HaltUnderBrightLight.
Page 176 · Robotics with the Boe-Bot Advanced Topic: How the Phototransistor Voltage Output Circuit Works The phototransistor circuit you built applies a voltage to I/O pin P6. The voltage labeled VP6 in Figure 6-6 is the voltage output that the circuit applies to the I/O pin. This voltage increases with more light and decreases with less light. Since P6 is set to input, this voltage causes IN6 to store a binary-1 or a binary-0. If the voltage is above 1.4 V, IN6 stores a binary-1; if it’s below 1.
Light-Sensitive Navigation with Phototransistors · Page 177 The reason the voltage at P6 changes with light is because the phototransistor lets more current pass with more light, or less current pass with less light. That current, which is labeled I in Figure 6-6, also has to pass though the resistor. When more current passes through a resistor, the voltage across it will be higher. When less current passes, the voltage will be lower.
Page 178 · Robotics with the Boe-Bot Let’s use Ohm’s Law to calculate VP6 in with the phototransistor letting two different amounts of current flow through the circuit: 1.75 mA, which might happen as a result of fairly bright light, and 0.25 mA, which would happen with less bright light. Figure 6-8 shows the conditions and their solutions. When you try these calculations, make sure to remember that milli (m) is thousandths and kilo (k) is thousands when you substitute the numbers into Ohm’s Law.
Light-Sensitive Navigation with Phototransistors · Page 179 Your Turn – Ohm’s Law and Resistor Adjustments Let’s say that the light in your room is twice as bright as the one in the room that resulted in Vo = 3.5 V for bright light and 0.5 V for shade. Another situation that could cause higher current is if the light is a stronger source of infrared. In either case, the phototransistor could allow twice as much current to flow through the circuit, which could lead to measurement difficulties.
Page 180 · Robotics with the Boe-Bot Parts List In this activity, you will need two phototransistors and two 0.1 μF capacitors. Figure 6-8 shows drawings of both. Look carefully at Figure 6-8 and make note of the difference between a phototransistor and an infrared LED. Phototransistor Flatter on top 0.1 μF Capacitor Schematic Symbol and Part Drawing Infrared LED More Rounded Dome Figure 6-8 Distinguishing Phototransistors from Infrared LEDs; Identifying the 0.
Light-Sensitive Navigation with Phototransistors · Page 181 Common capacitance measurements are: Microfarads: Nanofarads: Picofarads: (millionths of a farad), abbreviated μF (billionths of a farad), abbreviated nF (trillionths of a farad), abbreviated pF -6 1 μF = 1×10 F -9 1 nF = 1×10 F -12 1 pF = 1×10 F The 104 on the 0.1 μF capacitor’s case is a measurement picofarads or (pF). In this labeling system, 104 is the number 10 with four zeros added, so the capacitor is 100,000 pF, which is 0.1 μF.
Page 182 · Robotics with the Boe-Bot Figure 6-9: Analog Phototransistor Circuit Schematics and Wiring Diagram Flat Spots, Shorter Pins Flat Spots, Shorter Pins The roaming examples in this chapter will depend on the phototransistors being pointed upward and outward to detect differences in incident light levels from different directions. Make sure your phototransistors are pointing upward and outward as shown in Figure 6-10.
Light-Sensitive Navigation with Phototransistors · Page 183 Figure 6-10: Point the Phototransistors Upward and Outward About Charge Transfer and the Phototransistor Circuit Each phototransistor/capacitor circuit is called a charge transfer circuit. The BASIC Stamp will measure the rate at which each capacitor loses its charge through its phototransistor by measuring how long it takes the capacitor’s voltage to decay.
Page 184 · Robotics with the Boe-Bot Connected in Parallel The phototransistor and capacitor shown in Figure 6-11 are connected in parallel. For two components to be connected in parallel, each of their leads must be connected to common terminals (also called nodes). The phototransistor and the capacitor each have one lead connected to Vss. They also each have one lead connected to the same 1 kΩ resistor lead. So, they are connected in parallel.
Light-Sensitive Navigation with Phototransistors · Page 185 If the State argument is set to 1, RCTIME will wait for it to change to 0 indicating that the voltage decayed down to 1.4 V. If State is set to 0, RCTIME will wait for the voltage to rise to 1.4 V. In either case, the command stores the time measurement result in the Variable argument, which is typically a word variable.
Page 186 · Robotics with the Boe-Bot Is tLeft stuck at 0 or 1? A 0 could mean it’s way too dark, and a 1 could mean it’s way too bright. Either one could also indicate a wiring error, so double check your circuits too. These sensor circuits are designed for indoor lighting. Make sure no direct sunlight is shining in through the windows. If there is, close the blinds. Enter and run TestP6LightSense.bs2. Make a note of the value displayed in the Debug Terminal.
Light-Sensitive Navigation with Phototransistors · Page 187 Your Turn – Test the Other Phototransistor Circuit The Boe-Bot robot’s other phototransistor circuit is connected to P3. Before modifying your program to test the other circuit, it’s always best to save the working program as-is first. Save TestP6LightSense.bs2, then save a copy as TestP3LightSense.bs2. Change the Pin argument from 6 to 3 in the HIGH and RCTIME commands.
Page 188 · Robotics with the Boe-Bot Figure 6-13: Oscilloscope View of Decay Times HIGH 6 RCTIME 6, 1, tLeft PAUSE 1 tLeft ≈5V 1.4 V 0V PAUSE 1 HIGH 3 tRight RCTIME 3, 1, tRight ≈5V 1.4 V 0V The upper trace in Figure 6-13 plots the capacitor’s voltage in the QT circuit connected to P6; that’s the Boe-Bot’s left light sensor circuit. In response to HIGH 6, the voltage rises from 0 V to almost 5 V between about 0.5 ms and 1 ms. The signal stays at around 5 V for the duration of PAUSE 1.
Light-Sensitive Navigation with Phototransistors · Page 189 ACTIVITY #3: LIGHT SENSITIVITY ADJUSTMENT If these RCTIME light measurements are going to be used while the Boe-Bot is roaming, they will have to share the BASIC Stamp’s processing time with PULSOUT commands for servo control. There’s a 20 ms time window between each pair of PULSOUT commands for RCTIME commands.
Page 190 · Robotics with the Boe-Bot PWM stands for Pulse Width Modulation. In Chapter 2, you studied pulse width modulation for servo control using PULSOUT. The PWM command makes the BASIC Stamp create another form of pulse width modulation. This signal is a more rapid sequence of pulses that’s especially useful for setting voltage across a capacitor through a resistor. The proportion of high time to cycle time (high + low time) is what controls the capacitor voltage, and it is called duty cycle.
Light-Sensitive Navigation with Phototransistors · Page 191 Let’s start by reducing the decay times to half of the values you measured in the previous activity. In practice, your program will need to reduce it by more to navigate in lower light levels, but this shows the first step in getting there. To reduce decay times by ½, you’ll have to use the PWM command to charge the capacitors to half way between 1.4 V and 5 V.
Page 192 · Robotics with the Boe-Bot One Light Sensor, Two Different Measurements HighVsPwmInRctime.bs2 demonstrates how the decay measurement for the sensor takes less time when PWM charges it to a lower value. Enter and run HighVsPwmInRctime.bs2, and observe the two measurements of the same light level in the Debug Terminal. Try varying the light level, the tRight2 measurement should always be significantly smaller than tRight1. ' ' ' ' Robotics with the Boe-Bot - HighVsPwmInRctime.
Light-Sensitive Navigation with Phototransistors · Page 193 Figure 6-14: Debug Terminal and Oscilloscope Views of HighVsPwmInRctime.bs2 tRight1 = 1345 tRight2 = 264 ≈5V ≈ 2.5 V 1.4 V 0V th th Why is tRight2 more like 1/5 of tRight1? Isn’t it supposed to be 1/4 ? In the first decay, the I/O pin was output-high right up until the time RCTIME changes it to input.
Page 194 · Robotics with the Boe-Bot of HIGH and PAUSE, with a Duty of 80, and test to find out how much darker it can get before the servo stop functioning properly. Run TestMaxDarkWithHighPause.bs2. Gradually increase the shade until the servos start twitching. (A shoebox would work well for this.) Repeat with TestMaxDarkWithPwm.bs2. The servos should still start twitching at some point, but it should be darker before it happens.
Light-Sensitive Navigation with Phototransistors · Page 195 The Boe-Bot will be able to use this information for tasks like navigating toward or away from light. The first example program looks pretty long, but don’t worry. You’ll be downloading it from www.parallax.com/go/Boe-Bot instead of hand-entering it. Test LightSensorValues.bs2 LightSensorValues.bs2 utilizes several subroutines that condense the light measurements into two values: light, and ndShade.
Page 196 · Robotics with the Boe-Bot sensor. The value of ndShade is -279, which indicates shade over the left sensor, and the light value has dropped because shade over one sensor also reduces the total light measurement. Figure 6-16: Example Shadow Tests with LightSeekingDisplay.bs2 Facing a Light Source Shade over Boe-Bot’s Left Light Sensor Download LightSensorExamples.zip from www.parallax.com/go/Boe-Bot. Make sure there is no direct sunlight streaming in nearby windows.
Light-Sensitive Navigation with Phototransistors · Page 197 '-----[ Title ]--------------------------------------------------------------' Robotics with the Boe-Bot - LightSensorValues.bs2 ' Displays conditioned ambient light level and differential shade on a scale ' of -500 to 500. ' {$STAMP BS2} ' {$PBASIC 2.5} ' Stamp directive. ' PBASIC directive.
Page 198 · Robotics with the Boe-Bot ' ' (-500 -> dark shade over left, 0 -> equal shade, +500 -> dark shade over right) Light_Shade_Info: GOSUB Light_Sensors sumdiff = (tLeft + tRight) MAX 65535 IF duty <= 70 THEN light=duty-(sumdiff/905) MIN 1 IF sumdiff = 0 THEN light = 0 ELSEIF duty = 255 THEN light=duty+((1800-(sumdiff))/26) ELSE light = duty ENDIF GOSUB Duty_Auto_Adjust n = tLeft d = tLeft + tRight GOSUB Fraction_Thousandths ndShade = 500-q RETURN ' ' ' ' ' ' ' ' ' ' ' ' ' Subroutine label Get ra
Light-Sensitive Navigation with Phototransistors · Page 199 '-----[ Subroutine - Fraction_Thousandths ]----------------------------------' Calculate q = n/d as a number of thousandths. ' n and d should be unsigned and n < d. Requires Nib size temp & i variables.
Page 200 · Robotics with the Boe-Bot measurements. The program has a subroutine named Duty_Auto_Adjust that automatically adjusts the duty variable to help prevent rooms that are too dark from disabling the Boe-Bot’s servos and rooms that are bright from blinding the light sensors. After calling the Light_Sensors subroutine, the Light_Shade_Info subroutine does some math on tLeft, tRight, and the duty variable to calculate the light variable’s value, which again indicates the overall light level.
Light-Sensitive Navigation with Phototransistors · Page 201 Negative constant instead. So, down in the Duty_Auto_Adjust subroutine, the statement IF sign=Negative THEN sumDiff = -sumDiff checks to find out if the sign variable contains a 1, indicating that a value tested as negative earlier in the subroutine. This line would still work if it was rewritten IF sign=1 THEN sumDiff = -sumDiff.
Page 202 · Robotics with the Boe-Bot All you need for this display is some small modifications to LightSensorValues.bs2’s Initialization and Main Routine sections. Below is an example. It makes use of some new DEBUG formatters, like REP and CRSRX. The REP formatter repeats a character a certain number of times. So DEBUG CLS, REP CR\5 clears the screen, and then prints 5 carriage returns, which sends the cursor down 5 lines.
Light-Sensitive Navigation with Phototransistors · Page 203 LightSensorDisplay.bs2 was another example in LightSensorExamples.zip. Open it with the BASIC Stamp Editor. If you would prefer to save LightSensorValues.bs2 as LightSensorDisplay.bs2 and hand enter the changes, make sure to leave five spaces between the quotation marks and the first characters in each scale.
Page 204 · Robotics with the Boe-Bot The routine that sets pulseLeft and pulseRight values starts by deciding if the shade is over the right or left sensor, by comparing (ndShade + 500) to 500. The > (greater than), >= (greater than or equal to), < (less than), and <= (less than or equal to) operators only compare two positive numbers. Since the smallest ndShade could be is -500, the code in the IF condition adds 500 to ndShade and then compares it to 500. It’s the PBASIC equivalent to IF ndShade > 0.
Light-Sensitive Navigation with Phototransistors · Page 205 If ndShade is larger, like maybe 190, which means the shade over the right sensor is darker, pulseLeft ends up with a value of 710, which would make the left wheel turn backwards for a much sharper turn. For values of ndShade that are greater than 250, the expression 900 - ndShade might result in values smaller than 650. Likewise, for values of ndShade between 1 and 49, the expression might result in values above 850.
Page 206 · Robotics with the Boe-Bot Test Navigation Routine with Debug Terminal Figure 6-19 shows some Debug Terminal display examples from the next example program, LightSeekingDisplay.bs2. Checklist instructions will prompt you to run the program next, but first, just take a look at the Debug Terminal displays in the figure. These screen captures demonstrate how the navigation routine adjusts the pulseLeft and pulseRight variables in response to different ndShade values.
Light-Sensitive Navigation with Phototransistors · Page 207 Figure 6-19: Shade and Wheel Speed Indicator Examples Equal light – full speed forward Left speed indicator Shade over left – slow down right wheel Right speed indicator Right wheel stopped Dark shade over right – left wheel full speed reverse Left wheel full speed reverse Equal shade – back to full speed forward
Page 208 · Robotics with the Boe-Bot LightSeekingDisplay.bs2 is another example from the LightSensorExamples.zip archive. It expands on LightSensorDisplay.bs2 with these features: Word-size variable declarations for pulseLeft and pulseRight A DEBUG command that displays a top view of the Boe-Bot The light seeking routine IF…THEN…ELSE…ENDIF code block Debug commands that display the pulseLeft and pulseRight variable values next to each wheel.
Light-Sensitive Navigation with Phototransistors · Page 209 '-----[ Initialization ]-----------------------------------------------------FREQOUT 4, 2000, 3000 ' Start beep DEBUG CLS, REP CR\5, " -+---------+---------+-", ' Shade level graphical view CR, " -500 500", CR, " Boe-Bot forward", CR, " --------", ' Boe-Bot top view with pulse CR, " || |[] ---- | || ", ' labels CR, " || |[]| -- | | || ", CR, "pulse ||=| ---- |=|| pulse ", CR, "Left || | ==== | || Right ", CR, " || ||| ___ | || ", CR, " ||| |___| |
Page 210 · Robotics with the Boe-Bot LightSeekingDisplay.bs2 utilizes another DEBUG formatter, CRSRXY, to position the cursor to display each wheel speed indicator. CRXRXY should be followed by two numbers. For example, DEBUG CRXRXY, 6, 11, ">" would display the > character at six spaces from the Debug Terminal’s left margin, and 11 carriage returns down from the top. The program actually uses an expression to set the number of carriage returns for positioning the cursor.
Light-Sensitive Navigation with Phototransistors · Page 211 and pulseRight. So tLeft can be declared as an alias of pulseLeft and tRight can be declared as an alias for pulseRight. Now, pulseLeft and tLeft use the same piece of memory, and likewise with pulseRight and tRight, and your application just recovered two words of RAM. With the modifications in LightSeekingDisplayBetterRAM.bs2, the program reduces RAM usage from “almost all” to “less than half.
Page 212 · Robotics with the Boe-Bot Figure 6-21 Saving Space with Variable Aliases ' Application Variables pulseLeft VAR Word pulseRight VAR Word light VAR Word ndShade VAR Word ' Application Variables pulseLeft VAR Word pulseRight VAR Word light VAR Word ndShade VAR Word ' Subroutine Variables tLeft VAR Word tRight VAR Word n VAR Word d VAR Word q VAR Word sumDiff VAR Word duty VAR Byte i VAR Nib temp VAR Nib sign VAR Bit ' Subroutine Variables tLeft VAR pulseLeft tRight VAR pulseRight n VAR tLeft d V
Light-Sensitive Navigation with Phototransistors · Page 213 '-----[ Initialization ]-----------------------------------------------------FREQOUT 4, 2000, 3000 ' Start beep DEBUG "Program running..." ' Display program running message '-----[ Main Routine ]-------------------------------------------------------DO ' Main Loop. GOSUB Light_Shade_Info ' Get light & ndShade ' Navigation Routine IF (ndShade + 500) > 500 THEN ' If more shade on right...
Page 214 · Robotics with the Boe-Bot Troubleshooting If the Boe-Bot robot seems a little less sensitive to light on one side, try correcting it by following the instructions in the next section (Your Turn – Light/Shade Sensitivity Adjustments). The same applies if you want to the Boe-Bot to either be more or less sensitive to shade.
Light-Sensitive Navigation with Phototransistors · Page 215 Your Turn – Light/Shade Sensitivity Adjustments You can change the 900 and 600 in these lines to make the Boe-Bot more or less sensitive to shade: pulseLeft = 900 - ndShade MIN 650 MAX 850 ...and: pulseRight= 600 - ndShade MIN 650 MAX 850 For example, you can increase the Boe-Bot’s light/shade sensitivity by changing 900 to 875 and changing 600 to 625. You can make it even more sensitive by changing the 900 to 850 and the 600 to 650.
Page 216 · Robotics with the Boe-Bot SUMMARY A phototransistor is a light–controlled current valve. It lets more current through with brighter incident light and less current through with less bright light. This chapter utilized two different phototransistor circuits to detect light: a voltage output circuit and a charge transfer circuit. The phototransistor voltage output circuit in this chapter was connected to an I/O pin set to input for a binary value that indicated bright or ambient light.
Light-Sensitive Navigation with Phototransistors · Page 217 Activity #4 through Activity #6 utilize a collection of subroutines that supply the Main Routine with values of overall light levels along with the light/shade contrast between the two sensors. This light/shade contrast between the sensors is called a differential measurement, and the subroutines also normalize the measurement to a scale of -500 to 500.
Page 218 · Robotics with the Boe-Bot 9. Write a DEBUG command that positions the character “#” eight spaces to the right of the Debug Terminal’s left margin and 10 carriage returns down from the top. Projects 1. In Activity #1, the circuit along with the example code in the Your Turn section made the Boe-Bot stop under a light at the end of the course.
Light-Sensitive Navigation with Phototransistors · Page 219 E2. V = I × R → I = V ÷ R = 4.5 ÷ 2000 = 0.00225 A = 2.25 mA. E3. The BASIC Stamp’s threshold voltage is 1.4 V, but the light threshold occurs at 2.8 V. So, the phototransistor delivers a certain current that results in a 2.8 V measurement, in terms of V = I × R, that’s 2.8 V = I × 2000 Ω. We need to figure out the resistance to make the voltage 1.4 V for that same current, that’s 1.4 V = I × R.
Page 220 · Robotics with the Boe-Bot For lower light areas and weaker flashlights, you may need to adjust IF light > 320 THEN... so that it compares the light variable to a lower value, for example: IF light > 250 THEN… Decreasing the value the IF…THEN statement compares to the light variable to makes it more sensitive; increasing it makes it less sensitive. The value 324 is the highest possible value so don’t increase your comparison value above 323. TIP: Use LightSensorValues.
Navigating with Infrared Headlights · Page 221 Chapter 7: Navigating with Infrared Headlights The Boe-Bot can already use whiskers to get around objects it detects when it bumps into them, but wouldn’t it be better if the Boe-Bot could just “see” objects and then decide what to do about them? Well, that’s exactly what the Boe-Bot can do with infrared headlights and eyes like the ones in Figure 7-1.
Page 222 · Robotics with the Boe-Bot Figure 7-2: IR LED and Receiver in Your Home IR on/off at ≈38 kHz for certain periods of time IR Receiver IR LED Note that the TV remote sends messages describing which button you press by rapidly flashing its IR LED on/off at a rate in the 38 kHz neighborhood. That’s around 38,000 times per second. The IR receiver only responds to infrared if it’s flashing on/off at this rate.
Navigating with Infrared Headlights · Page 223 and hold a button on the remote and point its IR LED into the digital camera’s lens, it displays the infrared LED as a flashing, bright white light. Figure 7-3: IR LED in a TV Remote Viewed through a Digital Camera With a button pressed and held, the IR LED doesn’t look any different. Through a digital camera display, the IR LED appears as a flashing, bright white light.
Page 224 · Robotics with the Boe-Bot Parts List: Figure 7-4 New Parts Used in this Chapter (2) (2) (2) (2) IR receivers IR LEDs (clear case) IR LED shield assemblies Resistors, 220 Ω (red-red-brown) (2) Resistors, 1 kΩ (brown-black-red) IR receiver (top) IR LED (middle) IR LED shield assembly (bottom) Check Figure 7-5 to make sure you have selected infrared LEDs and not phototransistors. The infrared LED has a taller and more rounded plastic dome, and is shown on the right side of Figure 7-5.
Navigating with Infrared Headlights · Page 225 IR LED will snap in. + Figure 7-6 Snapping the IR LED into the Shield Assembly - IR Object Detection Circuit Figure 7-7 shows the IR object detection circuit schematic and Figure 7-8 shows a wiring diagram of the circuit. In the wiring diagram, one IR object detector (IR LED and receiver) is mounted on each corner of the breadboard closest to the very front of the Boe-Bot. Disconnect power from your board and servos.
Page 226 · Robotics with the Boe-Bot Watch your IR LED anodes and cathodes! The anode lead is the longer lead on an IR LED by convention. The cathode lead is shorter and mounted in the plastic case closer to its flat spot. The same conventions applied to the red LEDs in Chapter 2. In Figure 7-8, the anode lead of each IR LED connects to a 1 kΩ resistor. The cathode lead plugs into the same breadboard row as an IR detector’s center pin, and that row is connected to Vss with a jumper wire.
Navigating with Infrared Headlights · Page 227 It takes two lines of code to test for the presence or absence of an object using an IR object detection circuit. Here is an example that tests to find out if an object is in front of the Boe-Bot robot’s left IR detection circuit. FREQOUT 8, 1, 38500 irDetectLeft = IN9 The command FREQOUT 8, 1, 38500 makes the IR LED’s brightness vary, getting brighter and dimmer 38500 times per second.
Page 228 · Robotics with the Boe-Bot Leave the Boe-Bot connected to its programming cable, because you will be using the Debug Terminal to test your IR object detector. Place an object, such as your hand or a sheet of paper, about an inch from the left IR object detector, in the manner shown in Figure 7-1 on page 221. Verify that the Debug Terminal displays a 0 when you place an object a few inches in front of the IR object detector. Verify that it displays 1 when you remove the object.
Navigating with Infrared Headlights · Page 229 Your Turn – Test the Right IR Object Detector Save TestLeftIr.bs2 as TestRightIr.bs2. Change the DEBUG command, program title and comments to refer to the right IR object detector. Change the variable name from irDetectLeft to irDetectRight. You will need to do this in four places in the program. Change the FREQOUT command’s Pin argument from 8 to 2. Change the input register monitored by the irDetectRight variable from IN9 to IN0.
Page 230 · Robotics with the Boe-Bot ACTIVITY #2: FIELD TESTING FOR OBJECT DETECTION AND INFRARED INTERFERENCE In this activity, you will build and test indicator LEDs that will tell you if an object is detected without the help of the Debug Terminal. This is handy if you are not near a PC or laptop, and you need to trouble-shoot your IR detector circuits. You will also write a program to “sniff” for infrared interference from fluorescent lights.
Navigating with Infrared Headlights · Page 231 Figure 7-10: Wiring Diagrams for Infrared Emitter and Receiver Circuits To Servos To Servos 15 14 Vdd 13 12 anode lead (916) 624-8333 Rev B www.parallax.com www.stampsinclass.
Page 232 · Robotics with the Boe-Bot Verify that the LED next to each detector emits light when the detector detects an object. If one or both of the LEDs appear not to work, check your wiring and your program. ' Robotics with the Boe-Bot - TestBothIrAndIndicators.bs2 ' Test IR object detection circuits. ' {$STAMP BS2} ' {$PBASIC 2.5} ' Stamp directive. ' PBASIC directive.
Navigating with Infrared Headlights · Page 233 Your Turn – Remote Testing and Range Testing You can now use your LED detectors to take your Boe-Bot and test your IR detectors on objects that might not otherwise be in reach of your computer’s programming cable. Unplug your Boe-Bot from the programming cable, and take your Boe-Bot to a variety of objects and test the range of the IR detectors. Try the detection range of different colored objects.
Page 234 · Robotics with the Boe-Bot ' Robotics with the Boe-Bot – IrInterferenceSniffer.bs2 ' Test fluorescent lights, infrared remotes, and other sources ' of 38.5 kHz IR interference. ' {$STAMP BS2} ' {$PBASIC 2.5} counter ' Stamp directive. ' PBASIC directive. VAR Nib DEBUG "IR interference not detected, yet...
Navigating with Infrared Headlights · Page 235 Parts List: You will need some extra parts for this activity. (2) (2) (2) (2) Resistors, 470 Ω (yellow-violet-brown) Resistors, 220 Ω (red-red-brown) Resistors, 2 kΩ (red-black-red) Resistors, 4.7 kΩ (yellow-violet-red) Series Resistance and LED Brightness First, let’s use one of the red LEDs to “see” the difference that a resistor makes in how brightly an LED glows. All we need to test the LED is a program that sends a high signal to the LED.
Page 236 · Robotics with the Boe-Bot Replace the 220 Ω resistor connected to P1 and the right LED’s cathode with a 470 Ω resistor. Note now how brightly the LED glows. Repeat for a 2 kΩ resistor. Repeat once more with a 4.7 kΩ resistor. Replace the 4.7 kΩ resistor with the 220 Ω resistor before moving on to the next portion of this activity. Explain in your own words the relationship between LED brightness and series resistance.
Navigating with Infrared Headlights · Page 237 Also, before moving on, make sure to test this last change with TestBothIrAndIndicators.bs2 to verify that both IR object detectors are working properly. ACTIVITY #4: OBJECT DETECTION AND AVOIDANCE An interesting thing about the IR detectors is that their outputs are just like the whiskers. When no object is detected, the output is high; when an object is detected, the output is low. In this activity, RoamingWithWhiskers.
Page 238 · Robotics with the Boe-Bot Example Program – RoamingWithIr.bs2 ' ' ' ' ' Open RoamingWithWhiskers.bs2 Modify it so that it matches the program below. Reconnect power to your board and servos. Save and run it. Verify that, aside from the fact that there’s no contact required, it behaves like RoamingWithWhiskers.bs2. -----[ Title ]-------------------------------------------------------------Robotics with the Boe-Bot - RoamingWithIr.bs2 Adapt RoamingWithWhiskers.
Navigating with Infrared Headlights · Page 239 ' -----[ Subroutines ]-------------------------------------------------------Forward_Pulse: PULSOUT 13,850 PULSOUT 12,650 PAUSE 20 RETURN ' Send a single forward pulse. Turn_Left: FOR pulseCount = 0 TO 20 PULSOUT 13, 650 PULSOUT 12, 650 PAUSE 20 NEXT RETURN ' Left turn, about 90-degrees.
Page 240 · Robotics with the Boe-Bot Sampling Between Every Pulse to Avoid Collisions The great thing about detecting an obstacle before bumping into it is that it gives the BoeBot some room to navigate around it. The Boe-Bot can apply a pulse to turn away from an object, check again and if the object is still there, apply another pulse to avoid it. The Boe-Bot can keep applying pulses and checking, until it steers clear of the obstacle. Then, it can resume forward pulses.
Navigating with Infrared Headlights · Page 241 PULSOUT 13,pulseLeft PULSOUT 12,pulseRight PAUSE 15 ' Apply the pulse. LOOP ' Repeat Main Routine How FastIrRoaming.bs2 Works This program takes a slightly different approach to applying pulses. Aside from the two bits used to store the IR detector outputs, it uses two word variables to set the pulse durations delivered by the PULSOUT command.
Page 242 · Robotics with the Boe-Bot Before the DO…LOOP repeats, the last thing to do is to deliver pulses to the servos. Notice that the PAUSE command is no longer 20. Instead, it’s 15 since roughly 5 ms is taken checking the IR LEDs. PULSOUT 13,pulseLeft PULSOUT 12,pulseRight PAUSE 15 ' Apply the pulse. Your Turn Save FastIrRoaming.bs2 as FastIrRoamingYourTurn.bs2. Use the LEDs to broadcast that the Boe-Bot has detected an object.
Navigating with Infrared Headlights · Page 243 Disconnect power from your board and servos. Point your IR object detectors downward and outward as shown in Figure 7-11. Recommended Materials: (1) Roll of black vinyl electrical tape, ¾″ (19 mm) wide. (1) Sheet of white poster board, 22 x 28 in (56 x 71 cm).
Page 244 · Robotics with the Boe-Bot 22” (56 cm) 22” (56 cm) Figure 7-12 Electrical Tape Outline Simulates Tabletop Edge If you try a tabletop after success with the electrical tape course: Remember to follow the same steps you followed before running the Boe-Bot in the electrical tape delimited course! Make sure to be the spotter for your Boe-Bot.
Navigating with Infrared Headlights · Page 245 detectors, but as soon as a drop-off is detected, you may want your Boe-Bot to take several pulses worth of turn before checking the detectors again. Just because you are taking multiple pulses in an evasive maneuver, it doesn’t mean you have to return to whiskers-style navigation. Instead, you can add a pulseCount variable that you can use to set to the number of pulses to deliver for a maneuver.
Page 246 · Robotics with the Boe-Bot DO ' Main Routine. FREQOUT 8, 1, 38500 irDetectLeft = IN9 FREQOUT 2, 1, 38500 irDetectRight = IN0 ' Check IR detectors. ' Decide navigation. IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN pulseCount = 1 ' Both detected, pulseLeft = 850 ' one pulse forward. pulseRight = 650 ELSEIF (irDetectRight = 1) THEN ' Right not detected, pulseCount = 10 ' 10 pulses left.
Navigating with Infrared Headlights · Page 247 The IF…THEN statements now set the value of pulseCount as well as pulseRight and pulseLeft. If both detectors can see the table, take one cautious pulse forward. IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN pulseCount = 1 pulseLeft = 850 pulseRight = 650 Else, if the right IR detector does not see the tabletop, rotate left 10 pulses.
Page 248 · Robotics with the Boe-Bot may actually track the edge of the electrical tape delimited course. Pivoting backward instead of rotating in place may also lead to some interesting behaviors. Modify AvoidTableEdge.bs2 so that it follows the edge of the electrical tape delimited course by adjusting the pulseCount values so that the Boe-Bot doesn’t turn too far away from the edge. Experiment with pivoting as a way to make the Boe-Bot roam inside the perimeter instead of following the edge.
Navigating with Infrared Headlights · Page 249 3. What does it mean if the IR detector sends a low signal? What does it mean when the detector sends a high signal? 4. What happens if you change the value of a resistor in series with a red LED? What happens if you change the value of a resistor in series with an infrared LED?? Exercises 1. Modify a line of code in IrInterferenceSniffer.bs2 so that it only monitors one of the IR detectors. 2. Explain the function of pulseCount in AvoidTableEdge.bs2.
Page 250 · Robotics with the Boe-Bot E2. The program sets this variable to 1 when it’s taking a forward pulse. That way, as the Boe-Bot moves forward, it checks for a drop-off between each pulse. When it detects a drop-off, it executes a turn for a certain number of pulses, which is also determined by the value of the pulseCount variable. P1. The FastIrRoaming.bs2 program can be combined with a DO…LOOP UNTIL loop that does nothing until it detects an object. A sample solution is shown below.
Navigating with Infrared Headlights · Page 251 ENDIF PULSOUT 13, pulseLeft PULSOUT 12, pulseRight PAUSE 15 GOSUB Check_IRs LOOP ' Apply the pulse. ' Check IRs again ' -----[ Subroutines ] -----------------------------------------------Check_IRs: FREQOUT 8, 1, 38500 irDetectLeft = IN9 FREQOUT 2, 1, 38500 IrDetectRight = IN0 RETURN ' Check IR Detectors P2. This behavior is in many ways the opposite of the roaming behavior covered in this chapter.
Page 252 · Robotics with the Boe-Bot DO PULSOUT 13, 790 ' Rotate slowly PULSOUT 12, 790 PAUSE 15 ' 5 ms for detectors GOSUB Check_IRs ' While looking for object LOOP UNTIL (irDetectLeft = 0) OR (irDetectRight = 0) ' Now figure out exactly where the object is and go toward it DO ' Object in both detectors -- go forward IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN pulseLeft = 850 ' Forward pulseRight = 650 ' Object on left - go left ELSEIF (irDetectLeft = 0) THEN pulseLeft = 650 ' Left toward object pu
Navigating with Infrared Headlights · Page 253 ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Variables ]--------------------------------------------------irDetectLeft irDetectRight pulseLeft pulseRight counter VAR VAR VAR VAR VAR Bit Bit Word Word Nib ' Left IR sensor reading ' Right IR sensor reading ' Pulses sent to servos ' Loop counter ' -----[ Initialization ]---------------------------------------------DEBUG "Program Running!" FREQOUT 4, 2000, 3000 start/reset.
Page 254 · Robotics with the Boe-Bot ELSEIF (irDetectRight = 0) THEN pulseLeft = 650 pulseRight = 650 ELSE pulseLeft = 850 pulseRight = 650 ENDIF PULSOUT 13,pulseLeft PULSOUT 12,pulseRight PAUSE 15 RETURN ' Apply the pulse.
Robot Control with Distance Detection · Page 255 Chapter 8: Robot Control with Distance Detection In Chapter 7, we used the infrared LEDs and receivers to detect whether an object is in the Boe-Bot’s way without actually touching it. Wouldn’t it be nice to also know how far away the object is? This is usually a task for sonar, which sends a pulse of sound out and records how long it takes for the echo to come back.
Page 256 · Robotics with the Boe-Bot Figure 8-1 Filter Sensitivity Depends on Carrier Frequency Another way to think about it is that the most sensitive frequency will detect the objects that are the farthest away, while less sensitive frequencies can only be used to detect closer objects. This makes distance detection simple. Pick 5 frequencies, then test them from most sensitive to least sensitive. Try at the most sensitive frequency first.
Robot Control with Distance Detection · Page 257 Figure 8-2 Distance Detection Frequencies and Zones for the Boe-Bot Object 15 14 Vd d 13 12 Red Black X4 Vdd X5 Vin Vs s X3 P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0 X2 Zone 0 41500 Hz + Zone 1 40500 Hz Zone 2 Zone 3 39500 Hz 38250 Hz Zone 4 37500 Hz Boar d of Education © 20 00 -2 00 3 Zone 5 No Detection at any Frequency You might be wondering why the value of zone 4 is 37.5 kHz and not 38.5 kHz.
Page 258 · Robotics with the Boe-Bot The first time through the FOR…NEXT loop, freqSelect is 0, so the LOOKUP command places the value 37500 in the irFrequency variable. Since irFrequency contains 37500 after the LOOKUP command, the FREQOUT command sends that frequency to the IR LED connected to P8. As in the previous chapter, the value of IN9 is then saved in the irDetect variable.
Robot Control with Distance Detection · Page 259 Figure 8-3 Testing Distance Detection Output Examples Keep in mind that these distance measurements are relative and not necessarily precise or evenly spaced. However, they will give the Boe-Bot a good enough sense of object distance for following, tracking, and other activities. Zones 1-4 typically fall in the range of 6 to 12 in (15 to 30 cm) for the shielded LEDs with a 1 kΩ resistor.
Page 260 · Robotics with the Boe-Bot ' -----[ Main Routine ]------------------------------------------------------DO distance = 0 FOR freqSelect = 0 TO 4 LOOKUP freqSelect,[37500,38250,39500,40500,41500], irFrequency FREQOUT 8,1, irFrequency irDetect = IN9 distance = distance + irDetect DEBUG CRSRXY, 4, (freqSelect + 3), DEC5 irFrequency DEBUG CRSRXY, 11, freqSelect + 3 IF (irDetect = 0) THEN DEBUG "Yes" ELSE DEBUG "No " PAUSE 100 NEXT DEBUG CR, "--------"Zone LOOP --------", CR, ", DEC1 distance Your Tu
Robot Control with Distance Detection · Page 261 Displaying Both Distances It’s useful at times to have a quick program you can run to test both the Boe-Bot’s distance detectors at the same time. This program is organized into subroutines, which can be handy for copying and pasting into other programs that require distance detection. Example Program – DisplayBothDistances.bs2 Enter, save, and run DisplayBothDistances.bs2.
Page 262 · Robotics with the Boe-Bot ' -----[ Subroutine – Get_Distances ]----------------------------------------Get_Distances: distanceLeft = 0 distanceRight = 0 FOR freqSelect = 0 TO 4 LOOKUP freqSelect,[37500,38250,39500,40500,41500], irFrequency FREQOUT 8,1,irFrequency irDetectLeft = IN9 distanceLeft = distanceLeft + irDetectLeft FREQOUT 2,1,irFrequency irDetectRight = IN0 distanceRight = distanceRight + irDetectRight PAUSE 100 NEXT RETURN ' -----[ Subroutine – Display_Distances ]---------------------
Robot Control with Distance Detection · Page 263 distance, pressure, or fluid level, it generally involves a control system. These systems sometimes consist of sensors and valves, or sensors and motors, or, in the case of the Boe-Bot, sensors and continuous rotation servos. There is also some kind of processor that takes the sensor measurements and converts them to mechanical action.
Page 264 · Robotics with the Boe-Bot error feeds into an operator block. This block shows that error will be multiplied by a value called a proportional constant (Kp). The value of Kp is 35. The block’s output shows the result of -2 × 35 = -70, which is called the output adjust. This output adjust goes into another summing junction, and this time it is added to the servo’s center pulse width of 750. The result is a 680 pulse width that will make the servo turn about ¾ speed clockwise.
Robot Control with Distance Detection · Page 265 right IR object detector, the output adjust results is a pulse width of 820. Here is the equation and calculations for this block diagram: Left servo output = = = (Left distance set point – Measured left distance) Kp + Center pulse width ((2 – 4) –35) + 750 820 The result of this control loop is a pulse width that makes the left servo turn about ¾ of full speed counterclockwise. This is also a forward pulse for the left wheel.
Page 266 · Robotics with the Boe-Bot Remember that in PBASIC math expressions are executed from left to right. First, distanceRight is subtracted from 2. The result of this subtraction is then multiplied by Kpr, which is 35, and after that, the product is added to the center pulse width of 750. You can use parentheses to force a calculation that is further to the right in a line of PBASIC code to be completed first.
Robot Control with Distance Detection · Page 267 Example Program – FollowingBoeBot.bs2 FollowingBoeBot.bs2 repeats the proportional control loop just discussed with every servo pulse. In other words, before each pulse, the distance is measured and the error signal is determined. Then the error is multiplied by Kp, and the resulting value is added/subtracted to/from the pulse widths that are sent to the left/right servos. Enter, save, and run FollowingBoeBot.bs2.
Page 268 · Robotics with the Boe-Bot ' -----[ Main Routine ]------------------------------------------------------DO GOSUB Get_Ir_Distances ' Calculate proportional output.
Robot Control with Distance Detection · Page 269 Kpl Kpr SetPoint CenterPulse CON CON CON CON -35 35 2 750 The first thing the Main Routine does is call the Get_Ir_Distances subroutine. After the Get_Ir_Distances subroutine is finished, distanceLeft and distanceRight each contain a number corresponding to the zone in which an object was detected for both the left and right IR object detectors.
Page 270 · Robotics with the Boe-Bot Your Turn Figure 8-6 shows a lead Boe-Bot followed by a shadow Boe-Bot. The lead Boe-Bot is running a modified version of FastIrRoaming.bs2, and the shadow Boe-Bot is running FollowingBoeBot.bs2. Proportional control makes the shadow Boe-Bot a very faithful follower. One lead Boe-Bot can string along a chain of 6 or 7 shadow Boe-Bots. Just add the lead Boe-Bot’s side panels and tailgate to the rest of the shadow Boe-Bots in the chain.
Robot Control with Distance Detection · Page 271 With both Boe-Bots running their respective programs, place the shadow BoeBot behind the lead Boe-Bot. The shadow Boe-Bot should follow at a fixed distance, so long as it is not distracted by another object such as a hand or a nearby wall. You can adjust the set points and proportionality constants to change the shadow BoeBot’s behavior. Use your hand or a piece of paper to lead the shadow Boe-Bot while doing these exercises: Try running FollowingBoeBot.
Page 272 · Robotics with the Boe-Bot Building and Testing the Course For successful navigation of this course, some testing and Boe-Bot adjustment will be required. Materials Required (1) Sheet of poster board, approximate dimensions: 22 X 28 in (56 X 71 cm) (1) Roll of black vinyl electrical tape, ¾” (19 mm) wide On your poster board, use the electrical tape to lay out a course as shown in Figure 8-7.
Robot Control with Distance Detection · Page 273 Verify that your zone readings indicate that an object is detected in a very close zone. Both sensors should give you a 1 or 0 reading. 15 1 4 6- 9VD C V dd R ed Bl ack S i nTA MPS C LAS S TM 1 S out V in S in V ss AT N V ss R st V dd P 15 P0 P1 P2 P3 P4 P5 Figure 8-9 Test for Low Zone Number – Top View 13 1 2 9 V dc B a t t ery U1 P 14 P 13 P 12 P 11 P 10 P6 P9 P7 P8 w w w . st a mps i nc al ss .
Page 274 · Robotics with the Boe-Bot Figure 8-11 Test for High Zone Number – Side View Electrical Tape Troubleshooting the Electrical Tape Course If you are unable to get a high zone value when the IR detectors are focused on the electrical tape, take a separate piece of paper, and make a stripe that’s four strips wide instead of three. If the zone numbers are still low, make sure that you are using 2 kΩ resistors (red-black-red) in series with your IR LEDs. You can also try a 4.
Robot Control with Distance Detection · Page 275 Adjust your IR object detectors until the Boe-Bot passes this last test. Then you will be ready to try following the stripe.
Page 276 · Robotics with the Boe-Bot Place your Boe-Bot at the “Start” location shown in Figure 8-13. The Boe-Bot should wait there until you place your hand in front of its IR object detectors. It will then roll forward. When it clears the starting stripe, take your hand away, and it should start tracking the stripe. When it sees the “Finish” stripe, it should stop and wait there.
Robot Control with Distance Detection · Page 277 ' -----[ Variables ]---------------------------------------------------------freqSelect irFrequency irDetectLeft irDetectRight distanceLeft distanceRight pulseLeft pulseRight VAR VAR VAR VAR VAR VAR VAR VAR Nib Word Bit Bit Nib Nib Word Word ' -----[ Initialization ]----------------------------------------------------FREQOUT 4, 2000, 3000 ' -----[ Main Routine ]------------------------------------------------------DO GOSUB Get_Ir_Distances ' Calculate pro
Page 278 · Robotics with the Boe-Bot ' -----[ Subroutine - Get Pulse ]--------------------------------------------Send_Pulse: PULSOUT 13,pulseLeft PULSOUT 12,pulseRight PAUSE 5 RETURN Your Turn – Stripe Following Contest You can turn this into a contest with the lowest course time winning, provided the BoeBot faithfully waits at the “Start” and “Finish” stripes. You can make up other courses too. For best performance, experiment with different SetPoint, Kpl, and Kpr values.
Robot Control with Distance Detection · Page 279 Figure 8-14: Ping))) Sensor and Bracket, Crawler Legs, and Gripper Add-Ons Contests and Challenges Interested in a contest? The www.parallax.com/go/Boe-Bot page also has links to rules to contests ranging from simple to complex and very challenging. Some ideas are also included here in Appendix C: Boe-Bot Navigation Contests which begins on page 299.
Page 280 · Robotics with the Boe-Bot IR Remote for the Boe-Bot IR Remote for the Boe-Bot is available in print (#28139) and as a free PDF download. This book uses the same circuit you currently have built on your Boe-Bot, and has example programs that: Make it possible for you to drive your Boe-Bot around by pressing and holding certain buttons on the remote.
Robot Control with Distance Detection · Page 281 constant to determine the system’s output. The error is the measured system output subtracted from the set point. For the Boe-Bot, both system output and set point were in terms of distance. The BASIC stamp was programmed in PBASIC to operate control loops for the both the left and right servos and distance detectors.
Page 282 · Robotics with the Boe-Bot Exercises 1. List the sensitivity of the IR detector for each kHz frequency shown in Figure 8-1. 2. Write a segment of code that does the frequency sweep for just four frequencies instead of five. 3. Make a condensed checklist for the tests that should be performed to ensure faithful stripe following. Projects 1. Create different types of electrical tape intersections and program the Boe-Bot to navigate through them.
Robot Control with Distance Detection · Page 283 Solutions Q1. The relative sensitivity at 35 kHz is 30%. For 36 kHz, it's 50%. Q2. When index = 4, prime = 11. index = 0, prime = 2 index = 1, prime = 3 index = 2, prime = 5 index = 7, prime = 19 Q3. Expressions are evaluated left to right. To override, use parentheses to change the order. Q4. Use the CON directive. BoilingPoint CON 100 E1. Frequency (kHz): 34 35 36 37 38 39 40 41 42 Sensitivity : 14% 30% 50% 76% 100% 80% 55% 35% 16% E2.
Page 284 · Robotics with the Boe-Bot P1. In the solution below, the Check_For_Intersection subroutine implements the algorithm outlined. The left servo was arbitrarily chosen for counting the forward pulses. A bit-sized variable named isStuck is used as a flag to let the Main Routine know whether an intersection has been reached. In the Navigate_Intersection subroutine, the Boe-Bot goes forward past the intersection and then backs up, checking the sensors, using DO…LOOP…UNTIL.
Robot Control with Distance Detection · Page 285 ' -----[ Initialization ]---------------------------------------------FREQOUT 4, 2000, 3000 ' -----[ Main Routine ]-----------------------------------------------DO GOSUB Get_Ir_Distances GOSUB Update_LEDs ' Read IR sensors ' Indicate white/black line ' Calculate proportional output and move accordingly.
Page 286 · Robotics with the Boe-Bot PULSOUT 13, 750 PULSOUT 12, 650 PAUSE 20 NEXT ELSEIF (distanceRight >=4) THEN FOR counter = 1 TO Turn90Degree PULSOUT 13, 850 PULSOUT 12, 750 PAUSE 20 NEXT ENDIF ' without proportional control ' so use PAUSE 20 ' Right detector reads black ' Turn 90 degrees right ' That's it. At this point the Boe-Bot should have turned 90 degrees ' to follow the intersection. Continue following the black line. RETURN Check_For_Intersection: ' Keep track of no.
Robot Control with Distance Detection · Page 287 Update_LEDs: ' Use LEDs to indicate whether detectors are seeing black or white. ' White = Off, Black = On. Black is a distance reading > or = 4 . IF (distanceLeft >= 4) THEN HIGH LeftLED ELSE LOW LeftLED IF (distanceRight >= 4) THEN HIGH RightLED ELSE LOW RightLED RETURN Stop_Quickly: ' This stops the wheels so the Boe-Bot does not "coast" forward.
Page 288 · Robotics with the Boe-Bot
Parts List and Kit Options · Page 289 Appendix A: Parts List and Kit Options To complete the activities in this text, you will need a complete Boe-Bot robot and the electronic components necessary to build the example circuits. Kit options are described in this appendix. All of the information in this appendix was current at the time of printing. Parallax may make part substitutions at our discretion, out of necessity or to upgrade the quality of our products.
Page 290 · Robotics with the Boe-Bot Robotics with the Boe-Bot Parts kit If you already have a Board of Education and BASIC Stamp 2, you may purchase the Robotics with the Boe-Bot Parts Kit, with or without this printed book: Robotics with the Boe-Bot Parts & Text, #28154 Robotics with the Boe-Bot Parts only, #28124 Parts and quantities subject to change without notice Stock Code Description Quantity 150-01020 1 kΩ resistor 2 150-01030 10 kΩ resistor 4 150-02020 2 kΩ resistor 2 150-02210 220
Parts List and Kit Options · Page 291 Boe-Bot Hardware Pack Contents Parts and quantities subject to change without notice Parallax Stock Code Description Quantity 700-00002 Machine screw, 3/8” 4-40 pan-head, Phillips 8 700-00003 Hex nut, 4-40 zinc plated 10 700-00009 Tail wheel ball 1 700-00015 Nylon washer, #4 screw-size 2 700-00016 Machine screw, 4-40 x 3/8” flathead 2 700-00022 Boe-Bot aluminum chassis 1 700-00023 Cotter pin, 1/16" x 1.
Page 292 · Robotics with the Boe-Bot
Resistor Color Codes and Breadboarding Rules · Page 293 Appendix B: Resistor Color Codes and Breadboarding Rules RESISTOR COLOR CODES Resistors like the ones we are using in this student guide have colored stripes that tell you what their resistance values are. There is a different color combination for each resistance value. There may be a fourth stripe that indicates the resistor’s tolerance.
Page 294 · Robotics with the Boe-Bot BREADBOARDING RULES Look at your Board of Education or HomeWork Board. The white square with lots of holes, or sockets, in it is called a solderless breadboard. This breadboard, combined with the black strips of sockets along two of its sides, is called the prototyping area (shown in Figure B-2). The example circuits in this text are built by plugging components such as resistors, LEDs, speakers, and sensors into these small sockets.
Resistor Color Codes and Breadboarding Rules · Page 295 have symbols. Vss corresponds to the negative terminal of the battery supply for the Board of Education or BASIC Stamp HomeWork Board. Vin is the battery’s positive terminal, and Vdd is regulated to +5 volts. Let’s take a look at an example that uses a schematic to connect the parts shown in Figure B-3. For each of these parts, the part drawing is shown above the schematic symbol.
Page 296 · Robotics with the Boe-Bot Vdd Vin X3 Vdd 470 LED Vss Vss + P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0 X2 Figure B-4 Example Schematic and Wiring Diagram Schematic (left) and wiring diagram (right) Figure B-5 shows a second example of a schematic and wiring diagram. Here, P14 is connected to one end of a resistor, with the other end connected to the + terminal of an LED, and the – terminal of the LED is connected to Vss. These two schematics differ by only one connection.
Resistor Color Codes and Breadboarding Rules · Page 297 Here is a more complex example that involves two additional parts, a 1 kΩ resistor, a phototransistor, and a capacitor. The schematic symbols and part drawings for the components you are not already familiar with are shown in Figure B-6. The phototransistor’s terminals are labeled C, B, and E. The B terminal is optical, so it doesn’t have any electrical connections.
Page 298 · Robotics with the Boe-Bot Figure B-7 Resistor, Phototransistor, and Capacitor Schematic Figure B-8 Resistor, Phototransistor, and Capacitor Wiring Diagram Flat spot and shorter pin Keep in mind that the wiring diagrams presented here as solutions to the schematics are not the ONLY solutions to those schematics. For example, Figure B-9 shows another solution to the schematic just discussed. Follow the connections and convince yourself that it does satisfy the schematic.
Boe-Bot Navigation Contests · Page 299 Appendix C: Boe-Bot Navigation Contests If you're planning a competition for autonomous robots, these rules are provided courtesy of Seattle Robotics Society. CONTEST #1: ROBOT FLOOR EXERCISE Purpose The floor exercise competition is intended to give robot inventors an opportunity to show off their robots or other technical contraptions. Rules The rules for this competition are quite simple.
Page 300 · Robotics with the Boe-Bot Maximum Time to Complete Course Four minutes. Example Course All measurements in the example course are approximate. There is a solid line dividing Area "A" from Area "T" at position "F.” This indicates where the course ends. The line is black, approximately 2.25 inches wide and spaced approximately two feet from the walls. All curves have a radius of at least one foot and at most three feet. The walls are 3 1/2 inches high and surround the course.
Boe-Bot Navigation Contests · Page 301 Scoring Each contestant’s score is calculated by taking the time needed to complete the course (in seconds) minus 10% for each "accomplishment." The contestant with the lowest score wins. Line Following Scoring Accomplished Percent Deducted Stops in area A after reaching B and C 10% Does not touch any walls 10% Starts on command 10% ("Starts on command" means the robot starts with an external, non-tactile command.
Page 302 · Robotics with the Boe-Bot or the right wall. The maze is carefully designed so that there is no advantage if you follow the left wall or the right wall. Robot Limitations The main limit on the robot is that it be autonomous: once started by the owner or handler, no interaction is allowed until the robot emerges from the exit, or it becomes hopelessly stuck. Obviously the robot needs to be small enough to fit within the walls of the maze.
Index · Page 303 Index <>, 134 =, 54 3-pin male-male headers, 45 3-position switch, 42 90° turns, 111 accelerometer, 278 aerospace projects, 58 alarm circuit, 88 ambient light, 172 amps, 31 analog sensor, 179 artificial intelligence, 160 ASCII, 131 Base Phototransistor, 170 Basic Analog and Digital, 38 BASIC Stamp Editor, 12 Memory Map, 127 batteries, 42, 46 battery pack, 77 BIN1, 150 binary sensor, 179 BINx, 150 Bit, 53 Board of Education, 41 Board revisions, 41 Boe-Boost, 42 brownout, 86 Byte, 53 camer
Page 304 · Robotics with the Boe-Bot HOME, 202 REP, 202 Debug Terminal, 92 DEBUGIN, 92 declaring constants, 200 desk lamp, 171 digitized measurement, 179 diode, 28 distance calculations, 112 DO WHILE...LOOP, 128 DO UNTIL...LOOP, 128 DO...LOOP, 26 DO...
Index · Page 305 halogen, 170 ramping, 117 illumninance, 171 rotating, 107 infrared, 221 stopping under bright light, 175 infrared interference, 222 subroutines, 120 LED part drawing and schematic symbol, 29 tactile, 143 luminance, 171 lux, 171 measure brightness with phototransistor, 179 LOOKUP, 257 LOW, 32 luminance, 171 lux, 171 maneuvers.
Page 306 · Robotics with the Boe-Bot CON, 200 PULSOUT syntax, 36 CR, 21 PWM, 190 CRSRX formatter, 202 PWM syntax, 189 CRSRXY, 151 RCTIME, 184 DATA, 127 READ, 127 DEBUG ? formatter, 55 REP formatter, 202 DEBUGIN, 92 RETURN, 120 DO WHILE...LOOP, 128 SDEC formatter, 55 DO ...LOOP UNTIL, 128 SELECT...CASE, 127 DO...LOOP, 26 STEP, 56 ELSE, 155 STOP, 235 ELSEIF, 155 VAR syntax, 53 END, 235 Word modifier for DATA, 132 ENDIF, 155 ENDSELECT, 127 FOR...
Index · Page 307 Ch02Prj01_DimlyLitLED.bs2, 70 OneSubroutine.bs2, 121 Ch02Prj02_4RotationCombinations.bs2, 71 P1LedHigh.bs2, 235 Ch03Prj01_TestCompleteTone.bs2, 100 Ch03Prj02_DebuginMotion.bs2, 101 Circle.bs2, 140 CirclingWithWhiskerInput.bs2, 168 ControlServoRunTimes.bs2, 65 CountToTen.bs2, 57 DisplayBothDistances.bs2, 261 EepromNavigation.bs2, 129 PulseBothLeds.bs2, 39 PulseP13Led.bs2, 37 RightServoTest.bs2, 83 RoamAndSniffBoeBot.bs2, 252 RoamingWithIr.bs2, 238 RoamingWithWhiskers.
Page 308 · Robotics with the Boe-Bot VariablesAndSimpleMath.
Index · Page 309 infrared object detection, 228 light sensor navigation, 214 Programming connection.
Parts and quantities are subject to change without notice. Parts may differ from what is shown in this picture. If you have any questions about your kit, please email stampsinclass@parallax.com.