27404 Parallax Inc, 27404 Datasheet

COMPETITION RING FOR SUMOBOT

27404

Manufacturer Part Number
27404
Description
COMPETITION RING FOR SUMOBOT
Manufacturer
Parallax Inc
Datasheet

Specifications of 27404

Accessory Type
Hobby and Education
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Contains lead / RoHS non-compliant
For Use With/related Products
SumoBot®
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Contains lead / RoHS non-compliant
Applied Robotics with the
SumoBot
Student Guide
VERSION 1.0

Related parts for 27404

27404 Summary of contents

Page 1

Applied Robotics with the SumoBot Student Guide VERSION 1.0 ...

Page 2

... HomeWork Board, Parallax, and the Parallax logo are trademarks of Parallax Inc. If you decide to use trademarks of Parallax Inc. on your web page or in printed material, you must state that "(trademark trademark of Parallax Inc.”, “upon the first appearance of the trademark name in each printed document or web page ...

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 ...

Page 4

...

Page 5

Preface........................................................................................................................iii Introduction................................................................................................................ iii Educator Resources.................................................................................................. iv The Stamps In Class Educational Series .................................................................. iv Foreign Translations...................................................................................................v Special Contributors .................................................................................................. vi Chapter #1: Mechanical Adjustments ......................................................................7 Before You Get Started ..............................................................................................7 Small Adjustments can Make a Big Difference ..........................................................7 ACTIVITY #1: ...

Page 6

ACTIVITY #3: Using Peripheral Vision...................................................................164 ACTIVITY #4: Introduction to State Machines and Diagrams ................................170 ACTIVITY #5: Search Pattern and Tawara Avoidance ..........................................176 ACTIVITY #6: Fully Functional Sumo Example Programs.....................................186 Summary................................................................................................................203 Chapter #5: Debugging and Datalogging ............................................................ 207 Seeing what it ...

Page 7

Preface INTRODUCTION Robotics is currently enjoying ever increasing popularity with students. Especially when it involves a contest or competition, enthusiasm runs high as participants put everything they've got into their robots in hopes of winning top honors. With this in ...

Page 8

... As of this 1.0 revision, there are no answer keys or teachers guides available. Parallax does, however, have many resources and a support forum specially designed for instructors to use as a collaborative tool. Instructors should contact Parallax Inc. directly for more details. THE STAMPS IN CLASS EDUCATIONAL SERIES ...

Page 9

... Sensors”, Student Guide, Version 1.3, Parallax Inc., 2003 “Basic Analog and Digital”, Student Guide, Version 1.3, Parallax Inc., 2004 “Industrial Control”, Student Guide, Version 1.1, Parallax Inc., 1999 Educational Project Kits: Elements of Digital Logic, Understanding Signals and Experiments with Renewable ...

Page 10

... SPECIAL CONTRIBUTORS Parallax Inc. would like to recognize the Education Team members who made this book possible: Education and Project Manager Aristides Alvarez, Author and Engineer Andy Lindsay, Technical Illustrator Rich Allred, Graphic Designer Jen Jacobs, and Technical Editor Stephanie Lindsay. Special thanks also go to Ryan Clarke in Tech Support and Kris Magri in Education for their insightful and speedy review, and, as always, to Ken Gracey, the founder of Parallax Inc.’ ...

Page 11

Chapter #1: Mechanical Adjustments BEFORE YOU GET STARTED To complete the activities in this book, you will need to build, program and test two complete SumoBot robots by following the activities in the SumoBot Manual. Also, since Applied Robotics with ...

Page 12

The less friction, the more easily the SumoBot slips, which means it can no longer push as hard. There are two ways to increase the friction between the tire tread and sumo ring. First, increase the SumoBot's weight, ...

Page 13

Setting up the SumoBot Competition Ring Poster The SumoBot robot and SumoBot Robot Competition Ring poster are for indoor use only. For best results, follow these setup instructions: √ Unfold the SumoBot Competition Ring poster, and re-fold it the opposite ...

Page 14

Testing Plow Adjustments A simple program to make each SumoBot go forward should be used to test the plows. This eliminates the possibility of IR object detectors interfering with the SumoBot's forward motion. For example, if one of the SumoBot's ...

Page 15

Repeat five to ten times to be sure which SumoBot's plow adjustment has the advantage. √ Adjust the plow of the SumoBot that appeared to lose more often, and repeat the test. √ When you are confident that one ...

Page 16

DEBUG "Main program running..." -----[ Main Routine ]------------------------------------------------------- FOR counter = 1 TO 100 PULSOUT ServoLeft, 850 PULSOUT ServoRight, 650 PAUSE 20 NEXT DEBUG "Done!", CR, "Press/release reset", CR, "twice to restart...", CR END Understanding Forward100Pulses.bs2 When you ...

Page 17

Reset button, then it ends the program ends. If you have already completed Robotics with the Boe-Bot, the forward motion code in Forward100Pulses.bs2's Main Routine should ...

Page 18

Figure 1-4 SumoBot Servo Connections The instructions that make the SumoBot move forward starts with these ServoLeft PIN ServoRight PIN The SumoBot's left servo is connected to P13, so I/O pin P13 is given the name . Likewise, P12 is ...

Page 19

Do not adjust your plows. The strategies presented in this book will use the head-on approach. You can modify your programs (and the plows) to optimize for different approach angles, but wait until after Chapter 5. √ Test a variety ...

Page 20

A notebook for your observations - keep notes on the various results you observe for developing wrestling strategies. ACTIVITY #2: PREVENTING SERVO SLOWDOWN A SumoBot that executes certain maneuvers more quickly will have an edge over a slower opponent. One ...

Page 21

Figure 1-6 Top Speed vs. Low Time As mentioned earlier, taking too much time between pulses to check sensors can cause the servos to slow down. IR object detectors don't take a very big bite out of the low time ...

Page 22

With a couple modifications to Forward100Pulses.bs2 from Activity #1, you'll be ready to go. √ Save Forward100Pulses.bs2 as ForwardLowTimeTest.bs2. √ Add a constant declaration: LowTime LowTime CON √ Change the FOR...NEXT substitute the constant for the 20 in the LowTime ...

Page 23

Compare the results of the two trials and determine which program gives the SumoBot better performance. ' -----[ Program Description ]------------------------------------------------ ' Applied Robotics with the SumoBot - ForwardLowTimeTest.bs2 ' SumoBot goes forward indefinitely. ' the forward motion. ' ...

Page 24

LOOP DEBUG "Press/release reset", CR, "twice to restart...", CR END Your Turn - More Pulses, Less Distance Chapter 4, Activity #3 in Robotics with the Boe-Bot demonstrates how the amount of time a servo turns translates to distance traveled. When ...

