Datasheet
Chapter 4: Navigation Tips ยท Page 165
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
IF...THEN statements in the previous
example program's main routine. They will make the SumoBot respond by rotating in
place to turn toward objects it detects on either side. If an object is on the SumoBot's left
side, the
ELSEIF irLS = 1 THEN code block will get executed. The DO UNTIL...LOOP
makes the SumoBot rotate left until either one of the front IR detectors sees the object.
The
ELSEIF irRS = 1 THEN... code block behaves similarly for objects on the right
side.
ELSEIF irLS = 1 THEN ' Object left side?
DO UNTIL irRF = 1 OR irLF = 1 ' State = track left side object
maneuver = RotateLeft ' Rotate left
GOSUB Servos_And_Sensors
LOOP
ELSEIF irRS = 1 THEN ' Object right side?
DO UNTIL irRF = 1 OR irLF = 1 ' State = track right side object
maneuver = RotateRight ' Rotate right
GOSUB Servos_And_Sensors
LOOP