Page 1
Robotics with the Boe-Bot Student Guide VERSION 2.2...
Page 2
Parallax Inc. 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 Inc. will, at its option, repair or replace the merchandise, or refund the purchase price.
Page 3
Parallax products. Parallax Inc. is also not responsible for any personal damage, including that to life and health, resulting from use of any of our products. You take full responsibility for your BASIC Stamp application, no matter how life-threatening it may be.
Activity #6: Introducing ASCII Code................33 Activity #7: When You’re Done ..................35 Summary ........................37 Chapter 2: Your Boe-Bot’s Servo Motors ..............41 Introducing the Continuous Rotation Servo ..............41 Activity #1: How to Track Time and Repeat Actions .............42 Activity #2: Tracking Time and Repeating Actions with a Circuit ........45 Activity #3: Connecting the Servo Motors ..............58...
Page 6
Activity #1: Building and Testing Photoresistor Circuits ..........194 Activity #2: Roam and Avoid Shadows Like Objects ..........200 Activity #3: A More Responsive Shadow Controlled Boe-Bot........203 Activity #4: Getting More Information from Your Photoresistors.........205 Activity #5: Flashlight Beam Following Boe-Bot ............210 Activity #6: Roaming Toward the Light ...............219...
Page 7
Table of Contents · Page iii Appendix E: Boe-Bot Parts Lists ................317 Appendix F: Balancing Photoresistors ..............321 Appendix G: Tuning IR Distance Detection ............329 Appendix H: Boe-Bot Navigation Contests ............335 Index ........................339...
Page 9
"Boe-Bot". Its name comes from the Board of Education carrier board that is mounted on its wheeled chassis. An example of a Boe-Bot with an infrared obstacle detection circuit built on the Board of Education solderless prototyping area is shown in Figure P-1.
Page 10
Page vi · Robotics with the Boe-Bot The activities and projects in this text begin with an introduction to your Boe-Bot’s brain, ® the Parallax BASIC Stamp 2 microcontroller, and then move on to construction, testing, 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.
Page 11
After completing this text, you can continue your studies with any of the kits and student guides or other manuals discussed below. All of these publications are available for free download from www.parallax.com. The versions cited below were current at the time of this printing. We continually strive to improve our educational program. Please check our web sites, www.parallax.com and www.stampsinclass.com, for the latest revisions.
Page 12
(Boe-Bot) shown in Figure P-2 along with similar robot derivatives with many unique functions. After several revisions, Chuck's design was adopted as the basis of the Parallax Boe-Bot that is used in this text. Russ Miller of Parallax designed the Boe-Bot based on this prototype.
Page 13
Thanks to student Laura Wong and to Rob Gerber for their respective contributions to v1.5. A special thanks to the Parallax, Inc. staff. Each and every member of the Parallax team has in some way contributed to making the Stamps in Class program a success.
Page 14
Page x · Robotics with the Boe-Bot If you have suggestions, think you found a mistake, or would like to contribute an activity or chapter to forthcoming Robotics with the Boe-Bot versions or More Robotics with the Boe-Bot texts, contact us at stampsinclass@parallax.com. Subscribe and stay tuned to the StampsInClass Yahoo! Group for the latest in free hardware offers for Robotics with the Boe-Bot contributions.
Chapter 1: Your Boe-Bot’s Brain · Page 1 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.
Parallax CD. Many electronics outlets carry the What’s a Microcontroller Kits and printed Student Guides. If you have any difficulty finding them locally, they can also be purchased directly from Parallax, either on-line at www.parallax.com or by phone at (888) 512-1024.
Page 17
Chapter 1: Your Boe-Bot’s Brain · Page 3 Both this text and What’s a Microcontroller? contain instructions for getting started with BASIC Stamp hardware and software in Chapter 1. These instructions are almost identical. Introducing the BASIC Stamp and Board of Education ®...
Boe-Bot’s BASIC Stamp brain. It also displays messages on your computer screen sent by the BASIC Stamp, allowing your Boe-Bot one way to report what it is doing and sensing to you, the roboticist.
Adapter. See the information box on page 14 for details. Downloading the Software from the Internet It’s easy to download the BASIC Stamp Editor software from the Parallax web site. The web page shown in Figure 1-4 may look different from the web page you see when you visit the site.
Page 6 · Robotics with the Boe-Bot Figure 1-4 The Parallax Web Site: www.parallax.com √ When you get to the BASIC Stamp Software page, find a BASIC Stamp Windows Editor download with a version number of 2.0 or higher. √...
Chapter 1: Your Boe-Bot’s Brain · Page 7 Figure 1-6 File Download Window Figure 1-7 shows the Save As window that appears next. You can use the Save in field to browse your computer’s hard drives to find a convenient place to save the file.
Finding the Software on the Parallax CD You can also install the BASIC Stamp Editor from the Parallax CD, but the CD has to be newer than April, 2003 so that you can get the version of the BASIC Stamp Editor that is compatible with the examples in this text.
Page 23
Chapter 1: Your Boe-Bot’s Brain · Page 9 √ If the Welcome application does not automatically run, double-click My Computer , then double-click your CD drive, and then double-click Welcome . √ Click the Software link shown in Figure 1-10.
ACTIVITY #2: INSTALLING THE SOFTWARE By now, you have either downloaded the BASIC Stamp Editor Installer from the Parallax web site or located it on the Parallax CD. Now it’s time to run the BASIC Stamp Editor Installer. Installing the Software Step by Step √...
Page 25
“Downloading the Software from the Internet” section, click the Open button now. √ If you located the software on the Parallax CD, click the Install button shown in Figure 1-13. Figure 1-13 The Parallax CD Browser Install button located near bottom of window.
Page 26
Page 12 · Robotics with the Boe-Bot √ Select Typical for your setup type as shown in Figure 1-15. √ Click the Next button. Figure 1-15 Setup Type √ When the InstallShield Wizard tells you it is “Ready to Install the Program”, click the Install button shown in Figure 1-16.
Chapter 1: Your Boe-Bot’s Brain · Page 13 Figure 1-17 InstallShield Wizard Completed ACTIVITY #3: SETTING UP THE HARDWARE AND TESTING THE SYSTEM The BASIC Stamp needs to be connected to power for it to run. It also needs to be connected to a PC so it can be programmed.
Page 28
At the time of this writing, the US232B/LC USB to Serial Adapter made by Future Technology Devices International is the recommended adapter for use with Parallax products. The US232B/LC comes with the hardware shown in Figure 1-19 and a mini-CD ®...
Page 29
Chapter 1: Your Boe-Bot’s Brain · Page 15 Board of Education Connection Instructions If you have a BASIC Stamp and Board of Education, Figure 1-20 shows the hardware you will need to get started. Required Hardware (1) Strip of four rubber feet...
Page 30
Page 16 · Robotics with the Boe-Bot Figure 1-21 Rubber Feet (left) Affixed to Underside of the Board of Education (right) The Board of Education Rev C has a 3-position switch (see Figure 1-22). Position-0 is for turning the power to the Board of Education completely off. Regardless of whether or not you have a battery or power supply connected to the Board of Education Rev C, when the 3-posiiton switch is set to 0, the device is off.
Page 31
Chapter 1: Your Boe-Bot’s Brain · Page 17 Figure 1-23 Battery Pack Polarity indicators on molded plastic (left) and loaded with correct polarity (right). √ If your BASIC Stamp is not already plugged into your Board of Education, insert it into the socket shown in Figure 1-24, step-1.
Page 32
Page 18 · Robotics with the Boe-Bot √ Plug the serial cable into the Board of Education as shown in Figure 1-24, step-2. √ Plug the battery pack into the 6-9 VDC battery jack as shown in Figure 1-24, step-3.
Page 33
Chapter 1: Your Boe-Bot’s Brain · Page 19 (1) BASIC Stamp HomeWork Board Figure 1-27 Getting Started Hardware for the BASIC Stamp HomeWork Board √ Remove each rubber foot from its adhesive strip and affix it to the underside of the HomeWork Board next to each plated hole at each corner of the board as shown in Figure 1-28, making sure not to cover up the holes.
Page 35
The Windows Start Menu can also be used to run the BASIC Stamp Editor. Click your Windows Start Button, then select Programs → Parallax, Inc. → Stamp Editor 2…, then click the BASIC Stamp Editor Icon. Your BASIC Stamp Editor window should look similar to the one shown in Figure 1-32.
Page 22 · Robotics with the Boe-Bot √ To make sure your BASIC Stamp is communicating with your computer, click the Run menu, then select Identify. Figure 1-32 BASIC Stamp Editor An Identification window similar to the one shown in Figure 1-33 will appear. The example in the figure shows that a BASIC Stamp 2 has been detected on COM2.
Page 37
' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Hello, this is a message from your Boe-Bot." You will enter this program into the BASIC Stamp Editor. Some lines of the program are made automatically by clicking buttons on the toolbar. Other lines are made by typing...
Page 38
Page 24 · Robotics with the Boe-Bot √ Begin by clicking the BS2 icon (the green diagonal chip) on the toolbar, shown highlighted in Figure 1-35. If you hold your cursor over this button, its flyover help description “Stamp Mode: BS2” will appear.
Page 39
Chapter 1: Your Boe-Bot’s Brain · Page 25 HelloBoeBot.bs2 Entered into the BASIC Stamp Editor Figure 1-37 √ Save your work by clicking File and selecting Save , (shown in Figure 1-38). Figure 1-38 Saving the Program HelloBoeBot.bs2 √ Enter the name HelloBoeBot.bs2 into the File name field near the bottom of the Save As window as shown in Figure 1-39.
Page 40
Page 26 · Robotics with the Boe-Bot Figure 1-39 Entering the File Name The next time you save, the BASIC Stamp Editor will automatically save to the same filename (HelloBoeBot.bs2) unless you tell it to save to a different filename by clicking File and selecting Save As (instead of just Save).
Page 41
Chapter 1: Your Boe-Bot’s Brain · Page 27 √ Press and release the Reset button. Did you see a second “Hello…” message appear in the Debug Terminal? Figure 1-41 Debug Terminal The Debug Terminal displays messages sent to the PC/laptop by the BASIC Stamp.
Page 42
DEBUG DEBUG "Hello, this is a message from your Boe-Bot." This is the command that tells the BASIC Stamp to send a message to the PC using the serial cable.
Page 43
Chapter 1: Your Boe-Bot’s Brain · Page 29 √ A good new name for the file would be HelloBoeBotYourTurn.bs2. √ Modify the comments at the beginning of the program so that they read: ' Robotics with the Boe-Bot - HelloBoeBotYourTurn.bs2 ' BASIC Stamp does simple math, and sends the results ' to the Debug Terminal.
Page 30 · Robotics with the Boe-Bot Your Debug Terminal should now resemble Figure 1-44. Figure 1-44 Modified HelloBoeBot.bs2 Debug Terminal Output Make sure that when you re-run your program, you get the results you expect. Where did my Debug Terminal go? Sometimes the Debug Terminal gets hidden behind the BASIC Stamp Editor window.
Page 45
Chapter 1: Your Boe-Bot’s Brain · Page 31 Using the BASIC Stamp Editor’s Help √ In the BASIC Stamp Editor, Click Help , then select Index as shown in Figure 1- Figure 1-46 Selecting Index from the Help Menu √...
Page 46
Getting and Using the BASIC Stamp Manual The BASIC Stamp Manual is available for free download from the Parallax web site, and it’s also included on the Parallax CD. It can also be purchased as a bound and printed manual.
Chapter 1: Your Boe-Bot’s Brain · Page 33 √ Briefly look over the BASIC Stamp Manual explanation of the command. DEBUG √ Count the number of example programs in the section. How many are DEBUG there? Figure 1-49 Reviewing the...
Page 48
Page 34 · Robotics with the Boe-Bot Example Program – AsciiName.bs2 √ Enter and run AsciiName.bs2. Remember to use the toolbar icons to place Compiler Directives into your programs! Use the diagonal green electronic chip icon '{$STAMP BS2} - Use the gear icon labeled 2.5.
Chapter 1: Your Boe-Bot’s Brain · Page 35 √ Save AsciiRandom.bs2 as YourAsciiName.bs2 √ Look up the ASCII Chart in the BASIC Stamp Manual. √ Modify the program to spell your own name. √ Run the program to see if you spelled your name correctly.
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 serial cable? 3.
Page 52
Page 38 · Robotics with the Boe-Bot instead of two small ones. Modify these two commands so that the answers appear on different lines in the Debug Terminal. DEBUG DEC 7 * 11 DEBUG DEC 7 + 11 Projects 1. Write a program that uses a...
Page 53
Chapter 1: Your Boe-Bot’s Brain · Page 39 Solutions Q1. The BASIC Stamp 2 microcontroller module. Q2. Binary numbers. Q3. The Debug Terminal. DEBUG – This command is used to send a message from the BASIC Stamp to the DEBUG PC.
Page 54
' Send message to Debug Terminal and do some math. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Hello, this is a message from your Boe-Bot.", CR DEBUG "What's 7 X 11?", CR, "The answer is: ", DEC 7 * 11 The output from the Debug Terminal is: Hello, this is a message from your Boe-Bot.
The Parallax Continuous Rotation servos shown in Figure 2-1 are the motors that will make the Boe-Bot’s wheels turn. This figure points out the servos’ external parts. Many of these parts will be referred to as you go through the instructions in this and the next chapter.
Page 42 · 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.
Page 57
Chapter 2: Your Boe-Bot’s Servo Motors · Page 43 Example Program: TimedMessages.bs2 There are lots of different ways to use the command. This example program uses PAUSE to delay between printing messages that tell you how much time has elapsed. The PAUSE program should wait one second before it sends the “One second elapsed…”...
Page 58
Page 44 · Robotics with the Boe-Bot √ Try changing the arguments from 1000 and 2000 to 5000 and PAUSE Duration 10000, for example: DEBUG "Start timer..." PAUSE 5000 DEBUG CR, "Five seconds elapsed..." PAUSE 10000 DEBUG CR, "Fifteen seconds elapsed..."...
In this activity, you will build circuits that emit light that will allow you to “see” the kind of signals that are used to control the Boe-Bot’s servo motors. What’s a Microcontroller? Excerpts – This activity contains selected excerpts from the What’s a Microcontroller? Student Guide v2.0.
Page 60
Page 46 · Robotics with the Boe-Bot 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.
Page 61
Chapter 2: Your Boe-Bot’s Servo Motors · Page 47 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.
Page 62
Rotation servos turn, make tones with speakers, and prepare sensors to detect light and objects. You will also program the BASIC Stamp to use I/O pins as inputs to monitor sensors that indicate mechanical contact, light level, objects in the Boe-Bot's path, and even their distance.
Page 63
Chapter 2: Your Boe-Bot’s Servo Motors · Page 49 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.
Page 64
Page 50 · Robotics with the Boe-Bot Programs that Control the LED Test Circuits commands can be used to make the BASIC Stamp connect an LED HIGH alternately to Vdd and Vss. The argument is a number between 0 and 15 that tells the BASIC Stamp which I/O pin to connect to Vdd or Vss.
Page 65
Chapter 2: Your Boe-Bot’s Servo Motors · Page 51 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.
Page 66
Page 52 · Robotics with the Boe-Bot 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.
Page 67
Chapter 2: Your Boe-Bot’s Servo Motors · Page 53 Your Turn – Blink the Other LED Blinking the other LED (connected to P12) is a simple matter of changing the argument in the commands and re-running the program. HIGH √...
Page 68
Page 54 · Robotics with the Boe-Bot accurate servo motor control, the time these signals stay high must be much more precise than you can get with a and a command. You can only change the HIGH PAUSE PAUSE command’s argument by 1 ms (remember, that’s 1/1000 of a second) at a...
Page 69
Chapter 2: Your Boe-Bot’s Servo Motors · Page 55 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.
Page 70
This concept is discussed in more detail in Basic Analog and Digital, another Parallax Stamps in Class Student Guide. √ Enter, save, and run PulseBothLeds.bs2.
Page 71
Chapter 2: Your Boe-Bot’s Servo Motors · Page 57 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.
Page 58 · Robotics with the Boe-Bot 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.
Page 73
Chapter 2: Your Boe-Bot’s Servo Motors · Page 59 √ Examine the labeling on your carrier board and figure out whether you have a BASIC Stamp HomeWork Board Rev B or a Board of Education Rev C, B, or A.
Page 74
Use only supplies with DC output voltage ratings between 6 and 7.5 V, and current output ratings of 800 mA or more. Only use a DC supply that is equipped with the same kind of plug as the Boe-Bot battery pack (2.1 mm, center-positive).
Page 75
Chapter 2: Your Boe-Bot’s Servo Motors · Page 61 Select Vdd if you are using a DC 15 14 13 12 supply that plugs into an AC outlet (AC adapter). Figure 2-12 Black Selecting Your 15 14 13 12 Servo’s Power...
Page 76
Page 62 · 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.
Page 77
Chapter 2: Your Boe-Bot’s Servo Motors · Page 63 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:...
Page 78
Page 64 · Robotics with the Boe-Bot White Black Figure 2-17 Servo Connection Schematic for the BASIC Stamp HomeWork Board. White Black √ Remove the two LED/resistor circuits, and save the parts. √ Build the servo ports shown on the left side of Figure 2-18.
Page 79
Chapter 2: Your Boe-Bot’s Servo Motors · Page 65 Figure 2-18 Servo Connection Wiring Diagram for the BASIC Stamp Solid Black HomeWork Black wire with Wire (916) 624-8333 (916) 624-8333 Board white stripe Rev B Rev B www.parallaxinc.com www.parallaxinc.com www.stampsinclass.com www.stampsinclass.com...
Page 81
Servo Tools and Parts The Parallax screwdriver shown in Figure 2-21 is the only extra tool you will need for this activity. Alternately, any Phillips #1 point screwdriver with a 1/8″ (3.18 mm) shaft should do the trick.
Page 82
Page 68 · Robotics with the Boe-Bot the pulse will last. You can also figure out what the command's PULSOUT 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.
Page 83
Chapter 2: Your Boe-Bot’s Servo Motors · Page 69 ' P12 for manual centering. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" 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 84
On some potentiometers, this moving part is a knob or a sliding bar, others have sockets that can be adjusted with screwdrivers. The resistance of the potentiometer inside the Parallax Continuous Rotation servo is adjusted with a #1 point Phillips screwdriver tip.
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 86
Page 72 · 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 is an example of an operator.
Page 87
Chapter 2: Your Boe-Bot’s Servo Motors · Page 73 anotherValue Word These commands are examples of initializing variables to values that you determine. After these two commands are executed, will store 500, and will value anotherValue store 2000. value = 500...
Page 88
Page 74 · Robotics with the Boe-Bot value = value - anotherValue ' Answer = -1500 DEBUG "value = ", SDEC value, CR ' Display values again √ Run the modified program and verify that changes from 500 to -1500.
Run the modified program and verify that it counts backwards in steps of 3. 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.
Page 90
1.3 ms pulses to an LED. Let’s take a closer look at that series of pulses and find out how it can be used to control a servo. Figure 2-25 shows how a Parallax Continuous Rotation servo turns full speed clockwise when you send it 1.3 ms pulses.
Page 91
Chapter 2: Your Boe-Bot’s Servo Motors · Page 77 You can use ServoP13Clockwise.bs2 to send this pulse train to the servo connected to P13. Example Program: ServoP13Clockwise.bs2 Your entire system, including servos should be connected to power for this activity.
Page 92
Page 78 · Robotics with the Boe-Bot √ Run the program and verify that the servo connected to P12 is now rotating between 50 and 60 RPM clockwise. ' Robotics with the Boe-Bot – ServoP12Clockwise.bs2 ' Run the servo connected to P12 at full speed clockwise.
Page 93
This will be important soon. Think about it: when the servos are mounted on either side of the chassis, one will have to rotate clockwise while the other rotates counterclockwise to make the Boe-Bot roll in a straight line. Does that seem odd? If you can’t picture it, try this: √...
Page 94
By testing several possible combinations and filling in the Description column of Table 2-1, you will become familiar with them and build a reference for yourself. You will fill in the Behavior column after your Boe-Bot is fully assembled, when you can see how each combination makes it move.
Page 95
Chapter 2: Your Boe-Bot’s Servo Motors · Page 81 Table 2-1: PULSOUT Duration Combinations Durations Description Behavior Full speed, P13 servo counterclockwise, P12 servo clockwise. Both servos should stay still because of the centering adjustments you made in Activity #4.
Page 96
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...
Page 97
Chapter 2: Your Boe-Bot’s Servo Motors · Page 83 ' {$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...
Page 98
Page 84 · Robotics with the Boe-Bot 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.bs2 ' Run both servos in opposite directions for three seconds, then reverse ' the direction of both servos and run another three seconds.
Page 99
Chapter 2: Your Boe-Bot’s Servo Motors · Page 85 √ Remember to disconnect power from your system (board and servos) when you are done. That means setting the 3-posisiton switch to position-0 if you have a Board of Education Rev C. If you have a HomeWork Board, disconnect the 9 V battery from the battery clip and remove one battery from the battery pack.
5. What are the names of the different size variables that can be declared in a PBASIC program? What size values can each size of variable store? 6. What is the key to controlling a Parallax Continuous Rotation servo’s speed and direction? How does this relate to timing diagrams? How does it relate to...
Page 101
Chapter 2: Your Boe-Bot’s Servo Motors · Page 87 PBASIC commands? What are the command and argument that you can adjust to control a continuous rotation servo’s speed and direction? Exercises 1. Write a command that makes the BASIC Stamp do nothing for 10 PAUSE seconds.
Page 102
Page 88 · Robotics with the Boe-Bot 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. Millisecond is abbreviated "ms".
Page 103
Chapter 2: Your Boe-Bot’s Servo Motors · Page 89 PULSOUT 12, 650 ' P12 servo clockwise PULSOUT 14, 650 ' P14 LED lights dimly PAUSE 20 LOOP P2. First, calculate the number of loops needed to get the servos to run for three seconds, for each combination of rotation.
Page 104
Page 90 · Robotics with the Boe-Bot DEBUG "Program Running!" counter Word FOR counter = 1 TO 120 ' Loop for three seconds PULSOUT 13, 850 ' P13 servo counterclockwise PULSOUT 12, 850 ' P12 servo counterclockwise PAUSE 20 NEXT...
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...
Page 106
Parts List: Instructions: See Figure 3-2. √ Insert the 13/32″ rubber grommet into the hole in the center of the Boe-Bot chassis. (1) Boe-Bot chassis √ Make sure the groove in the outer edge of (4) 1″ Standoffs the rubber grommet is seated on the edge of (4) Pan head screws, 1/4″...
Page 107
(right). Boe-Bot Parts - The parts for the Boe-Bot are either included in the Boe-Bot full kit or in a combination of the Board of Education Full Kit and Robotics Parts Kit. See Appendix E: Boe-Bot Parts Lists for more information.
Page 108
Page 94 · Robotics with the Boe-Bot Figure 3-3 Servo Control Horn Removal Parts (left); after following instructions (right). Phillips Control Output screw horn shaft Stop! √ Before this next step, you must have completed these activities from Chapter 2: Your Boe-Bot’s Servo Motors...
Page 109
Chapter 3: Assemble and Test Your Boe-Bot · Page 95 Figure 3-4 Mounting the Servos on the Chassis Parts (left); assembled (right). 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.
Page 110
√ Use the flathead screws and nuts to attach the battery pack to underside of the Boe-Bot chassis as shown on the left side of Figure 3-6. √ Make sure to insert the screws through the battery pack, then tighten down the nuts on the topside of the chassis.
Page 111
Instructions: The left side of Figure 3-8 shows the Boe-Bot’s tail wheel mounted on the chassis. The tail wheel is merely a plastic ball with a hole through the center. A cotter pin holds it to the chassis and functions as an axle for the wheel.
Page 112
Page 98 · Robotics with the Boe-Bot √ Each plastic wheel has a recess that fits on a servo output shaft. Press each plastic wheel onto a servo output shaft making sure the shaft lines up with and sinks into the recess.
Page 113
Chapter 3: Assemble and Test Your Boe-Bot · Page 99 Figure 3-9 Boe-Bot Chassis and Boards With the Board of Education Rev C With the HomeWork Board Figure 3-10 shows the servo ports reconnected for both the Board of Education Rev C (left side) and the HomeWork Board (right side).
Page 114
P12 - White On Board of Education Rev C On HomeWork Board Figure 3-11 shows the Boe-Bot chassis with their respective boards attached. √ Set the board on the four standoffs so that they line up with the four holes on the outer corner of the board.
In this activity, you will test to make sure that the electrical connections between your board and the servos are correct. Figure 3-13 shows your Boe-Bot’s front, back, left, and right. We need to make sure that the servo on the right turns when it receives pulses from...
Page 116
Wheel Counterclockwise 3 seconds Example Program: RightServoTest.bs2 √ Set the Boe-Bot on its nose so that the drive wheels are suspended above ground. √ Reload the batteries into the battery pack. √ If you have a Board of Education Rev C, set the 3-position switch to position-2.
Page 117
Chapter 3: Assemble and Test Your Boe-Bot · Page 103 √ If the right wheel/servo does not behave as predicted, see the Servo Trouble Shooting section. It comes right after RightServoTest.bs2. √ If the right wheel/servo does behave properly, then move on to the Your Turn section, where you will test the left wheel.
Page 118
Page 104 · Robotics with the Boe-Bot Servo Trouble Shooting: 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 Rev C, make sure the 3-position switch is set to position-2.
If the left wheel/servo does not behave as predicted, see the Servo Trouble Shooting section on page 104. √ If the left wheel/servo does behave properly, then your Boe-Bot is functioning properly, and you are ready to move on to the next activity. ACTIVITY #3: START/RESET INDICATOR CIRCUIT AND PROGRAM When the voltage supply drops below the level a device needs to function properly, it’s...
Page 120
If low batteries are the cause, it could be the fact that the Boe-Bot’s program went back to the beginning and started over again. In other cases, the Boe-Bot can end up doing a confused dance because every time the servos start turning, it overtaxes the already low batteries.
Page 121
Chapter 3: Assemble and Test Your Boe-Bot · Page 107 Figure 3-16 Piezospeaker What’s frequency? It’s the measurement of how often something occurs in a given amount of time. What’s a piezoelectric element and how can it make sound? It’s a crystal that changes shape slightly when voltage is applied to it.
Page 122
Page 108 · Robotics with the Boe-Bot √ Build the circuit shown in Figure 3-17 and Figure 3-18. Figure 3-17 Program Start/Reset Indicator Circuit To Servos To Servos 15 14 13 12 (916) 624-8333 Rev B www.parallax.com Black www.stampsinclass.com Figure 3-18...
Page 123
Chapter 3: Assemble and Test Your Boe-Bot · Page 109 Programming the Start/Reset Indicator The next example program tests the piezospeaker. It uses the command to send FREQOUT precisely timed high/low signals to a speaker. Here is the command’s syntax:...
Page 124
Your Turn - Adding StartResetIndicator.bs2 to a Different Program The lines of code in the battery indicator program will be used at the beginning of every example program from here onward. You could consider it part of the “initialization routine” or “boot routine” for every Boe-Bot program.
Chapter 3: Assemble and Test Your Boe-Bot · Page 111 An initialization routine is comprised of all the commands necessary to get a device or program up and running. It often includes setting certain variable values, beeping noises, and for more complex devices, self testing and calibration.
Page 126
PULSOUT Duration it into the Debug Terminal's Transmit windowpane. √ Continue this activity with the Boe-Bot sitting on its nose so that the wheels do not touch the ground. √ Enter, save, and run TestServoSpeed.bs2. √ Point at the Debug Terminal’s Transmit windowpane with your mouse, and click it to activate the cursor in that window for typing.
Page 127
Chapter 3: Assemble and Test Your Boe-Bot · Page 113 When the servo is done turning, you will be prompted to enter another value. √ Type 850 and then press the Enter key. √ Verify that the servo turns full speed counterclockwise.
Page 128
Page 114 · Robotics with the Boe-Bot FOR counter = 1 TO 244 PULSOUT 12, pulseWidth PULSOUT 13, pulseWidthComp PAUSE 20 NEXT LOOP How TestServoSpeed.bs2 Works Three variables are declared, for the loop, for the counter FOR…NEXT pulseWidth commands, and...
Page 129
Chapter 3: Assemble and Test Your Boe-Bot · Page 115 be 650. If you enter a pulse width of 700, will be 800. Try a few other pulseWidthComp examples. They will all add up to 1500. pulseWidthComp = 1500 - pulseWidth loop that runs for 6 seconds sends pulses to the right (P12) servo.
Page 130
Page 116 · Robotics with the Boe-Bot You can use Table 3-1 to record the data for your own transfer curve. Keep in mind that the example program is controlling the right wheel with the values you enter. The left wheel turns in the opposite direction.
Page 131
Chapter 3: Assemble and Test Your Boe-Bot · Page 117 Since the servo turns for 6 seconds, you can multiply this value by 10 to get revolutions per minute (RPM). √ Multiply this value by 10 and enter the result into Table 3-1 next to the 1.3 ms entry.
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.
Page 133
2. Modify TestServoSpeed.bs2 so that you can use to enter the pulse DEBUGIN width for the left and the right servo as well as the number of pulses to deliver in loop. Use this program to control your Boe-Bot’s motion via the FOR…NEXT Debug Terminal’s Transmit windowpane.
Page 134
Q1. Symptoms include erratic behavior such as going in unexpected directions or doing a confused dance. Q2. A command at the beginning of all Boe-Bot programs causes the FREQOUT piezospeaker to play a tone. This tone will therefore occur every time an accidental reset happens due to brownout conditions.
Page 135
Chapter 3: Assemble and Test Your Boe-Bot · Page 121 FREQOUT 4, 2000, 3000 ' Signal start of program. FOR counter = 1 TO 122 ' Clockwise just under 3 seconds. PULSOUT 12, 650 PAUSE 20 NEXT FOR counter = 1 TO 40 ' Stop one second.
Page 136
Page 122 · Robotics with the Boe-Bot PULSOUT 13, ltPulseWidth ' Left servo motion PULSOUT 12, rtPulseWidth ' Right servo motion PAUSE 20 NEXT LOOP Note: This project is best tested with the Boe-Bot's wheels propped up.
Backward would be toward the left edge of the page. A left turn would be make the Boe-Bot ready to drive off the top of the page, and a right turn would have it facing the bottom of the...
Page 138
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.
Page 139
Chapter 4: Boe-Bot Navigation · Page 125 the same amount of time, the argument also controls the time the servo runs. EndValue Here’s an example program that will make the Boe-Bot roll forward for about three seconds. Example Program: BoeBotForwardThreeSeconds.bs2 √...
Page 140
PULSOUT 12, 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. It takes about 3 seconds for the loop to execute 122 times, so the Boe-Bot drives forward for about 3 FOR…NEXT...
Page 141
Chapter 4: Boe-Bot Navigation · Page 127 Moving Backward, Rotating, and Pivoting All it takes to get other motions out of your Boe-Bot are different combinations of the arguments. For example, these two commands can be used PULSOUT Duration PULSOUT...
Page 142
NEXT Your Turn - Pivoting You can make the Boe-Bot turn by pivoting around one wheel. The trick is to keep one wheel still while the other rotates. For example, if you keep the left wheel still and make the right wheel turn clockwise (forward), the Boe-Bot will pivot to the left.
“software adjustment”. Straightening the Boe-Bot’s Path The first step is to examine your Boe-Bot’s travel for long enough to find out if it’s curving either to the left or to the right when it’s supposed to be going straight ahead.
Page 144
Boe-Bot so that it curves slightly to the right. Let’s say that the Boe-Bot turns slightly to the left. There are two ways to think about this problem: either the left wheel is turning too slowly, or the right wheel is turning too quickly.
Page 145
If your Boe-Bot curved to the right instead of the left, it means you need to slow down the left wheel by reducing the of 850 in the command.
Page 132 · Robotics with the Boe-Bot 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 , or maybe even . If it doesn’t turn far counter = 1 TO 23...
Page 147
You will have to test the Boe-Bot speed. The easiest way to do this is to set the Boe-Bot next to a ruler and make it travel forward for one second. By measuring how far your Boe-Bot traveled, you will know your Boe-Bot’s speed. If your ruler has inches, your answer will be in inches per second (in/s), if it has centimeters your answer will be in centimeters per second (cm/s).
Page 148
Page 134 · Robotics with the Boe-Bot √ 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.
Page 149
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).
Page 150
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.
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 152
√ Enter, save, and run StartAndStopWithRamping.bs2. √ Verify that the Boe-Bot gradually accelerates to full speed, maintains full speed for a while, and then gradually decelerates to a full stop. ' -----[ Title ]-------------------------------------------------------------- ' Robotics with the Boe-Bot - StartAndStopWithRamping.bs2 ' Ramp up, go forward, ramp down.
Page 153
Chapter 4: Boe-Bot Navigation · Page 139 NEXT ' Continue forward for 75 pulses. FOR pulseCount = 1 TO 75 ' Loop sends 75 forward pulses. PULSOUT 13, 850 ' 1.7 ms pulse to left servo. PULSOUT 12, 650 ' 1.3 ms pulse to right servo.
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. ACTIVITY #5: SIMPLIFY NAVIGATION WITH SUBROUTINES In the next chapter, your Boe-Bot will have to perform maneuvers to avoid obstacles.
Page 155
Chapter 4: Boe-Bot Navigation · Page 141 Figure 4-5 shows part of a PBASIC program that contains a subroutine call and a subroutine. The subroutine call is the command. The actual GOSUB My_Subroutine subroutine is everything from the label through the command.
Page 156
Page 142 · Robotics with the Boe-Bot DEBUG "Command in subroutine", CR PAUSE 1000 RETURN √ Watch your Debug Terminal, and press the Reset button a few times. You should get the same set of three messages in the right order each time.
Page 157
Chapter 4: Boe-Bot Navigation · Page 143 Example Program – MovementsWithSubroutines.bs2 √ Enter, save, and run MovementsWithSubroutines.bs2. Hint: you can use the Edit menu in the BASIC Stamp Editor to copy and paste code blocks from one program to another.
Page 158
NEXT RETURN 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.
Page 159
NEXT PAUSE 200 RETURN Did your Boe-Bot perform the familiar forward-left-right-backward sequence? This program may be difficult to read at first, because the instructions are arranged in a new way. Instead of having each variable statement and each command on a different GOSUB line, they are grouped together on the same line and separated by colons.
Page 146 · Robotics with the Boe-Bot colons function the same as a carriage return to separate each PBASIC instruction. Using colons this way allows all of the new variable values for a given maneuver to be stored together, and on the same line as the subroutine call.
Page 161
Bot drive forward, turn left, turn right, and drive back again. Each technique has its merits, but all would be cumbersome if you wanted your Boe-Bot to execute a longer, more complex set of maneuvers. The upcoming program examples will use the now-...
Page 162
Left_Turn, 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. The list is saved in EEPROM during program download with the...
Page 163
Chapter 4: Boe-Bot Navigation · Page 149 while a certain condition exists. Our example program will use DO…LOOP UNTIL . In this case, it causes the to keep repeating until the character (condition) DO…LOOP “Q” is read from EEPROM. statement can be used to select a variable and evaluate it...
Page 164
Page 150 · Robotics with the Boe-Bot FREQOUT 4, 2000, 3000 ' Signal program start/reset. ' -----[ Main Routine ]------------------------------------------------------- DO UNTIL (instruction = "Q") READ address, instruction ' Data at address in instruction. address = address + 1 ' Add 1 to address for next read.
Page 165
RETURN ' Return to Main Routine section. Did your Boe-Bot drive in a rectangle, going forward on the first two sides and backwards on the second two? If it looked more like a trapezoid, you may want to adjust loop's...
Page 166
Remember that the last character in the directive DATA should always be a “Q.” √ Modify the directive to make your Boe-Bot perform the familiar forward- DATA left-right-backward sequence of movements. √ Try adding a second directive. Remember to remove the “Q” from the end...
Page 167
This next example program looks complicated at first, but it is a very efficient way to design programs for custom Boe-Bot choreography. This example program uses EEPROM data storage, but does not use subroutines. Instead, a single code block is...
Page 168
Page 154 · Robotics with the Boe-Bot LOOP UNTIL (pulseCount = 0) The first time through the loop, = 0. The first command will addressOffset READ retrieve a value of 64 from the first address at the label, and place it in the Pulses_Count variable.
Page 169
' 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 √...
Page 170
PULSOUT Duration maneuver’s code block. √ Modify your program with your newly charted directives. DATA √ Enter, save, and run your custom program. Did your Boe-Bot do what you wanted it to do? Keep working on it until it does.
PULSOUT Duration for the faster of the two servos. This changes the Boe-Bot’s path from a curve to a straight line if the servos are not perfectly matched. To refine turning so that the Boe-Bot turns to the desired angle, the...
Page 172
What command needs to be adjusted and what kind of adjustment should you make? 4. If your Boe-Bot travels 11 in/s, how many pulses will it take to make it travel 36 inches? 5.
Page 173
180° turn with right-rotate. With this information, write routines to make the Boe-Bot perform 30, 45, and 60 degree turns. 3. Write a routine that makes the Boe-Bot go straight forward, then ramp in and out of a pivoting turn, and then continue straight forward.
Page 175
Chapter 4: Boe-Bot Navigation · Page 161 PULSOUT 12, 850 PAUSE 20 NEXT FOR counter = 1 to 12 ' Rotate right 45 degrees PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT FOR counter = 1 to 16 ' Rotate right 60 degrees...
Page 176
Circle with a PULSOUT one-yard diameter: ' Robotics with the Boe-Bot - Chapter 4 - Circle.bs2 ' Boe-Bot navigates a circle of 1 yard diameter. '{$STAMP BS2} '{$PBASIC 2.5} DEBUG "Program running!"...
Page 177
Chapter 4: Boe-Bot Navigation · Page 163 match your Boe-Bot and particular surface. For a triangle pattern, the Boe-Bot must travel 1 meter/yard forward, then make a 120 degree turn. This should be repeated three times for the three sides of the triangle. You may have to adjust...
In this chapter, you will build tactile switches, called whiskers, onto your Boe-Bot and test them. You will then program the Boe-Bot to monitor the state of these switches, and to decide what to do when it encounters an obstacle. The end result will be autonomous navigation by touch.
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.
Page 182
Page 168 · 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 169 as a reference.
Page 184
Page 170 · 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 HomeWork Board Right Whisker Use the 220 Ω resistors (red-red-brown-color codes) to connect P5 and P7 to their corresponding 3-pin headers.
Page 185
Chapter 5: Tactile Navigation with Whiskers · Page 171 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, single- pole, 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.
Page 186
Page 172 · 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 called an input register.
Page 174 · 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.
Page 189
Chapter 5: Tactile Navigation with Whiskers · Page 175 Figure 5-10: Whisker Plus LED Wiring Diagram for the Board of Education Left This lead is Whisker To Servos the anode. 15 14 13 12 Black Flat spot on plastic case indicates cathode.
Page 190
Page 176 · Robotics with the Boe-Bot Figure 5-11: Whisker Plus LED Wiring Diagram for the HomeWork Board Left The anode Whisker To Servos connects to the 220 Ω resistor. (916) 624-8333 Rev B www.parallax.com www.stampsinclass.com Flat spot on plastic case...
In this activity, the BASIC Stamp will be programmed to take advantage of this information to guide the Boe-Bot. When the Boe-Bot is rolling along and a whisker is pressed, it means the Boe-Bot bumped into something. A navigation program needs to take this input, decide what it means, and call a set of maneuvers that will make the Boe- Bot back up from the obstacle, turn, and go in a different direction.
Page 192
This next program makes the Boe-Bot go forward until it encounters an obstacle. In this case, the Boe-Bot knows when it encounters an obstacle by bumping into it with one or both of its whiskers. As soon as the obstacle is detected by the whiskers, the navigation routines and subroutines developed in Chapter 4 will make the Boe-Bot back up and turn.
Page 193
Chapter 5: Tactile Navigation with Whiskers · Page 179 √ Try letting the Boe-Bot roam. When it contacts obstacles in its path, it should back up, turn, and then roam in a new direction. ' -----[ Title ]-------------------------------------------------------------- ' Robotics with the Boe-Bot - RoamingWithWhiskers.bs2 ' Boe-Bot uses whiskers to detect objects, and navigates around them.
Page 194
Page 180 · Robotics with the Boe-Bot PAUSE 20 NEXT RETURN Turn_Right: FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees. PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT RETURN Back_Up: ' Back up. FOR pulseCount = 0 TO 40...
Page 195
PULSOUT 13,850 PAUSE 20 RETURN Since each full speed forward pulse makes the Boe-Bot roll around half a centimeter, it’s a really good idea to only send one pulse, then go back and check the whiskers again. Since the statement is inside a , each time the program returns from a IF…THEN...
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.
Page 197
IF…THEN alternate whisker contacts in the next program. Example Program: EscapingCorners.bs2 This program will cause your Boe-Bot to execute a U-turn at either the fourth or fifth alternate corner, depending on which whisker was pressed first. √ Enter, save, and run EscapingCorners.bs2.
Page 198
Page 184 · Robotics with the Boe-Bot ' --- Detect Consecutive Alternate Corners ------------------------ ' See the "How EscapingCorners.bs2 Works" section that follows this program. IF (IN7 <> IN5) THEN ' One or other is pressed. IF (old7 <> IN7) AND (old5 <> IN5) THEN ' Different from previous.
Page 199
1, and when it gets to 4 due to the fact that the counter Boe-Bot is stuck in a corner, it is reset to 1. The variables have to be set old7 old5 so that it looks like one of the two whiskers was pressed some time before the program started.
Page 200
IF (old7 <> IN7) AND (old5 <> IN5) THEN statement. The statement covers what happens if the statement is not true. In ELSE other words, it must not be an alternate whisker that was pressed, so reset the counter because the Boe-Bot is not stuck in a corner.
Page 201
Chapter 5: Tactile Navigation with Whiskers · Page 187 ELSE counter = 1 This statement ends the decision making process for the ENDIF old7 <> IN7 statement. (old5 <> IN5) THEN ENDIF ENDIF The remainder of the program is the same as before. Your Turn One of the statements in EscapingCorners.bs2 checks to see if...
This chapter introduced sensor-based Boe-Bot navigation. The next three chapters will focus on using different types of sensors to give the Boe-Bot vision. Both vision and touch open up lots of opportunities for the Boe-Bot to navigate in increasingly complex environments.
Page 203
Write down the modifications you will have to make to the Main Routine section of RoamingWithWhiskers.bs2. Projects 1. Modify RoamingWithWhiskers.bs2 so that the Boe-Bot makes a 4 kHz beep that lasts 100 ms before executing the evasive maneuver. Make it beep twice if both whisker contacts are detected during the same sample.
Page 204
Page 190 · Robotics with the Boe-Bot Solutions Q1. A tactile switch. Q2. Zero (0) volts, resulting in Binary zero (0) at the input register. IN8 = 0 when whisker is pressed. IN8 = 1 when whisker is not pressed.
Page 205
Chapter 5: Tactile Navigation with Whiskers · Page 191 To modify the Routine, replace the three commands under the first Main GOSUB condition with this single line: GOSUB Turn_Away P1. The key to solving this problem is to write a statement that makes a beep with the required parameters: FREQOUT 4, 100, 4000 ' 4kHz beep for 100ms...
Page 206
Page 192 · Robotics with the Boe-Bot ' Robotics with the Boe-Bot - CirclingWithWhiskerInput.bs2 ' Move in 1 yard circle, increase/decrease radius in response ' to whisker presses, one whisker increases, one decreases. ' {$STAMP BS2} ' Stamp directive. ' {$PBASIC 2.5} ' PBASIC directive.
There are many different light sensors that serve unique functions. The light sensor in your Boe-Bot kit is designed to detect visible light, and it can be used to make your Boe- Bot detect variations in light level. With this ability, your Boe-Bot can be programmed...
"foot-candle" in the English system or the "lux" in the metric system. While using the photoresistors we won't be concerned about lux levels, just whether illuminance is higher or lower in certain directions. The Boe-Bot can be programmed to use the relative light intensity information to make navigation decisions.
Page 209
Schematic – First Light Ω Ω Detection Circuit kΩ kΩ To Servos To Servos 15 14 13 12 (916) 624-8333 Rev B www.parallax.com Figure 6-3 Black www.stampsinclass.com Wiring Diagrams for the First Light Detection Circuit Board of Education (left) and HomeWork Board (right).
Page 210
Page 196 · Robotics with the Boe-Bot How the Photoresistor Circuit Works A BASIC Stamp I/O pin can function as an output or an input. As an output, the I/O pin can send a high (5 V) or low (0 V) signal. Up to this point, high and low signals have been used to turn LED circuits on and off, control servos, and send tones to a speaker.
Page 211
Chapter 6: Light Sensitive Navigation with Photoresistors · Page 197 Figure 6-4 Schematic – Voltage Divider Circuit kΩ When resistors are connected end-to-end as shown in Figure 6-4 they are connected in series, and they can be referred to as series resistors. When two resistors are connected in series to set a voltage at Vo, the circuit is called a voltage divider.
Page 212
Page 198 · Robotics with the Boe-Bot Example Program: TestPhotoresistorsDividers.bs2 This example program is TestWhiskers.bs2 adapted to the photoresistor dividers. Instead of monitoring P5 and P7 as we did with the whiskers, we are now monitoring P3 and P6, which are connected to the photoresistor divider circuits. This program should display a value of 1 on both sides in a well-lit room.
Page 213
Chapter 6: Light Sensitive Navigation with Photoresistors · Page 199 Photoresistor Divider Troubleshooting General things to verify: √ Check your wiring and program for errors. √ Make sure that each component is firmly plugged into its socket. √ Check the color codes on your resistors. The resistors that connect between Vss and the photoresistors should be 2 kΩ...
Page 200 · Robotics with the Boe-Bot ACTIVITY #2: ROAM AND AVOID SHADOWS LIKE OBJECTS Since the photoresistor dividers behave similarly to whiskers, it’s worth examining what’s involved in adapting RoamingWithWhiskers.bs2 so that it functions with the photoresistor dividers. Adapting RoamingWithWhiskers.bs2 for the Photoresistor Dividers...
Page 215
Casting shadows over both photoresistors at the same time can be difficult. When the Boe-Bot is going forward, it is checking the photoresistors around 40 times/second. You will have to move quickly to cast a shadow over both photoresistors between pulses. It helps to move your hand rapidly from no shade to full shade to trigger both photoresistors at once.
Page 216
Your Turn – Improving performance You can improve your Boe-Bot’s performance by commenting some of the subroutine calls that were designed to help the Boe-Bot back away from obstacles and then turn to avoid them. Figure 6-6 shows an example where the two...
A Simple Shadow Controlled Boe-Bot One interesting form of remote control is to have the Boe-Bot sit still in normal light, then follow a shadow you cast over the photoresistors. It’s kind of a user-friendly way of guiding the Boe-Bot’s motion.
Page 218
Page 204 · Robotics with the Boe-Bot Boe-Bot should move forward. If you cast a shadow over one of the photoresistors, the Boe-Bot should turn in the direction of the photoresistor that senses the shadow. √ Enter, save, and run ShadowGuidedBoeBot.bs2.
This program does not need the condition or the two commands that ELSE PULSOUT follow. If you deliver no pulses, the Boe-Bot will sit still, just as it should when you deliver pulses using 750 for the argument. PULSOUT Duration √...
Page 220
√ Make sure you have selected the 0.01 µF capacitors (marked 103) for this activity. The 0.1 µF capacitors can be used in brightly lit areas, but they interfere with the Boe-Bot’s performance in indoor and low lighting activities. Rebuilding the Photosensitive Eyes The circuit the BASIC Stamp can use to determine light levels is called a resistor/capacitor (RC) circuit.
Page 221
Circuits For measurement Ω of resistance that varies with light. 0.01 µF To Servos To Servos 15 14 13 12 (916) 624-8333 Rev B www.parallax.com Black www.stampsinclass.com Figure 6-9 Wiring Diagrams for Photoresistor Circuits Board of Education (left) and HomeWork Board (right).
Page 222
Page 208 · Robotics with the Boe-Bot About RC Decay Time and the Photoresistor Circuit Think of a capacitor in the circuit shown in Figure 6-10 as a tiny rechargeable battery. When P6 sends the high signal, it essentially charges this capacitor-battery by applying 5 V to it.
Page 223
RC decay time on the photoresistor circuit connected to P6, which is the photoresistor on the Boe-Bot’s left. To measure RC decay, the first thing you have to do is make sure you have declared a...
In this activity, you will test and calibrate your Boe-Bot’s light sensors so that they recognize the difference between ambient light and a directed flashlight beam. You will then program the Boe-Bot to follow the flashlight beam that is pointed at the surface in front of the Boe-Bot.
Page 225
Adjust Sensors to Search for Flashlight Beam This activity works best if the photoresistors’ light-collecting surfaces are pointing ahead at separate points on the ground about 2 in (5.1 cm) in front of the Boe-Bot. √ Point the light collecting surfaces of your photoresistors at the surface in front of the Boe-Bot as shown in Figure 6-11.
Page 226
Page 212 · Robotics with the Boe-Bot Testing Sensor Response to Flashlight Beam Before you can program the Boe-Bot to turn towards a flashlight beam, you have to know the difference between light readings with and without the flashlight beam shining in the Boe-Bot’s path.
Page 227
LOOP Your Turn √ Try facing the Boe-Bot in different directions, and repeat your measurements. √ For better results, you can average your measurements for "flashlight on" and "flashlight off" and replace the values in Table 6-1 with your average values.
Page 228
Page 214 · Robotics with the Boe-Bot Constants can even be used to calculate other constants. Here is an example of two constants, named that are calculated using the LeftThreshold RightThreshold four constants just discussed. The constants are LeftThreshold RightThreshold used in the program to figure out whether or not the flashlight beam has been detected.
Page 229
Experiment and figure out exactly where to focus the light to get the forward, left turn, and right turn maneuvers to execute. √ Use the flashlight to guide your Boe-Bot through various obstacle courses and maneuvers. ' -----[ Title ]-------------------------------------------------------------- ' Robotics with the Boe-Bot - FlashlightControlledBoeBot.bs2...
Page 230
Page 216 · Robotics with the Boe-Bot FREQOUT 4, 2000, 3000 ' -----[ Main Routine ]------------------------------------------------------- GOSUB Test_Photoresistors GOSUB Navigate LOOP ' -----[ Subroutine - Test_Photoresistors ]----------------------------------- Test_Photoresistors: HIGH 6 ' Left RC time measurement. PAUSE 3 RCTIME 6,1,timeLeft HIGH 3 ' Right RC time measurement.
Page 231
Chapter 6: Light Sensitive Navigation with Photoresistors · Page 217 How FlashlightControlledBoeBot.bs2 Works These are the four constant declarations that you used with your own values from Table 6-1. LeftAmbient RightAmbient LeftBright RightBright Now that the four constants have been declared, the next two lines average and scale the values to come up with threshold values for the program.
Page 232
Page 218 · Robotics with the Boe-Bot This is the subroutine that performs the measurements on both photoresistor RC RCTIME circuits. The measurement for the left circuit is stored in the variable, and the timeLeft measurement for the right circuit is stored in the variable.
ACTIVITY #6: ROAMING TOWARD THE LIGHT The example program in this activity can be used to guide the Boe-Bot through exiting a fairly dark room toward a doorway that’s letting in brighter light. It also allows for much better control over the Boe-Bot’s roaming by casting shadows over the photoresistors...
Page 234
Each time the Boe-Bot turns a little, the variables timeRight timeLeft change so much that the Boe-Bot tries to correct and turn back. It never manages to get any forward pulses in. IF (timeLeft > timeRight) THEN ' Turn right.
Page 235
Bot just goes forward, and never makes any adjustments to the left or right. Why does that happen? Here is the answer: When the Boe-Bot is in a dark part of a room, the measurement for each photoresistor will be large. For the Boe-Bot to decide to turn toward a light source, the difference between these two measurements has to be large.
Page 236
Page 222 · Robotics with the Boe-Bot average = timeRight + timeLeft / 2 difference = average / 6 Now, the variable can be used in this statement, and it will be a difference IF…THEN large value when the lighting is low, and a small value when the lighting is bright.
Page 237
Chapter 6: Light Sensitive Navigation with Photoresistors · Page 223 √ Also try placing your Boe-Bot in a room that is poorly lit, but that has light streaming in through a doorway from an adjacent brightly lit room or hallway.
Page 238
Boe-Bot less sensitive to differences average in light or divide it by a larger value if you want to make the Boe-Bot more sensitive to differences in light level.
Page 239
Instead of the value 6, try dividing the variable by the values 3, 4, 5, 7, average and 9. √ Run the program and test the Boe-Bot’s ability to exit a dark room with each denominator value. √ Decide what the optimum denominator value is. Average_And_Difference:...
Page 240
Page 226 · Robotics with the Boe-Bot difference = difference / Denominator RETURN There is a better way though. √ Leave the routine like this: Average_And_Difference Average_And_Difference: average = timeRight + timeLeft / 2 difference = average / Denominator RETURN √...
Watch the Boe-Bot in Action at www.parallax.com! You can see the Boe-Bot solving Chapter 6 Projects 1 and 2 along with other Robotics video clips in the Robo Video Gallery under the Robotics Menu at www.parallax.com.
Page 242
Develop a program that makes the Boe-Bot avoid the black sheets of paper. Hints: Make sure to test and understand what the Boe-Bot sees when it is focused on a black sheet of paper and what it sees when it is focused on a white background.
Page 243
Bright sunlight from windows, and shadows cast by onlookers can make the demonstration fail. 2. If you succeeded with project 1, experiment with confining the Boe-Bot so that it can only roam in a space that is enclosed by black sheets of paper.
Page 244
Q5. It checks the sensors between each pulse, instead of having fixed maneuvers of many pulses. This makes the Boe-Bot much more responsive. Q6. A constant declaration tells the compiler the value of your constant.
Page 245
IF…THEN above or below the average readings. (For the author's Boe-Bot, scaling was not necessary). Here's a program solution that makes the Boe-Bot recognize the difference between black and white surfaces.
Page 246
PAUSE 3 RCTIME 6,1,timeLeft HIGH 3 ' Right RC time measurement. PAUSE 3 RCTIME 3,1,timeRight RETURN To develop a program that makes the Boe-Bot avoid the black sheets of paper, the decision and navigation steps required are very similar to...
Page 247
Chapter 6: Light Sensitive Navigation with Photoresistors · Page 233 "FlashlightControlledBoeBot.bs2" and "RoamingTowardTheLight.bs2". A sample solution is shown below. ' -----[ Title ]------------------------------------------------------- ' Robotics with the Boe-Bot - AvoidBlackSpots.bs2 ' Boe-Bot avoids black pieces of paper. ' {$STAMP BS2} ' Stamp directive ' {$PBASIC 2.5}...
Page 248
ENDIF RETURN Hints: Make sure to test and understand what the Boe-Bot sees when it is focused on a black sheet of paper and what it sees when it is focused on a white background. Use example programs from the last three activities in this chapter.
Chapter 7: Navigating with Infrared Headlights · Page 235 Chapter 7: Navigating with Infrared Headlights Today's hottest products seem to have one thing in common: wireless communication. Personal organizers beam data into desktop computers, and wireless remotes let us channel surf. Many remote controls and PDA’s use signals in the infrared frequency range to communicate, below the visible light spectrum.
Page 250
They emit infrared, and in some cases, the infrared reflects off objects and bounces back in the direction of the Boe-Bot. The eyes of the Boe-Bot are the infrared detectors. The infrared detectors send signals indicating whether or not they detect infrared reflected off an object.
Some fluorescent lights do generate signals that can be detected by the IR detectors. These lights can cause problems for your Boe-Bot’s infrared headlights. One of the things you will do in this chapter is develop an infrared interference “sniffer” that you can use to test the fluorescent lights near your Boe-Bot courses.
Page 252
Page 238 · Robotics with the Boe-Bot One IR pair (IR LED and detector) is mounted on each corner of the breadboard. Figure 7-4 shows the IR headlights circuit as a schematic and Figure 7-5 shows the circuit as a wiring diagram.
Page 253
1 ms to P8. The infrared LED circuit connected to P8 will broadcast this harmonic. If the infrared light is reflected back to the Boe-Bot by an object in its path, the infrared detector will send the BASIC Stamp a signal to let it know that the reflected...
Page 254
IR detector’s output in a variable immediately after sending the command. The value stored by the variable can FREQOUT then be displayed in the Debug Terminal or used for navigation decisions by the Boe-Bot. Example Program: TestLeftIrPair.bs2 √ Reconnect power to your board.
Page 255
If the reading is 1 most of the time when there is no object in front of the Boe-Bot, but flickers to 0 occasionally, it may mean you have interference from a nearby fluorescent light.
Some ballasts operate in the same frequency range of your IR detector, 38.5 kHz, which in turn causes the lamp to emit a signal at this frequency. When you integrate IR object detection with navigation, this interference can cause some bizarre Boe-Bot behavior! Rebuilding the LED Indicator Circuits These are the same LED indicator circuits that you used with the whiskers.
Page 257
That’s why it’s important to have a test program that shows you what the infrared detectors are sensing. You can use this program to verify that all the circuits are working before unplugging the Boe-Bot from its serial cable and testing other objects.
Page 258
Page 244 · Robotics with the Boe-Bot √ Verify that the speaker makes a clear, audible tone while the Debug Terminal displays “Testing piezospeaker…”. √ Use the Debug Terminal to verify that the BASIC Stamp still receives a zero from each IR detector when an object is placed in front of it.
Page 259
Boe-Bot right now. Likewise, the remotes you use to control these devices all use the same kind of IR LED that's on your Boe-Bot to transmit messages to the IR detector in your TV, VCR, CD/DVD player, etc.
Page 260
Page 246 · Robotics with the Boe-Bot Example Program – IrInterferenceSniffer.bs2 √ Enter, save, and run IrInterferenceSniffer.bs2. √ Test to make sure the Boe-Bot sounds the alarm when it detects IR interference. this with separate Boe-Bot that’s running TestIrPairsAndIndicators.bs2. If you don’t have a second Boe-Bot, just use a handheld remote for a TV, VCR, CD/DVD player, or projector.
You may have noticed that brighter car headlights (or a brighter flashlight) can be used to see objects that are further away when it’s dark. By making the Boe-Bot’s infrared LED headlights brighter, you can also increase its detection range. By resisting electric current less, a smaller resistor allows more current to flow through an LED.
Page 262
Page 248 · Robotics with the Boe-Bot The command is used here rather than , since would put the BASIC Stamp STOP into low power mode. Your Turn – Testing LED Brightness Remember to disconnect power before you make changes to a circuit. Remember also that the same program will run again when you reconnect power, so you can pick up right where you left off with each test.
Chapter 7: Navigating with Infrared Headlights · Page 249 √ Repeat with 2 kΩ resistors. √ Repeat with 470 Ω resistors. √ Repeat with 220 Ω resistors. Table 7-2: Detection Distance vs. Resistance IR LED Series Maximum Detection Distance, Resistance, (Ω) Circle one: ( in / cm ) 4700 2000...
Page 264
Page 250 · Robotics with the Boe-Bot irDetectLeft = IN9 statements were modified so that they look at the variables that store the IR IF…THEN pair detections instead of the whisker inputs. IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN...
Page 265
Chapter 7: Navigating with Infrared Headlights · Page 251 FREQOUT 4, 2000, 3000 ' Signal program start/reset. ' -----[ Main Routine ]------------------------------------------------------- FREQOUT 8, 1, 38500 ' Store IR detection values in irDetectLeft = IN9 ' bit variables. FREQOUT 2, 1, 38500 irDetectRight = IN0 IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN GOSUB Back_Up...
The great thing about detecting an obstacle before bumping into it is that it gives the Boe- Bot 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.
Page 267
Chapter 7: Navigating with Infrared Headlights · Page 253 irDetectRight pulseLeft Word pulseRight Word FREQOUT 4, 2000, 3000 ' Signal program start/reset. ' Main Routine FREQOUT 8, 1, 38500 ' Check IR Detectors irDetectLeft = IN9 FREQOUT 2, 1, 38500 irDetectRight = IN0 ' Decide how to navigate.
Page 268
Your Turn √ Save FastIrRoaming.bs2 as FastIrRoamingYourTurn.bs2. √ Use the LEDs to broadcast that the Boe-Bot has detected an object. √ Try modifying the values that pulseLeft and pulseRight are set to so that the Boe-Bot does everything at half speed.
There are also applications where the Boe-Bot must take evasive action when an object is not detected. For example, if the Boe-Bot is roaming on a table, its IR detectors might be looking down at the table surface as shown in Figure 7-8. The program should make it continue forward so long as both IR detectors can “see”...
Page 270
√ Replace your 1 kΩ resistors with 2 kΩ resistors (red-black-red) to connect P2 to its IR LED and P8 to its IR LED. We want the Boe-Bot to be nearsighted for this activity. √ Reconnect power to your board.
Page 271
Always be ready to pick your Boe-Bot up from above as it approaches the edge of the table it’s navigating. If the Boe-Bot tries to drive off the edge, pick it up before it takes the plunge. Otherwise, your Boe-Bot might become a Not-Bot! √...
Page 272
You may want your Boe-Bot to only take one pulse forward between checking the 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.
Page 273
Chapter 7: Navigating with Infrared Headlights · Page 259 FREQOUT 4, 2000, 3000 ' Signal program start/reset. ' Main Routine. FREQOUT 8, 1, 38500 ' Check IR detectors. irDetectLeft = IN9 FREQOUT 2, 1, 38500 irDetectRight = IN0 ' Decide navigation. IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN pulseCount = 1 ' Both detected,...
Page 274
Page 260 · Robotics with the Boe-Bot pulseCount Byte statements now set the value of as well as the values of IF…THEN pulseCount . If both detectors can see the table, take one cautious pulse pulseRight pulseLeft forward. IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN...
Page 275
Modify AvoidTableEdge.bs2 so that it follows the edge of the electrical tape delimited course by adjusting the values so that the Boe-Bot pulseCount 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.
LED found in common handheld remotes, and the infrared detector found in TVs, CD/DVD players, and other appliances that are controlled by these remotes. By shining infrared into the Boe-Bot’s path and looking for its reflection, object detection can be accomplished without physically contacting the object. Infrared LED circuits are used to send a 38.5 kHz signal with the help of a property of the...
Page 277
Exercise 3? Projects 1. Design a Boe-Bot application that sits still until you wave your and in front of it, then it starts roaming. 2. Design a Boe-Bot application that slowly rotates in place until it detects an object.
Page 278
A sample solution is shown below. ' -----[ Title ]------------------------------------------------------- ' Robotics with the Boe-Bot - MotionActivatedBoeBot.bs2 ' Boe-Bot starts roaming when hand is waved in front of IR detectors. ' {$STAMP BS2} ' {$PBASIC 2.5}...
Page 279
"FastIrRoaming.bs2", with a bit added that spins the Boe-Bot slowly until an object is detected. In the solution below, once the Boe-Bot has spied an object, it will continue forward even if the detectors both read "no object" (1) for a few loops. This is...
Page 280
Page 266 · Robotics with the Boe-Bot detectors read "no object" for brief moments, but this is not reason enough to give up the chase. ' Robotics with the Boe-Bot - SumoBoeBot.bs2 ' Search for object, lock onto it and push it.
Page 281
P3. The key to solving this problem is to combine "FastIrRoaming.bs2" and "IrInterferenceSniffer.bs2" in a single program. ' -----[ Title ]------------------------------------------------------- ' Robotics with the Boe-Bot - RoamAndSniffBoeBot.bs2 ' Boe-Bot roams around and sounds alarm when IR detected. ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Variables ]---------------------------------------------------...
Page 282
Page 268 · Robotics with the Boe-Bot ' -----[ Subroutines ] ------------------------------------------------ Sniff: ' From IrInterferenceSniffer.bs2 IF (IN0 = 0) OR (IN9 = 0) THEN FOR counter = 1 TO 5 ' Beep 5 times HIGH 1 ' and flash LEDs...
Chapter 8: Robot Control with Distance Detection In Chapter 7, we used the infrared sensors 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 284
Programming Frequency Sweep for Distance Detection shows an example of how the Boe-Bot can test for distance using frequency. Figure 8-2 In this example, the object is in Zone 3. That means that the object can be detected when 37500 and 38250 Hz is transmitted, but it cannot be detected with 39500, 40500, and 41500 Hz.
Page 285
Chapter 8: Robot Control with Distance Detection · Page 271 Figure 8-2: Frequencies and Zones for the Boe-Bot Object Object 15 14 13 12 Vd d Black Vs s Zone 0 Zone 1 Zone 2 Zone 3 Zone 4 Zone 5...
Page 286
Page 272 · Robotics with the Boe-Bot FREQOUT 8,1, irFrequency irDetect = IN9 ' Commands not shown... NEXT The first time through the … loop, is 0, so the command NEXT freqSelect LOOKUP places the value 37500 in the variable. Since...
Page 287
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. √ Enter, save, and run TestLeftFrequencySweep.bs2.
Page 288
Page 274 · Robotics with the Boe-Bot ' -----[ Variables ]---------------------------------------------------------- freqSelect irFrequency Word irDetect distance ' -----[ Initialization ]----------------------------------------------------- DEBUG CLS, " OBJECT", CR, "FREQUENCY DETECTED", CR, "--------- --------" ' -----[ Main Routine ]------------------------------------------------------- distance = 0 FOR freqSelect = 0 TO 4...
Page 289
Run the program and verify that this pair can measure a similar distance. 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.
Closed loop control is a common method of maintaining levels, and it works very well for helping the Boe-Bot maintain its distance from an object. There are lots of different kinds of closed loop control. Some of the most common are hysteresis, proportional, integral, and derivative control.
Page 292
This particular example is for the right IR LED/detector and right servo. The set point is 2, which means we want the Boe-Bot to maintain a distance of 2 between itself and any object it detects. The measured distance is 4, which is too far away. The error is the set point minus the measured distance which is 2 –...
Page 293
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. The idea of feedback is that the system’s output is re-sampled, by the shadow Boe-Bot taking another distance measurement.
Page 294
Page 280 · Robotics with the Boe-Bot Center pulse width Output Figure 8-5 adjust Error = -2 Proportional Kp X error Control Block -35 X -2 Diagram for Left Servo and IR LED and Left servo Measured left output Detector Pair...
Page 295
√ Enter, save, and run FollowingBoeBot.bs2. Point the Boe-Bot at an 8 ½ × 11” sheet of paper held in front of it as though it’s √ a wall-obstacle. The Boe-Bot should maintain a fixed distance between itself and the sheet of paper.
Page 296
Page 282 · Robotics with the Boe-Bot √ Move the sheet of paper too close to the Boe-Bot, and it should back up, away from the paper. ' -----[ Title ]-------------------------------------------------------------- ' Robotics with the Boe-Bot - FollowingBoeBot.bs2 ' Boe-Bot adjusts its position to keep objects it detects in zone 2.
Page 297
Chapter 8: Robot Control with Distance Detection · Page 283 Get_Ir_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 NEXT RETURN...
Page 298
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.
Page 299
Boe-Bot as shown in Figure 8-6. √ If you are not part of a class (and only have one Boe-Bot) the shadow vehicle will follow a piece of paper or your hand just as well as it follows a lead Boe- Bot.
Page 286 · Robotics with the Boe-Bot You can adjust the set points and proportionality constants to change the shadow Boe- Bot’s behavior. Use your hand or a piece of paper to lead the shadow Boe-Bot while doing these exercises: √...
Page 301
Run DisplayBothDistances.bs2 from page 275. Keep your Boe-Bot connected to its serial cable so that you can see the displayed distances. √ Start by placing your Boe-Bot so that it is looking directly at the white background of your poster board as shown in Figure 8-9. √...
Page 303
(red-black-red) in series with your IR LEDs. You can also try a 4.7 kΩ resistor to make the Boe-Bot more nearsighted. If none of this works, try a different brand of black vinyl electrical tape. Adjusting the IR LED/detector so that it is focused closer to or further from the front of the Boe-Bot (see Figure 8-11) may also help.
Page 304
4 or 5. Keep in mind that if you move the Boe-Bot toward its left, the right detectors should increase in value, and if you move the Boe-Bot toward its right, the left detectors should show the higher value.
Page 305
Run the program (shown below). √ 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 pairs. It will then roll forward. When it clears the starting stripe, take your hand away, and it should start tracking the stripe.
Page 306
Page 292 · Robotics with the Boe-Bot ' Change from 35 to -35 SetPoint ' Change from 2 to 3. CenterPulse ' -----[ Variables ]---------------------------------------------------------- freqSelect irFrequency Word irDetectLeft irDetectRight distanceLeft distanceRight pulseLeft Word pulseRight Word ' -----[ Initialization ]-----------------------------------------------------...
Page 307
Chapter 8: Robot Control with Distance Detection · Page 293 ' -----[ 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 Boe- Bot faithfully waits at the “Start”...
Watch the Boe-Bot in Action at www.parallax.com! You can see the Boe-Bot solving Chapter 8 Project 2 and other Robotics video clips in the Robo Video Gallery under the Robotics Menu at www.parallax.com.
Page 309
Remember to reset both counters to zero each time the loop counter gets to 60. After the Boe-Bot recognizes that it is at an intersection, it needs to move to the top edge of the intersection, then back up and figure out whether it sees electrical tape or white background on the left and right, then make the correct 90°...
Page 310
• Black readings should be 4-5 in both sensors. • Straddle the line, both sensors should read 0-1. • Move Boe-Bot back and forth over line, sensor over black line should read 4-5. P1. In the solution below, the subroutine implements Check_For_Intersection the algorithm outlined.
Page 311
Chapter 8: Robot Control with Distance Detection · Page 297 intersection is a 3-way or 4-way intersection, the Boe-Bot will arbitrarily turn in the direction that black is first detected. A constant, , is provided Turn90Degree to tune the 90 degree turn. Some audible and visual indicators are included, which aid in troubleshooting and understanding what the Boe-Bot is seeing and deciding, as well as adding a bit of personality and fun.
Page 313
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. PULSOUT 13, 750...
Page 314
' PAUSE reduced due to IR readings RETURN P2. If you create an interesting Boe-Bot maze project and you want to share it with others, you may want to join the StampsInClass Yahoo! Group, listed behind the title page of Robotics with the Boe-Bot. Or, you can email the parallax...
Appendix A: PC to BASIC Stamp Communication Trouble-Shooting · Page 301 Appendix A: PC to BASIC Stamp Communication Trouble-Shooting Here is a list of things to try to quickly fix any difficulties getting the BASIC Stamp Editor to communicate with your BASIC Stamp: √...
Page 316
Page 302 · Robotics with the Boe-Bot Figure A-1 Identification Window Example: BASIC Stamp 2 not found on COM ports. If you know the number of the COM port, but it does not appear in the Identification Window: √ Use the Edit Port List button to add that COM port. When you return to the Identification window, click the Refresh button to find out if the BASIC Stamp 2 is now detected.
Page 317
Appendix A: PC to BASIC Stamp Communication Trouble-Shooting · Page 303 √ If you are using a serial port (no USB to serial adaptor), make a note of the COM ports listed. If one or more of these COM ports do not appear in your BASIC Stamp Editor's list, make a note of the numbers for each COM port that doesn't appear in the list now.
Page 318
Click OK to close each window as needed and return to the BASIC Stamp Editor. √ Try downloading a program once more. √ If none of these solutions work, you may go to www.parallax.com and follow the Support link. Or, email support@parallax.com or call Tech Support toll free at 1-888-99-STAMP.
Appendix B: BASIC Stamp and Carrier Board Components and Features · Page 305 Appendix B: BASIC Stamp and Carrier Board Components and Features The BASIC STAMP 2 Microcontroller Module ® Figure B-1 shows a close-up of the BASIC Stamp 2 microcontroller module. Its major ®...
Page 320
Page 306 · Robotics with the Boe-Bot The Board of Education Rev C Carrier Board ® The Board of Education Rev C carrier board for BASIC Stamp 24-pin microcontroller ® ® modules is shown in Figure B-2. Its major components and their functions are indicated by labels.
Page 321
Appendix B: BASIC Stamp and Carrier Board Components and Features · Page 307 The BASIC Stamp HomeWork Board Project Platform ® ™ The BASIC Stamp HomeWork Board project platform is shown in Figure B-3. Its ® ™ major components and their functions are indicated by labels. Figure B-3: BASIC Stamp HomeWork Board Project Platform...
Page 322
Page 308 · Robotics with the Boe-Bot The Board of Education Rev B Carrier Board ® Figure B-4 shows the Board of Education Rev B carrier board for BASIC Stamp ® ® pin microcontroller modules. Its major components and their functions are indicated by labels.
Appendix C: Resistor Color Codes · Page 309 Appendix C: 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.
Page 324
Page 310 · Robotics with the Boe-Bot Third stripe is brown. Since brown is 1, it means add one zero to the right of the • first two digits. Yellow-Violet-Brown = 4-7-0.
Appendix D: Breadboarding Rules · Page 311 Appendix D: 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 D-1).
Page 326
Page 312 · Robotics with the Boe-Bot connected by lines on a schematic, the line indicates that an electrical connection is made. Lines can also be used to connect components to voltage supplies. Vdd, Vin, and Vss all have symbols. Vss corresponds to the negative terminal of the battery supply for the Board of Education or BASIC Stamp HomeWork Board.
Page 327
Appendix D: Breadboarding Rules · Page 313 Figure D-3 Example Schematic and Ω Wiring Diagram Schematic (left) and wiring diagram (right) Figure D-4 shows a second example of a schematic and wiring diagram. This schematic shows P14 connected to one end of a resistor, with the other end connected to the + terminal of an LED, and the –...
Page 328
Page 314 · Robotics with the Boe-Bot Figure D-4 Example Schematic and Wiring Diagram Ω Schematic (left) and wiring diagram (right) Here is a more complex example that involves two additional parts, a photoresistor and a capacitor. The schematic symbols and part drawings for these components are shown in Figure D-5.
Page 329
Appendix D: Breadboarding Rules · Page 315 the prototyping area (Figure D-7). In the schematic, the other lead of the resistor is connected to not one, but two other component terminals. A terminal from the photoresistor and capacitor both share this connection. On the breadboard, the other resistor lead is plugged into one of the rows of 5 sockets.
Page 330
Page 316 · Robotics with the Boe-Bot Figure D-7 Resistor, Photoresistor, and Capacitor Wiring Diagram 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 D-8 shows another solution to the schematic just discussed.
Boe-Bot Robot Kit (also known as the Boe-Bot Full Kit) Aside from a PC with a serial port and a few common household items, the Boe-Bot Robot Kit contains all the parts and documentation you’ll need to complete the experiments in this text.
Page 332
Robotics with the Boe Bot Parts Kit If you already have a Board of Education and BASIC Stamp, you may purchase the Robotics with the Boe-Bot Parts kit, with or without the printed text Robotics with the Boe-Bot Student Guide.
Page 333
All of the Boe-Bot hardware parts can be purchased individually, as found in our on-line Robot Component Shop if you find you need a replacement part. Please note that the Hardware Pack is not sold as a unit separately from the Boe-Bot Robot (Full) Kit or the Boe-Bot Parts Kit.
Page 334
Page 320 · Robotics with the Boe-Bot Board of Education Kits Almost all of the titles in the Stamps in Class curriculum feature different hardware and component packages that depend on the BASIC Stamp and Board of Education as a core.
The values will then be similar for similar incident light levels, which can help the Boe-Bot recognize different incident light levels more reliably. This technique can in turn assist the Boe-Bot in exiting dark rooms, even with mismatched photoresistor circuits.
Page 336
Page 322 · Robotics with the Boe-Bot √ Cup your hand over the photoresistors, making sure that you are casting equal shade over both. For best results, the measurements should be in the 200 to 400 range. √ Record the values of both time measurements in the second row of Table F-1.
Page 337
Appendix F: Balancing Photoresistors · Page 323 Calibrating Using a Linear Approximation The photoresistor is often referred to as a non-linear device. In other words, if it returns one measurement at one brightness, that doesn’t mean that the measurement will be five times as large when the light is five times as bright.
Page 338
Page 324 · Robotics with the Boe-Bot − − − − − − − − − − − − − − − − − − Once you’ve solved for m, you can plug m back into either of the two y = mx + b equations you started with to get b.
Page 339
Appendix F: Balancing Photoresistors · Page 325 Now, we know how to correct the variable so that it reports values similar to timeLeft variable in this narrow range of light levels: timeRight × timeLeft timeLeft adjusted A Linear Equation in PBASIC In most programming languages for PCs, this equation could be entered as-is.
Page 340
Page 326 · Robotics with the Boe-Bot √ Calculate the values of m you will use with the */ operator by multiplying m by 256. √ Substitute your value m and this line of code from BalancePhtoresistors.bs2: timeLeft = (timeLeft */ 351) + 7 √...
Point both the IR LEDs and detectors straight forward. √ Place the Boe-Bot in front of a wall with a white sheet of paper as the IR target. √ Place the Boe-Bot so that its IR LEDs are 2.5 cm away from the paper target.
Page 344
Page 330 · Robotics with the Boe-Bot ' -----[ Initialization ]----------------------------------------------------- DEBUG CLS, "Click transmit windowpane,", CR, "then press enter to begin", CR, "frequency sweep...", CR, CR, " OBJECT", CR, "FREQUENCY DETECTED", CR, "--------- --------", CR ' -----[ Main Routine ]-------------------------------------------------------...
Page 345
Appendix G: Tuning IR Distance Detection · Page 331 Figure G-1 Debug of Frequency Data The BASIC Stamp has been programmed to make the Debug Terminal display a “Yes” if an object was detected and a “No” if an object was not detected. Figure G-1 shows that the left sensor’s region of good signal response is between 36500 and 42500.
Page 346
√ Record five more data sets at this distance. √ Keep on backing up the Boe-Bot by 2.5 cm at a time and recording the five frequency sweep data sets between each distance adjustment. √ When the Boe-Bot has been backed up by 20 cm, the frequency sweep will display mostly, if not all ”No”...
Page 347
Appendix G: Tuning IR Distance Detection · Page 333 readings at a particular frequency. Note this frequency as a reliable measurement for the dividing line between Zone 0 and Zone 1. √ At each of the remaining five distances, find a frequency for which the output values have just become stable.
Appendix H: Boe-Bot Navigation Contests · Page 335 Appendix H: 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.
Page 350
Page 336 · 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.
Page 351
Appendix H: Boe-Bot Navigation Contests · Page 337 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. Table H-1: Line Following Scoring...
Page 352
Page 338 · Robotics with the Boe-Bot conditions. The maze is a classical two-dimensional proper maze: there is a single path from the start to the finish and there are no islands in the maze. Both the entrance and exit are located on outside walls.
Page 358
Page 344 · Robotics with the Boe-Bot programs RETURN, 140 rotational velocity, 115 saving, 26, 27 RPM, 115 proportional constant, 278 rubber band tire, 97 proportional control, 277 rubber grommet, 92, 96 prototyping area - S - input/output pins, 311...
Page 359
Index · Page 345 standoffs, 92, 100, 167 - U - start/reset indicator, 106 US232B, 14 StartValue, 74 USB to Serial Adapter, 13, 14 STEP StepValue, 75 USB to Serial Adaptor, 5 stepValue, 75 - V - STOP, 248 straightening the trajectory, 130 VAR, 71 subroutine call, 140, 141 variable, 71...
Page 360
Parts and quantities in the various Boe-Bot Robot kits are subject to change without notice. Parts may differ from what is shown in this picture. Please contact stampsinclsss@parallax.com if you have any questions about your kit.
Need help?
Do you have a question about the Boe-Bot and is the answer not in the manual?
Questions and answers