Page 25

The distance traveled will not be exactly the same because the servos don't turn as fast with 40 ms pauses. This means that you'll probably have to use a little less than twice as many pulses with 20 ms pauses ...

Page 26

Run the modified program. √ Repeat the 10 second measurement and record the servo speed. √ Keep increasing the LowTime obvious speed decay. √ Record the maximum LowTime SumoBot in your notes for future reference. Your Turn - Wheel ...

Page 27

Scales that show both ounces and grams are not uncommon, likewise with scales that show both kilograms and pounds. They all appear to work because they are being used on the Earth's surface. When astronauts took equipment from the earth ...

Page 28

Since weight is a force, and gravity is a form of acceleration, an equation you will find useful in your calculations is: = × The acceleration due to gravity is 9.8 m/s Engineering system. Problem: An object ...

Page 29

If you measure an object's mass certain number of grams, converting to kilograms is a matter of using the conversion factor that will make the units you don't want cancel out. Problem: You measured your mass to ...

Page 30

These unit conversions take some practice; here are ...

Page 31

Figure 1-8 also shows a close-up of the contact surfaces, where little components of the force you apply to the block and the frictional forces are opposing each other. While some of the frictional forces actually do come from the ...

Page 32

− indicates that the normal force pushing back just as hard as the object's weight is pushing down on the surface. This has to ...

Page 33

To appreciate how different the coefficients of friction can be for different pairs of materials, take a look at Table 1-2. Table 1-2: Examples of Coefficients of Friction Materials Rubber on Concrete Copper on steel Ice on ice Strategy Consideration: ...

Page 34

Figure 1-10 Friction vs. Applied Forces Another Strategy Consideration Figure 1-9 shows that the SumoBot can exert its highest force of friction just before losing traction. After it starts slipping, it can't push as hard against its opponent because its ...

Page 35

Coefficients of friction do not have units. coefficient of friction, multiplied by the normal force. There are no units that need to cancel each other out. For example, if you start with a normal force that's in newtons, and multiply ...

Page 36

Since we already know that the forces of the block on the table in both the x and y axis directions. ∑ ∑ − ...

Page 37

Next, convert to the corresponding units of force (newtons × × 9 ...

Page 38

Problem: The coefficient of static friction for two surfaces is 0.1 (pretty slippery). How much force will it take to get weight to start to slide if the contact surfaces are level? Solution: It takes 1 lb ...

Page 39

Don't worry if you don't happen to have a gram scale or pulley and attachment. Thanks to the popularity of calorie counting, dietary scales can be purchased at most food markets and drug stores for under $10 (US). Pulleys and ...

Page 40

When you have constructed this setup, follow these steps. √ Draw free body diagrams and write the equations for Figure 1-14. Use the problem and solution with Figure 1-11 and Figure 1-12 as your guide. √ Record the SumoBot's weight ...

Page 41

Use your weights and the equations introduced in this activity to calculate the coefficients of static and kinetic friction for the SumoBot tire treads and the sumo ring surface. √ Put the SumoBot on the scale, and add mass ...

Page 42

SUMMARY This chapter introduced a variety of mechanical adjustments you can make to the SumoBot. Adjusting the plow angle is one important consideration. Managing the pause time between servo pulses is another important consideration because it can result in slower ...

Page 43

What's the British Engineering unit of mass? 11. How does force relate to mass and acceleration? 12. What's the acceleration due to gravity in SI units? 13. What is an object's weight in terms of its mass and the ...

Page 44

It takes 70 lbs of force to start a 100 lb object sliding along a level surface. Calculate the coefficient of static friction between the object and the surface. 14. It takes force to start a ...

Page 45

Chapter #2: EEPROM Tricks and Program Tips The BASIC Stamp's EEPROM is a great tool for storing values that you don't want to get erased. After you've stored a value to EEPROM, it doesn't matter whether the power has been ...

Page 46

As the SumoBot programs get larger and more complex, both good EEPROM management and strict adherence to code conventions will make large and complex programs seem easy least, not nearly as hard as they might look. ACTIVITY #1: ...

Page 47

Figure 2-1 shows what the DATA addresses 0 to 31. It also points out the first byte address of each names. Keep in mind that the BASIC Stamp Editor makes each Symbol name a constant equal to the address of ...

Page 48

EEPROM stands for Electrically Erasable Reprogrammable Read Only Memory. EEPROM memory is nonvolatile. disconnect power, then reconnect power, and the values you stored will still be there. Compile-time vs. Run-time - DATA directives are processed when the BASIC Stamp Editor ...

Page 49

READ RunStatus, temp DEBUG DEC temp, CR DEBUG "Address of UndefData........", DEC UndefData, CR, CR DEBUG "Address of Alphabet........", DEC Alphabet, CR DEBUG "Values stored........." FOR counter = READ Alphabet + counter, temp DEBUG temp PAUSE 200 ...

Page 50

For example, 0 7C3 = (3 × × × ...

Page 51

Modify the RunStatus DATA RunStatus DATA @10, Word 500 √ Modify the command that reads the EEPROM byte at the like this: READ RunStatus, Word temp √ Test the program to make sure it can retrieve and display 500. ...

Page 52

READ EepromCounter, temp To make the program count the number of consecutive resets, simply add 1 to the value of and write it back to the EEPROM byte at the temp time the program starts, the value the temp = ...

Page 53

WRITE EepromCounter, temp temp = temp - 1 IF temp = 0 THEN DEBUG "Since download, you have", CR, "pressed Reset ", DEC temp, " times.", CR ELSE DEBUG CRSRX, 11, "...", DEC temp, " ...

Page 54

Here is an statement you can use to determine whether the value of IF...THEN odd or even in ResetButtonCounter.bs2: IF temp.BIT0 = 0 THEN DEBUG DEC ...

Page 55

Figure 2-3 Debug Terminal Transmit and Receive Windowpanes Transmit Windowpane Type each value here, then press Enter. Receive Windowpane Prompts you to enter values and replies into the Transmit Windowpane. Illustrating Many Jobs with a Few Variables The and variables ...

Page 56

DEBUG CR, "Enter values", CR, "between 100 and 1000", CR, "Press 0 (zero) when done", CR, ">" counter = 0 DO UNTIL counter > temp = 0 DEBUGIN DEC temp WRITE Values + counter, Word ...

Page 57

DEBUG CRSRX, 0, DEC5 temp, CRSRX temp > compare THEN DEBUG "greater than" ELSEIF temp < compare THEN DEBUG "less than" ELSE DEBUG "equal to" ENDIF DEBUG CR counter = counter + 2 LOOP ENDIF Example Program: ThreeVariablesManyJobs.bs2 ...

Page 58

Get values and store them to EEPROM DEBUG CR, "Enter values", CR, "between 100 and 1000", CR, "Press 0 (zero) when done", CR, ">" counter = 0 DO UNTIL counter > temp = 0 ...

Page 59

LOOP ENDIF DEBUG CR, "All done!" END ACTIVITY #3: PROGRAM ON/OFF WITH RESET It's really handy to be able to start and halt a sumo wrestling program by pressing and releasing the SumoBot's Reset button. This technique was first introduced ...

Page 60

Subroutine - Reset ]------------------------------------------------- Reset: READ RunStatus, temp temp = temp + 1 WRITE RunStatus, temp IF (temp.BIT0 = 1) THEN ...

Page 61

As you keep pressing the Reset button, the odd/even pattern continues, as does the program's alternation between the "Press/release Reset..." and "Program running..." messages. Example Program: TestResetButton.bs2 √ Enter, save, and download TestResetButton.bs2. ...

Page 62

END ' -----[ Subroutine - Reset ]------------------------------------------------- Reset: READ RunStatus, temp temp = temp + 1 WRITE RunStatus, temp IF (temp.BIT0 = 1) THEN DEBUG CLS, "Press/release Reset", CR, "button..." END ELSE DEBUG CR, "Program running..." ENDIF RETURN ' -----[ ...

Page 63

Building and Testing the LED and Piezospeaker Circuits The LED and piezospeaker circuit shown in Figure 2 interesting combination of the individual circuits. Instead of connecting the LED and piezospeaker to separate I/O pins, both circuits are connected ...

Page 64

LedSpeaker PIN 5 After declaring this directive, the name PIN an output. The BASIC Stamp Editor examines each command with argument and decides whether to send an output to the pin or store the input value sensed by the pin. ...

Page 65

FOR counter = TOGGLE LedSpeaker PAUSE 250 NEXT DEBUG CR, "Speaker playing tone" FREQOUT LedSpeaker, 2000, 3000 DEBUG CR, "All done." END Your Turn - Playing Musical Notes The command can be handy for storing brief sequences ...

Page 66

Parts List (1) Jumper wire (1) LED - red (1) 1 Resistor - 470 Ω (yellow-violet-brown) (1) 1 Resistor - 10 kΩ (brown-black-orange) Figure 2-5 Pushbutton Circuit added to LED and Piezospeaker A directive can also be used for P6: ...

Page 67

Example Program: TestPushbutton.bs2 √ Enter, save, and run TestPushButton.bs2. √ The Debug Terminal should display a message, and then start displaying a series of repeating zeros every 1/10 second. √ Watch the Debug Terminal as you press, hold, and release ...

Page 68

PIN 6 ' -----[ Initialization ]----------------------------------------------------- DEBUG CLS, "Press/hold/release" , CR, "pushbutton on", CR, "breadboard..." -----[ Main Routine ]------------------------------------------------------- DO DEBUG BIN1 pbSense PAUSE 100 LOOP Your Turn - Controlling the LED with the Pushbutton After adding ...

Page 69

ACTIVITY #5: PUSHBUTTON PROGRAM MODE SELECTION In some competitions, changing strategy between sumo rounds could make a big difference in your SumoBot's standing. This activity introduces a simple technique you can use to select the SumoBot's mode of operation based ...

Page 70

Subroutine - Mode_Select ]------------------------------------ ' Selects mode of operation Mode_Select: DEBUG CR, CR, "Release pushbutton after", CR, "number of ...

Page 71

CASE 1 DEBUG "one" CASE 2 DEBUG "two" CASE 3 DEBUG "three" CASE 4 DEBUG "four" CASE 5 DEBUG "five" ENDSELECT ENDIF END Strategy Tip Your SumoBot programs could use this mode argument any number of ways. For example, it ...

Page 72

EEPROM Data ]-------------------------------------------------------- ModeSelect DATA 0 ' -----[ Initialization ]----------------------------------------------------- IF pbSense = 1 THEN GOSUB Mode_Select ' -----[ Main Routine ]------------------------------------------------------- READ ModeSelect, temp IF temp = 0 THEN DEBUG CR, "No mode selected", CR, "Hold down ...

