Download Print this page

Parallax 29115 Manual page 11

Line follower module

Advertisement

Simple Line Follower Program
Now that a method has been developed to detect a line, it's a matter of processing and decoding this
information in order to cause the BOE-Bot to follow the line. Listing 2 (starts on page 11) is a simple
program that will cause the BOE-Bot to follow a ¼" line around a closed course.
The program logic is straightforward:
1. Read the Line Follower module
2. Adjust motor speed (steering) based on Line Follower input
3. Save last Line Follower reading
4. Go to Step 1
Line Following Program Analysis
This line following code uses great deal of the material developed in the test and calibration program.
Pin definitions for the BOE-Bot servo motors have been added, as well as speed control values for the
servos in the Constants section. These values were determined empirically by running a BOE-Bot in a
straight line (both motors at the same speed) and timing a measured distance. By independently
controlling motor speed, the BOE-Bot can be caused to move forward, backward or to turn
A single line has been added to the Initialization code; a line that is very important. In the main body of
program, the last sensor reading is saved. This will be used to guide the BOE-Bot in the event that an
invalid value is returned from the Line Follower module and will keep the BOE-Bot moving in the last
known direction. At the beginning of the program there have been no readings, so the value of lastBits
is initialized to %00100. This will cause the BOE-Bot to go straight, even if it is started off the line.
The function of the main loop is to read the Line Follower module and decode its bits, determining the
appropriate steering input to give the BOE-Bot. The decoding process is done with the NCD operator.
NCD returns the highest set ("1") bit of a given number, or zero if no bits are set. A non-zero value will
be the highest set bit position plus one. Using NCD, the value of steer will fall between zero and five.
Then BRANCH is used to direct control to the motor control (steering) routines. Once the servos have
been updated, the program saves the current reading and continues from the top.
If the BOE-Bot starts -- or somehow manages to roam – off the line (this can happen in very sharp
corners), the value returned in lfBits will be zero. This will cause the BRANCH table to send it to the
label at Off_Line. This section of code restores the last valid sensor reading, then jumps back to the
steering control. This will keep the BOE-Bot moving and should allow it to find the line and resume on
course.
Programmers with some BOE-Bot experience may notice a lack of any loop padding – time between servo
motor updates (typically 20 to 30 ms). The reason is that the Read_Line_Follower subroutine takes
about 17 milliseconds to execute
delay between servo updates. Keep in mind that adding additional code to the main program loop will
tend to slow the BOE-Bot.
1
Refer to Robotics!, Chapter 2, for a complete discussion on BOE-Bot motor control and steering.
2
Refer to The Nuts & Volts of BASIC Stamps, Column #44, for a routine for code timing.
Parallax, Inc. • Parallax Line Follower (#29115) • 12/2001
2
. This time, combined with other program overhead, provides sufficient
1
.
Page 10

Advertisement

loading