Datasheet

Chapter 4: Navigation Tips ยท Page 143
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 that you can get from this array. It
turns out that you can reduce all these possibilities to a very simple
IF...ELSEIF...ELSE...ENDIF statement. In fact, just an IF, six ELSIFs, and one
ELSE can control the whole show and give you a highly functional wrestling program.
The
IF, all the ELSEIFs and the ELSE conditions in the final program call subroutines that
do specific maneuvers until either a sensor condition is detected indicating the subroutine
succeeded, or the allowed amount of time for the subroutine to execute the maneuver has
expired. It makes the SumoBot's behavior both predictable and automated. This chapter
demonstrates the various building blocks that go into a program that simplifies the
SumoBot's decision process and automates maneuver's responses to sensor events.
SENSOR FLAGS AND NAVIGATION STATES
There are several ingredients to building a program that makes a lot of different sensors
and maneuvers easy to manage. First, build a subroutine that makes selecting servo pulse
durations fully automated. All your program should have to do is set a variable equal to a
maneuver name, and then call the servo control subroutine. Second, build a subroutine
that calls both the servo control subroutine and updates all the sensors. That way, after
your program has picked its maneuver, the
sensors variable can be completely updated
between each servo pulse. Third, construct independent navigation states. Each
navigation state should be a subroutine that does a job with no further intervention until it
has either succeeded or its time for the maneuver has expired. Finally, construct an
IF...THEN statement that checks and responds to the most important sensor flags first,
and then goes down a list of possible conditions that the SumoBot should react to. This
IF...THEN statement simply responds to each sensor condition by calling the navigation
subroutine that is designed to respond to that condition.
It takes a few steps to get to the final form of the program, starting as always with small
programs. These small programs are then converted into programs that feature sections
and a common variable use convention. After several of these are built, they can be
merged into a larger test program. After the test program is tested, it can be rearranged
into a simplified Main Routine that makes executive decisions and then passes control to
navigation subroutines.