Page 73

NEXT PAUSE 1000 IF pbSense = 0 THEN WRITE ModeSelect, temp EXIT ENDIF NEXT RETURN Your Turn √ Try modifying PushbuttonMode.bs2 so that you can choose different forward distances to make the SumoBot travel in case you have to repeat ...

Page 74

One of the most important ingredients of modular programs is keeping the same naming conventions for variables. For example, in this book, used to receive and manipulate stored information and sensor measurements. After decisions are made based on temp next ...

Page 75

While all the steps up to this point were purely mechanical, the Initialization section will take some thought. There are several options. You can put the from PushbuttonMode.bs2's initialization as the first, second or third step. To make the decision, ...

Page 76

I/O Definitions ]---------------------------------------------------- LedSpeaker PIN 5 ' ---> Pasted from PushbuttonMode.bs2 <--- pbSense PIN 6 ' -----[ Variables ]---------------------------------------------------------- temp VAR Word counter VAR Byte ' -----[ EEPROM Data ]-------------------------------------------------------- RunStatus DATA 0 ' ---> Pasted from PushbuttonMode.bs2 ...

Page 77

DEBUG "five" ENDSELECT ENDIF ResetTest: DEBUG CR, "Done!" END ' -----[ Subroutine - Reset ]------------------------------------------------- Reset: READ RunStatus, temp temp = temp + 1 WRITE RunStatus, temp IF (temp.BIT0 = 1) THEN DEBUG CLS, "Press/release Reset", CR, "button..." END ELSE ...

Page 78

PAUSE 100 FREQOUT LedSpeaker, 100, 4000 NEXT PAUSE 1000 IF pbSense = 0 THEN WRITE ModeSelect, temp EXIT ENDIF NEXT RETURN Your Turn - Testing the New Program There should be two ways to set the program mode. The first ...

Page 79

SUMMARY This chapter introduced a variety of EEPROM and program management techniques. EEPROM management focused on declaring and naming EEPROM bytes and groups of bytes used in the program. Techniques for counting resets were introduced for both toggling between different ...

Page 80

What is the decimal number for hexadecimal-E? 10. What PBASIC operator allows you to examine individual bits in larger variables? 11. What does the IF...THEN variable is even? 12. What variable stores the binary 1/0 values sensed by 13. ...

Page 81

Chapter #3: Sensor Management The SumoBot's sensors are critical components to its performance in the Sumo ring. To get the most out of the sensors that come in the SumoBot Robot Competition Kit, it's important to have a better understanding ...

Page 82

ACTIVITY #1: TESTING AND TUNING INFRARED OBJECT DETECTORS Figure 3-1 shows the SumoBot and the locations of its front left and front right infrared (IR) object detectors. The IR LED and receivers were plugged into headers X8 and X9 and ...

