Chapter 8: Robot Control with Distance Detection · Page 271
Figure 8-2: Frequencies and Zones for the Boe-Bot
P15
P14
P13
P12
P11
P10
P9
P5
P3
P8
P7
P2
P1
P0
P6
P4
X2
X3
Vdd Vs sVin
Bo ard o f Edu cati on
© 2000 -200 3
Vdd
Black
Red
X4 X5
15 14 13 12
+
Object
Object
Zone 5
No Detection
at any
Frequency
Zone 4
37500 Hz
Zone 3
38250 Hz
Zone 2
39500 Hz
Zone 1
40500 Hz
Zone 0
41500 Hz
You might be wondering why the value of zone 4 is 37.5 kHz and not 38.5 kHz. The
reason they are not the values that you would expect based on the % sensitivity graph is
because the FREQOUT command transmits a slightly more powerful (harmonic) signal at
37.5 kHz than it does at 38.5 kHz. The frequencies listed in Figure 8-2 are frequencies you
will program the BASIC Stamp to use to determine the distance of an object. These
frequencies were determined using tests similar to the ones outlined in Appendix G: Tuning
IR Distance Detection.
In order to test the IR detector at each frequency, you will need to use
FREQOUT to send
five different frequencies and test at each frequency to find out whether the IR detector
could see the object. The steps between each frequency are not quite even enough to use
the
FOR…NEXT loop’s STEP operator. You could use DATA and READ, but that would be
cumbersome. You could use five different
FREQOUT commands, but that would be a
waste of code space. Instead, the best approach for storing a short list of values that you
want to use in sequence is a command called
LOOKUP. The syntax for the LOOKUP
command is:
LOOKUP Index, [Value0, Value1, …ValueN], Variable
If the Index argument is 0, Value0 from the list inside the square braces will be placed
in
Variable. If Index is 1, Value1 from the list will be placed in Variable. There
could be up to 256 values in the list, but for the next example program, we will only need
5. Here is how it will be used:
FOR freqSelect = 0 TO 4
LOOKUP freqSelect,[37500,38250,39500,40500,41500],irFrequency