Download Print this page

Parallax 29115 Manual page 7

Line follower module

Advertisement

Test Program Analysis
Even though the program is simple in its design and purpose, it holds an important piece of code that will
be used in all other projects: the reading of the Line Detector module bits.
The program starts by defining some useful constants. Using constant values is a very good habit as it
increases code readability and allows a program to be modified easily and more reliably – especially if the
same value is used in several places in the program. Constant definitions have been created for LEDon
and LEDoff that will make the program easier to read. In this case LEDon has a value of zero since the
circuit is configured to turn LEDs on by making the corresponding output pin low.
The next set of values have to do with the kind of course that the BOE-Bot is running. Most of the time
the BOE-Bot will follow a black line drawn on a white course. The difficulty with this kind of course,
however, is that the large white surface can reflect a lot of additional light – including IR – onto the
detectors, causing them to be less sensitive than required to reliably detect the line. For this reason,
many robot clubs create line following courses that use a white line on a black background. See page XX
for tips on making your own course and dealing with excess light on the sensors.
For this program, the value of LFmode (line following mode) is se to BLine (black line) which gives it a
value of one. The LFmode value will be used with the Line Detector output to return the correct value
for the specified course type.
The final constant value is called MoveTo and has a value of 2. This is a little-used, yet very useful code
to use with DEBUG. MoveTo allows the cursor to be moved to a specific x/y character coordinate in the
DEBUG window. This technique is great for creating advanced displays.
The Line Follower is initialized by making sure that all of its LEDs are OFF. This is done by setting bits
two through six in register OutL to one. As soon as the same bits are set in DirL, the pins will be made
outputs and will go high, causing the LEDs to stay off. Notice that the output bits are set before setting
the direction bits. This eliminates any glitches on the outputs when the Stamp is reset and runs the
initialization sequence.
The next section of code creates a BOE-Bot diagram in the DEBUG window. This diagram will the Line
Follower bits in real time and in relation to the correct orientation of the BOE-Bot.
Once in the main body of code, the first thing the program does is call the subroutine
Read_Line_Follower. This is the heart of the program and will be used by all other line following
experiments.
Read_Line_Follower:
lfBits = 0
FOR ledPos = 2 TO 6
OutL.LowBit(ledPos) = LEDon
PAUSE 1
lfBits.LowBit(ledPos) = In9 ^ LFmode
OutL = OutL | %01111100
NEXT
lfBits = lfBits >> 2
RETURN
The subroutine starts by clearing the old reading. This is important because lfBits is eight bits wide but
only five are used. The core of the routine uses a FOR...NEXT loop to cycle through all five sensors.
The first line of the loop code turns on an LED by setting the corresponding output pin low.
Parallax, Inc. • Parallax Line Follower (#29115) • 12/2001
' clear last reading
' turn the LED on
' allow sensor to read
' record the sensor reading
' turn LEDs off
' shift bits to zero index
Page 6

Advertisement

loading