Page 83

The right column shows the components that you plugged into the header, the IR receiver, and shielded IR LED. Figure 3-2 IR Object Detection Circuits Testing the front left IR detector involves sending a 38500 kHz signal ...

Page 84

If the IR receiver is sending P11, it means it doesn't see any reflected infrared. If this is the case, the BASIC Stamp stores the value 1 in the P11 input register bit the IR receiver does ...

Page 85

The IR receivers are active-low, meaning they send a low signal to signify the active condition (IR signal detected). When your SumoBot is dealing with lots of sensors, the programming and trouble shooting will all be easier if they are ...

Page 86

Example Program - TestFRontIrObjectDetectors.bs2 √ Enter, save, and run TestFrontIrObjectDetectors.bs2. √ Point your SumoBot away from nearby objects. It may actually detect walls as far away. If your detectors are pointing slightly downward, they will ...

Page 87

Title ]-------------------------------------------------------------- ' Applied Robotics with the SumoBot - TestFrontIrObjectDetectors.bs2 ' This program tests the IR object detectors mounted on the X8 and X9 headers ' on the front of the SumoBot. ' {$STAMP BS2} ' {$PBASIC 2.5} ...

Page 88

Your Turn - Headlight Adjustments A small change in the direction the SumoBot's IR LEDs are pointing can make a huge difference in its performance. Remember this when testing the competition code at the end of chapter 4 and the ...

Page 89

Testing for Sources of IR Interference Fluorescent lights have a part called a ballast built into them. The ballast is responsible for amplifying the AC outlet voltage to a level that is high enough to make the gas inside the ...

Page 90

Main Routine ]------------------------------------------------ DO irLF = ~IrSenseLF irRF = ~IrSenseRF IF irLF = 1 OR irRF = 1 THEN DEBUG "IR interference detected!!!", CR FOR counter = FREQOUT LedSpeaker, 50, 4000 PAUSE 50 NEXT ENDIF ...

Page 91

Always test for and eliminate sources of IR interference near your SumoBot Competition Ring. ' -----[ Title ]-------------------------------------------------------------- ' Applied Robotics with the SumoBot - IrInterferenceSniffer.bs2 ' This program tests for IR interference from other fluorescent lights, ' handheld remotes, ...

Page 92

Testing for Electrical Continuity The leads on the IR LEDs and receivers tend to be thinner than jumper wires and other component leads. The X8 and X9 sockets on some SumoBot boards may also have sockets with slightly larger holes ...

Page 93

X8 and X9 sockets along with the component leads. Figure 3-4 shows examples. If the IR component leads already have a snug fit in the X8/X9 sockets, ...

Page 94

Figure 3-5 Opponent vs. Distraction If your SumoBot has a tendency to get distracted by nearby objects, there are ways to make it more nearsighted. The sensitivity of the IR receivers can be adjusted by changing either the resistance in ...

Page 95

Debug Terminal displays a "yes" if the IR receiver detected an object "no" didn't. Notice how the Debug Terminal shows a lot more "yes" detections for the 0.6 m distance test ...

Page 96

The next example program TestIrFrontObjectDetectors.bs2. argument is replaced with a Freq1 swept from 36000 to 42000 in steps of 500 by a way to perform a frequency sweep with the IR LEDs and capture the IR receivers' frequency responses. ' ...

Page 97

If zero "yes" readings appear, move the SumoBot 5 cm closer to the wall. If several "yes" readings appear, move the SumoBot 5 cm farther from the wall. √ Press and release the Reset button to refresh the Debug ...

Page 98

Initialization ]----------------------------------------------------- DEBUG CLS, "FRONT IR DETECTORS", CR, "Frequency Left Right", CR, "--------- ---- -----" -----[ Main Routine ]------------------------------------------------------- FOR frequency = 36000 TO 42000 STEP 500 FREQOUT IrLedLF, 1, frequency irLF = ~IrSenseLF FREQOUT IrLedRF, ...

Page 99

Modify TestIrFrontObjecDetectors.bs2 so that it has useful versions of the directive. IrFreq CON ACTIVITY #2: A CLOSER LOOK AT THE QTI LINE SENSORS The SumoBot shown in Figure 3-7 has its QTI line sensors mounted under ...

Page 100

Figure 3-8 Front Left and Right QTI Schematics Each QTI has four components mounted on its PCB, a 220 Ω resistor, a 470 Ω resistor, a 0.01 µF capacitor, and a QRD1114 reflective object sensor. The way these parts are ...

Page 101

The QRD1114 has an IRLED in it that shines IR light on the surface it's facing. Unlike the IR object detectors we just finished testing, this device does not need to flash the IR on/off at 38.5 kHz. That's because ...

Page 102

V RCTIME named : temp HIGH 9 PAUSE 1 RCTIME 9, 1, temp Remember that P10 has to be set high to turn on the QTI, and low to turn ...

Page 103

Figure 3-11 QTI RC-Decay for Different Surfaces If there is no surface to reflect IR from the QTI's IR LED, the only source of infrared for the IR transistor's base is the ambient light in the room. That might be ...

Page 104

Figure 3-12 White Tawara vs. Black Sumo Ring Surface Example Program - TestFrontQtiLineSensors.bs2 Keep well away from direct sunlight and other sources of bright light. Your SumoBot and SumoBot Robot Competition Ring poster should be well away from any sources ...

Page 105

BS2} ' {$PBASIC 2.5} ' -----[ I/O Definitions ]--------------------------------------------------- qtiPwrLeft PIN 10 qtiSigLeft PIN 9 qtiPwrRight PIN 7 qtiSigRight PIN 8 ' -----[ Variables ]---------------------------------------------------------- qtiLeft VAR Word qtiRight VAR Word ' -----[ Initialization ]----------------------------------------------------- DEBUG CLS, "FRONT ...

Page 106

Your Turn - Detecting Tilt What if the QTIs were to give you a unique signature when the SumoBot is tilted backward? √ Try tilting the SumoBot while it's sitting on the sumo ring. √ Are the readings different from ...

Page 107

QTI readings for the black surface and use them as a basis for setting a threshold value to decide whether the QTIs are "seeing" black or white. As you may have noticed from Activity #2, white QTI ...

Page 108

Figure 3-13 White Tawara vs. Black Sumo Ring Surface Example Program: QtiSelfCalibrate.bs2 √ Place the SumoBot on the black part of your practice ring. Lighting Reminder Your SumoBot and SumoBot Robot Competition Ring poster should be well away from any ...

Page 109

