Datasheet
Page 158ยท Applied Robotics with the SumoBot
way to ensure this is to keep a subroutine that's in charge of both sending pulses to the
servos and checking sensors. In the code below, every time the Main Routine calls
Servos_And_Sensors, both the Pulse_Servos subroutine and the sensors subroutines
(
Read_Object_Detectors in this case) get checked.
' -----[ Subroutine - Servos_And_Sensors ]-----------------------------
Servos_And_Sensors:
GOSUB Pulse_Servos ' Call Pulse_Servos subroutine
' Call sensor subroutine(s).
sensors = 0 ' Clear previous sensor values
GOSUB Read_Object_Detectors ' Call Read_Object_Detectors
RETURN
Below is an excerpt from the next example program. The ELSEIF code block sets
maneuver equal to PivotLeft, then it calls Servos_And_Sensors. The statement DO
UNTIL (irLF = 1 AND irRF = 1) OR counter > 15
is what looks for the correct
condition. Notice that the loop has two conditions that will cause the program to exit the
loop. The first is
(irLF = 1 AND irRF = 1). It makes the loop will automatically
stop when the SumoBot has pivoted far enough to see the object with both eyes. The
condition
...OR counter > 15 prevents the SumoBot from pivoting indefinitely while
its opponent pushes it out of the ring.
DO
IF irLF = 1 AND irRF = 1 THEN ' Both?
maneuver = Forward ' State = Lunge forward
GOSUB Servos_And_Sensors
ELSEIF irLF = 1 THEN ' Just left?
counter = 0 ' State = track front left object
DO UNTIL (irLF = 1 AND irRF = 1) OR counter > 15
maneuver = PivotLeft ' Pivot left 15
GOSUB Servos_And_Sensors
counter = counter + 1
LOOP
ELSEIF irRF = 1 THEN ' Just right?
.
.
.
LOOP