BS2} ' {$PBASIC 2.5} ' -----[ I/O Definitions ]--------------------------------------------------- qtiPwrLeft PIN 10 qtiSigLeft PIN 9 qtiPwrRight PIN 7 qtiSigRight PIN 8 ' -----[ Variables ]---------------------------------------------------------- qtiLeft VAR Word qtiRight VAR Word qtiThreshold VAR Word ' -----[ Initialization ]----------------------------------------------------- ...

Page 110

DEBUG "Black" ENDIF PAUSE 100 LOOP ' -----[ Subroutine - Read_Line_Sensors ]------------------------------------- Read_Line_Sensors: HIGH qtiPwrLeft HIGH qtiSigLeft PAUSE 1 RCTIME qtiSigLeft, 1, qtiLeft LOW qtiPwrLeft HIGH qtiPwrRight HIGH qtiSigRight PAUSE 1 RCTIME qtiSigRight, 1, qtiRight RETURN Your Turn - QTI ...

Page 111

Save and then run the modified program, starting with both QTIs over a black portion of the practice ring. √ Repeat your tests with the tawara line, and verify that the SumoBot is making the correct navigation decisions. ACTIVITY ...

Page 112

With some creative programming, you can actually check as many QTIs as you want, and it will only a fraction of the time that it takes to check just one QTI with the command when it's detecting black. This activity ...

Page 113

The code block below takes less time than an surface. It starts like it's going to take an waiting 1 ms for the V to approach 5 V. Instead of taking an 0 code bock changes P9 from output to ...

Page 114

Figure 3-15 Pulse-Decay Trick Timing Accounting for Command Execution Times Figure 3-15 shows the ideal situation, ignoring the amount of time it takes for the BASIC Stamp 2 to transition from one command to the next. Subtracting 220 from the ...

Page 115

Example Program: QtiPulseTrickLeft.bs2 The QtiPulseTrickLeft.bs2 program verifies that this technique works. carefully. Especially make sure you can match the commands that deal with P5 and P9 to the timing diagram in Figure 3-15. √ Make sure the left QTI is ...

Page 116

Your Turn - Incorporating the Right QTI Here's the interesting part, you can add another QTI measurement to the same block of code that performed the time measurement on the left QTI. The routine will take approximately the same amount ...

Page 117

Incorporating the Pulse-Decay Trick into Another Program Here is how to incorporate the test code from QtiPulseTrickLeft.bs2 into TestFrontQtiLineSensors.bs2 from Activity #2. The first step is to declare a dummy name for P6. DummyPin PIN Also declare a couple of ...

Page 118

Read_Line_Sensors: HIGH qtiPwrLeft HIGH qtiPwrRight HIGH qtiSigLeft HIGH qtiSigRight PAUSE 1 INPUT qtiSigLeft INPUT qtiSigRight PULSOUT DummyPin, qtiThreshold qtiStateLeft = qtiSigLeft qtiStateRight = qtiSigRight LOW qtiPwrLeft LOW qtiPwrRight RETURN The last step through the Main Routine and ...

Page 119

I/O Definitions ]--------------------------------------------------- qtiPwrLeft PIN 10 qtiSigLeft PIN 9 qtiPwrRight PIN 7 qtiSigRight PIN 8 DummyPin PIN 6 ' -----[ Variables ]---------------------------------------------------------- qtiStateLeft VAR Bit qtiStateRight VAR Bit qtiLeft VAR Word qtiRight VAR Word qtiThreshold VAR Word ' ...

Page 120

LOOP ' -----[ Subroutine - Calibrate_Qtis ]---------------------------------------- Calibrate_Qtis: HIGH qtiPwrLeft HIGH qtiSigLeft PAUSE 1 RCTIME qtiSigLeft, 1, qtiLeft LOW qtiPwrLeft HIGH qtiPwrRight HIGH qtiSigRight PAUSE 1 RCTIME qtiSigRight, 1, qtiRight GOSUB Read_Line_Sensors qtiThreshold = (qtiLeft + qtiRight qtiThreshold ...

Page 121

Your Turn - Active High vs. Active Low At present, the alert for the SumoBot encountering the white tawara line is when either or qtiStateLeft qtiStateRight change this so that the qtiState √ Use the invert bits operator, the tilde ...

Page 122

Figure 3-16 Sensors and Indicators Built on the Breadboard IR Object Detector (Left Side) Building and Testing the Side-Mounted IR Object Detector Circuits Figure 3-17 shows schematics of the side mounted IR LED and IR receiver pairs that comprise the ...

Page 123

Figure 3-17 Side-mounted IR Object Detection Circuits Left Figure 3-18 Wiring Diagram Right ...

Page 124

You will see that TestSideIrObjectDetectors.bs2 is just a modified version of TestFrontIrObjectDetectors.bs2. Different and receivers are declared, likewise for bit variables that store the IR receivers' output states. All of these different names are also updated in the statements, and ...

Page 125

Example Program: TestSideIrObjectDetectors.bs2 ' -----[ Title ]-------------------------------------------------------------- ' Applied Robotics with the SumoBot - TestSideIrObjectDetectors.bs2 ' This program tests only IR object detectors on the SumoBot's breadboard ' that look to the left and right. ' front. ' {$STAMP BS2} ...

Page 126

Your Turn - Testing All Four Your SumoBot will eventually need to check and process information from all four IR object detectors each time through the Main Routine’s matter of incorporating elements from the IR object detector programs from this ...

Page 127

Start by opening all of the following programs: TestLedSpeaker.bs2 o TestPushButton.bs2 o TestFrontIrObjectDetectors.bs2 o QtiPulseDecayTrick.bs2 o TestSideIrObjectDetectors.bs2 o √ Save QtiPulseDecayTrick.bs2 as TestAllSensors.bs2 √ Copy and paste the I/O definitions and variables from the other programs into your new ...

Page 128

So, the Main Routine of TestPushButton.bs2 will not serve our purpose, but this simple subroutine will. √ Add a Read_Pushbutton Read_Pushbutton: INPUT pbSense pushbutton = pbSense RETURN Some of the initialization ...

Page 129

PIN 10 qtiSigLeft PIN 9 qtiPwrRight PIN 7 qtiSigRight PIN 8 DummyPin PIN 6 IrLedLF PIN 4 IrSenseLF PIN 11 IrLedRF PIN 15 IrSenseRF PIN 14 IrLedLS PIN 2 IrSenseLS PIN 1 IrLedRS PIN 3 IrSenseRS PIN 0 pbSense ...

Page 130

Main Routine ]------------------------------------------------------- DO GOSUB Read_Line_Sensors GOSUB Read_Object_Detectors GOSUB Read_Pushbutton DEBUG HOME, ? irLS, ? irLF, ? irRF, ? irRS, ? qtiStateLeft, ? qtiStateRight, ? pushbutton PAUSE 100 LOOP ' -----[ Subroutine - Calibrate_Qtis ]---------------------------------------- Calibrate_Qtis: HIGH qtiPwrLeft ...

Page 131

HIGH qtiPwrLeft HIGH qtiPwrRight HIGH qtiSigLeft HIGH qtiSigRight PAUSE 1 INPUT qtiSigLeft INPUT qtiSigRight PULSOUT DummyPin, qtiThreshold qtiStateLeft = ~ qtiSigLeft qtiStateRight = ~ qtiSigRight LOW qtiPwrLeft LOW qtiPwrRight RETURN ' -----[ Subroutine - Read_Object_Detectors ]--------------------------------- Read_Object_Detectors: FREQOUT IrLedRS, 1, ...

Page 132

Your Turn - Cleaning up Names These variable declaration names have some room for improvement: irLS VAR irLF VAR irRF VAR irRS VAR qtiStateLeft VAR qtiStateRight VAR The main problem is that they are not really consistent. The object detector ...

Page 133

Repeat by using this feature to change √ Some of the comments may now be out of alignment. Go through the program and insert spaces to line the side comments back up to column 46. √ Save your modified ...

Page 134

VAR irLF VAR irRF VAR irRS VAR The best thing about this arrangement is that no other changes in the program have to be made. The program will still function normally, and you can display each bit value as ...

Page 135

Figure 3-22 shows an example of how these modified routines display the contents of the byte. But first let’s look at this line for a moment: sensors DEBUG CRSRXY BIN8 sensors , places the Debug Terminal cursor at ...

Page 136

In order from to BIT0 detectors - right side, right front, left front, left side. QTI line sensors - right front, left front, pushbutton. ACTIVITY #8: VARIABLE MANAGEMENT FOR LARGE PROGRAMS When you have a project with a lot ...

Page 137

VAR temp VAR multi VAR As mentioned earlier, a variable doesn't have to store the QTI decay black/white threshold value because it doesn't change after it is set at the beginning of the program. This makes it a ...

Page 138

RCTIME qtiSigLeft, 1, temp LOW qtiPwrLeft multi = temp HIGH qtiPwrRight HIGH qtiSigRight PAUSE 1 ' RCTIME qtiSigRight, 1, qtiRight RCTIME qtiSigRight, 1, temp ' qtiThreshold = (qtiLeft + qtiRight multi = (multi + temp ...

Page 139

PULSOUT DummyPin, qtiThreshold PULSOUT DummyPin, temp qtiLF = ~qtiSigLeft qtiRF = ~qtiSigRight . . . Remember, the goal of all this work is to make the program more easily expandable. The other goal is to make it so that ...

Page 140

IrLedRS PIN 3 IrSenseRS PIN 0 pbSense PIN 6 LedSpeaker PIN 5 ' -----[ Constants ]---------------------------------------------------------- IrFreq CON 38500 ' -----[ Variables ]---------------------------------------------------------- ' qtiLeft VAR Word ' qtiRight VAR Word ' qtiThreshold VAR Word temp VAR Word multi VAR ...

Page 141

DO GOSUB Read_Line_Sensors GOSUB Read_Object_Detectors GOSUB Read_Pushbutton DEBUG CRSRXY BIN8 sensors PAUSE 100 LOOP ' -----[ Subroutine - Calibrate_Qtis ]---------------------------------------- Calibrate_Qtis: HIGH qtiPwrLeft HIGH qtiSigLeft PAUSE 1 ' RCTIME qtiSigLeft, 1, qtiLeft RCTIME qtiSigLeft, 1, temp LOW qtiPwrLeft ...

Page 142

WRITE QtiThresh, Word multi RETURN ' -----[ Subroutine - Read_Line_Sensors ]------------------------------------- Read_Line_Sensors: HIGH qtiPwrLeft HIGH qtiPwrRight HIGH qtiSigLeft HIGH qtiSigRight PAUSE 1 READ QtiThresh, Word temp INPUT qtiSigLeft INPUT qtiSigRight ' PULSOUT DummyPin, qtiThreshold PULSOUT DummyPin, temp qtiLF = ~qtiSigLeft ...

Page 143

INPUT pbSense pushbutton = pbSense RETURN Your Turn - Program Cleanup √ Review the commented lines of code and their replacements. √ Remove the commented lines of code. √ Run the program and verify that it still works properly. ' ...

Page 144

SUMMARY This chapter reviewed how the SumoBot's IR detectors work, then introduced basic IR detector testing along with IR interference, electrical continuity, and IR receiver frequency response tests. Using these tests will help ensure that the SumoBot's IR detectors are ...

Page 145

What factors should you keep in mind when selecting a frequency for a given SumoBot ring? 12. What label designates the header with the front-left QTI sensor? 13. What connections does the SumoBot board make to the header with ...

Page 146

Projects 1. Write a program that beeps at different notes to tell you which sensor it detects. 2. Place an object on the SumoBot's left at a distance outside the SumoBot Competition Ring that the SumoBot can detect with only ...

Page 147

Chapter #4: Navigation Tips Effectively using four object detectors and two QTI line sensors for SumoBot navigation can seem a little daunting at first, especially when you consider that there are 64 different possible combinations of detected and not detected ...

Page 148

ACTIVITY #1: SERVO CONTROL WITH LOOKUP COMMANDS Since all the other subroutines in this book have utilized some combination of the and variables, why not make it so for servo control subroutines? This counter temp activity demonstrates a way to ...

Page 149

Figure 4-2 The Servo Control Loop The loop's FOR...NEXT EndValue will run. Every time through the loop takes about 24.6 ms times through the 24.6 ms loop takes about 41 × 0.0246 ≈ 1 second. argument to 82 ...

Page 150

With some experimentation, you can also control the speed of the servos too. Note from Figure 4-3 that the relationship between pulse width and rotational velocity is not simply linear. For example, a Duration as you increase to 710, 720, ...

Page 151

Applied Robotics with the SumoBot - ServoControlExample.bs2 ' {$STAMP BS2} ' {$PBASIC 2.5} counter VAR byte ' SumoBot goes forward 3 seconds. FOR counter = 1 TO 122 PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT ' SumoBot ...

Page 152

Your Turn - Using PIN Definitions and Constants Instead of the number 13 in the PULSOUT can use the directive PIN ServoLeft place of the number 12. Since we know that 650 is the speed-clockwise, a good constant name for ...

Page 153

Let's take a second look at that is 0, the command will copy 1046 to the counter LOOKUP 1, will copy 1175 to the note variable. If LOOKUP , and so on. note LOOKUP counter, [1046, 1175, 1319, 1397, 1580, ...

Page 154

Save the example program as LookupExampleYourTurn.bs2 √ Add these constant declarations with the C_6 CON 1046 D_6 CON 1175 E_6 CON 1319 F_6 CON 1397 G_6 CON 1580 A_6 CON 1760 B_6 CON 1976 C_7 CON 2093 √ Change ...

Page 155

The servo control subroutine will send pulse values to the servos. Constants for full speed counterclockwise ( FS_CCW ( will make the subroutine easier to write. NO_ROT) FS_CCW CON FS_CW CON NO_ROT CON Here is the subroutine. Remember that Pulse_Servos ...

Page 156

Example Program: ServoControlWithLookup.bs2 √ Enter and save ServoControlWithLookup.bs2 √ Move the 3-position switch on the SumoBot circuit board to position 1. √ Download the program to the SumoBot. √ Hold down the Reset button on the SumoBot circuit board, then ...

Page 157

NO_ROT CON 750 ' -----[ Variables ]---------------------------------------------------------- temp VAR Word counter VAR Byte maneuver VAR Nib ' -----[ Main Routine ]------------------------------------------------------- Test_Search_Pattern: DO FOR counter = maneuver = Forward GOSUB Pulse_Servos NEXT FOR counter = 1 TO ...

Page 158

Your Turn Here is a wider variety of maneuver constants along with extra servo pulse width rotation constants you will need to implement all 10 maneuvers. ' -----[ Constants ]--------------------------------------------------- ' SumoBot maneuver constants Forward CON Backward CON RotateLeft CON ...

Page 159

Modify the Pulse_Servos in the SumoBot maneuver constants list. √ For the and CurveLeft CurveRight can do a full circle in the ring without passing over the white tawara line (see Figure 4-4). Spend some time refining CurveLeft and ...

Page 160

If the SumoBots are already pushing each other and one of them does this maneuver, it will also give its opponent an opportunity to ...

Page 161

You can also program the SumoBot for more complex maneuvers, such as curving for a while, then rotating in place. With a limited amount of curve time, it gives the SumoBot a chance to get lined up with its opponent ...

Page 162

In the code below, every time the Main Routine calls , both the Servos_And_Sensors ( in this case) ...

Page 163

You can test this next example program by positioning the SumoBot so that neither of its IR object detectors see an object. Then place your hand in front of one of the detectors. The SumoBot should rotate toward your hand ...

Page 164

Title ]-------------------------------------------------------------- ' Applied Robotics with the SumoBot - FrontIrNavigation.bs2 ' When it sees an object with only one object detecting eye, it corrects ' it's heading until it sees the object with both eyes. ' {$STAMP BS2} ...

Page 165

VAR Word counter VAR Byte maneuver VAR Nib sensors VAR Byte irLS VAR sensors.BIT3 irLF VAR sensors.BIT2 irRF VAR sensors.BIT1 irRS VAR sensors.BIT0 ' -----[ Main Routine ]------------------------------------------------------- DO IF irLF = 1 AND irRF = 1 THEN maneuver ...

Page 166

RETURN ' -----[ Subroutine - Pulse_Servos ]------------------------------------------ Pulse_Servos: ' Pulse to left servo LOOKUP maneuver, [ FS_CCW, FS_CW, FS_CW, FS_CCW, NO_ROT, FS_CCW, LS_CCW, FS_CCW ], temp PULSOUT ServoLeft, temp ' Pulse to right servo LOOKUP maneuver, [ FS_CW, FS_CCW, FS_CW, ...

Page 167

ELSEIF irLF = 1 THEN DO UNTIL (irLF = 1 AND irRF = 1) OR counter > 15 maneuver = CurveLeft GOSUB Servos_And_Sensors counter = counter + 1 LOOP DO UNTIL (irLF = 1 AND irRF = 1) OR counter ...

Page 168

GOSUB Servos_And_Sensors counter = counter + 1 LOOP ELSE GOSUB Read_Object_Detectors ENDIF LOOP ACTIVITY #3: USING PERIPHERAL VISION When autonomous robots start a sumo match facing each other, the match tends to be more a battle of brawn than brains. ...

Page 169

Figure 4-8 Peripheral Vision for Opponent Detection Responding to an Object Detection on the Side This code for side IR object detection works about the same as the examples from the previous activity. They can be added to the example ...

Page 170

Example Program: FrontAndSideIrNavigation.bs2 The beauty in terminating the rotate loop as soon as one of the front IR detectors sees the object is that one of the other code blocks will then take over to get the SumoBot to face ...

Page 171

IrLedLF PIN 4 IrSenseLF PIN 11 IrLedRF PIN 15 IrSenseRF PIN 14 IrLedRS PIN 3 IrSenseRS PIN 0 ' -----[ Constants ]---------------------------------------------------------- ' SumoBot maneuvers Forward CON 0 Backward CON 1 RotateLeft CON 2 RotateRight CON 3 PivotLeft CON 4 ...

Page 172

IF irLF = 1 AND irRF = 1 THEN maneuver = Forward GOSUB Servos_And_Sensors ELSEIF irLF = 1 THEN counter = 0 DO UNTIL (irLF = 1 AND irRF = 1) OR counter > 15 maneuver = CurveLeft GOSUB Servos_And_Sensors ...

Page 173

GOSUB Read_Object_Detectors RETURN ' -----[ Subroutine - Pulse_Servos ]------------------------------------------ Pulse_Servos: ' Pulse to left servo LOOKUP maneuver, [ FS_CCW, FS_CW, FS_CW, FS_CCW, NO_ROT, FS_CCW, LS_CCW, FS_CCW ], temp PULSOUT ServoLeft, temp ' Pulse to right servo LOOKUP ...

Page 174

Your Turn - Limiting Rotation Unlike the front IR detectors, the loops for the side IR detectors do not limit the amount of rotation in place the SumoBot will perform. √ Add conditions to the DO UNTIL...LOOP to turn and ...

Page 175

However, the term "state machine" is commonly used to refer to finite state machines. Your SumoBot is without a doubt, a state machine. The last couple of example programs have used terms like "State = search pattern" and ...

Page 176

State diagrams can be visual aids for describing the different states in certain programs along with the conditions the programs use to transition from one ...

Page 177

Your Turn Figure 4-10 shows a modified version of the state machine diagram that involves a variable named . Because of the 100 ms pause between repeats of the counter in PushubttonLed.bs2, the DO...LOOP than or equal to 2 seconds ...

Page 178

LOOP ELSEIF irRF = 1 THEN counter = 0 DO UNTIL (irLF = AND irRF = 1) OR counter > 15 maneuver = PivotRight GOSUB Servos_And_Sensors counter = counter + 1 LOOP ELSE GOSUB Read_Object_Detectors ENDIF LOOP Software that is ...

Page 179

Figure 4-11 Hybrid State Machine Diagram √ Compare Figure 4-11 to the Main Routine from FrontIrNavigation.bs2 and verify that they describe the same state transitions. State diagrams are not a replacement for flowcharts. While state diagrams introduced in this activity ...

Page 180

Your Turn - Drawing a State Machine Diagram √ Try drawing a hybrid state machine diagram for the Main Routine in FrontAndSideIrNavigation.bs2 from this chapter's Activity #3. ACTIVITY #5: SEARCH PATTERN AND TAWARA AVOIDANCE Before your SumoBot will be ready ...

Page 181

Main Routine ]------------------------------------------------------- DO IF qtiLF = 1 THEN FOR counter = maneuver = Backward GOSUB Servos_And_Sensors NEXT FOR counter = maneuver = RotateRight GOSUB Servos_And_Sensors NEXT ELSEIF qtiRF = 1 THEN ...

Page 182

FOR counter = maneuver = RotateRight GOSUB Servos_And_Sensors IF sensors <> 0 THEN GOTO Next_State NEXT FOR counter = maneuver = RotateLeft GOSUB Servos_And_Sensors IF sensors <> 0 THEN GOTO Next_State NEXT FOR counter ...

Page 183

Press and hold the Reset button until you place it on the ring as shown in Figure 4-12. √ Let go of the Reset button, and compare your search pattern to the one shown in the figure. Does your ...

Page 184

DummyPin PIN 6 ' -----[ Constants ]---------------------------------------------------------- ' SumoBot maneuvers Forward CON 0 Backward CON 1 RotateLeft CON 2 RotateRight CON 3 PivotLeft CON 4 PivotRight CON 5 CurveLeft CON 6 CurveRight CON 7 ' Servo pulse width rotations FS_CCW ...

Page 185

Backward GOSUB Servos_And_Sensors NEXT FOR counter = maneuver = RotateRight GOSUB Servos_And_Sensors NEXT ELSEIF qtiRF = 1 THEN FOR counter = maneuver = Backward GOSUB Servos_And_Sensors NEXT FOR counter = 1 TO ...

Page 186

LOW qtiPwrLeft multi = temp HIGH qtiPwrRight HIGH qtiSigRight PAUSE 1 RCTIME qtiSigRight, 1, temp multi = (multi + temp multi = multi / 4 IF multi > 220 THEN multi = multi - 220 ELSE multi = ...

Page 187

Pause between pulses (remove when using IR object detectors + QTIs). PAUSE 20 RETURN ' -----[ Subroutine - Read_Line_Sensors ]------------------------------------- Read_Line_Sensors: HIGH qtiPwrLeft HIGH qtiPwrRight HIGH qtiSigLeft HIGH qtiSigRight PAUSE 1 READ QtiThresh, Word temp INPUT qtiSigLeft INPUT qtiSigRight ...

Page 188

There are a couple of different ways to get the SumoBot to do this maneuver. The first is to write a custom Initialization routine that performs this maneuver before moving on to the Main Routine. Here's another way. √ Save ...

Page 189

Add the GOTO Look_About ' -----[ Initialization ]------------------------------------------ GOSUB Calibrate_Qtis GOTO Look_About √ Run the modified program and verify that it makes the SumoBot look around before moving forward. There are lots of questions to consider and test when ...

Page 190

ACTIVITY #6: FULLY FUNCTIONAL SUMO EXAMPLE PROGRAMS This activity features two fully functional SumoBot example programs. While they both do the same things; they are organized a little differently. combination of the example programs, mainly from this chapter. The second ...

Page 191

Title ]-------------------------------------------------------------- ' Applied Robotics with the SumoBot - TestSumoWrestler.bs2 ' Fully functional state machine based sumo wrestling program ' with peripheral vision. ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ I/O Definitions ]--------------------------------------------------- ServoLeft PIN 13 ServoRight ...

Page 192

FS_CW CON 650 NO_ROT CON 750 LS_CCW CON 770 LS_CW CON 730 ' IR object detectors IrFreq CON 38500 ' -----[ Variables ]---------------------------------------------------------- temp VAR Word multi VAR Word counter VAR Byte maneuver VAR Nib sensors VAR Byte qtiLF VAR ...

Page 193

NEXT ELSEIF qtiRF = 1 THEN FOR counter = maneuver = Backward GOSUB Servos_And_Sensors NEXT FOR counter = maneuver = RotateLeft GOSUB Servos_And_Sensors NEXT ELSEIF irLF = 1 AND irRF = 1 THEN maneuver ...

Page 194

IF sensors <> 0 THEN GOTO Next_State NEXT Look_About: FOR counter = maneuver = RotateRight GOSUB Servos_And_Sensors IF sensors <> 0 THEN GOTO Next_State NEXT FOR counter = maneuver = RotateLeft GOSUB Servos_And_Sensors IF ...

Page 195

Subroutine - Calibrate_Qtis ]---------------------------------------- Calibrate_Qtis: HIGH qtiPwrLeft HIGH qtiSigLeft PAUSE 1 RCTIME qtiSigLeft, 1, temp LOW qtiPwrLeft multi = temp HIGH qtiPwrRight HIGH qtiSigRight PAUSE 1 RCTIME qtiSigRight, 1, temp multi = (multi + temp multi ...

Page 196

Pulse to left servo LOOKUP maneuver, [ FS_CCW, FS_CW, FS_CW, FS_CCW, NO_ROT, FS_CCW, LS_CCW, FS_CCW ], temp PULSOUT ServoLeft, temp ' Pulse to right servo LOOKUP maneuver, [ FS_CW, FS_CCW, FS_CW, FS_CCW, FS_CW, NO_ROT, FS_CW, LS_CW ], temp PULSOUT ...

Page 197

LOW qtiPwrLeft LOW qtiPwrRight RETURN Moving the State Routines to Subroutines Here is the Main Routine from the upcoming example program SumoWrestler.bs2, a revision of TestSumoWrestler.bs2 in which all of the state routines have ...

Page 198

Backward GOSUB Servos_And_Sensors NEXT FOR counter = maneuver = RotateRight GOSUB Servos_And_Sensors NEXT RETURN There was one small problem that had to be corrected before the program would run properly. The last command in the ...

Page 199

Also, make sure to adjust your QTI threshold calculation if you encountered problems with detecting the crease marks ...

Page 200

IrSenseRS PIN 0 ' -----[ Constants ]---------------------------------------------------------- ' SumoBot maneuvers Forward CON 0 Backward CON 1 RotateLeft CON 2 RotateRight CON 3 PivotLeft CON 4 PivotRight CON 5 CurveLeft CON 6 CurveRight CON 7 ' Servo pulse width rotations FS_CCW ...

Related keywords