Datasheet

Chapter 4: Navigation Tips · Page 159
You can test this next example program by positioning the SumoBot so that neither of its
IR object detectors see an object. Then place your hand in front of one of the detectors.
The SumoBot should rotate toward your hand until both detectors see it. Then it should
lunge forward at your hand. If you remove your hand, the SumoBot will stop and wait.
That's because the
ELSE condition in the IF...THEN...ELSIF...ELSE statement. All it
does is checks the IR detectors.
ELSE ' No objects detected?
GOSUB Read_Object_Detectors ' State = search pattern
ENDIF
Example Program: FrontIrNavigation.bs2
Enter, save, and run FrontIrNavigation.bs2.
Place the SumoBot somewhere where any objects its detectors are pointing at
will be more than a couple meters away. If there are objects near the ring,
consider using an
IrFreq CON directive with a value that makes the SumoBot
nearsighted.
Place your hand in front of the left IR object detector. The SumoBot should turn
toward your hand, then lunge forward at it.
Remove your hand, the SumoBot should stop moving.
Repeat for the right object detector.
Place your hand in front of both object detectors at the same time, then take it
away again. So long as both
irLF and irRF went from 0 to 1 at the same time,
the SumoBot should lunge and stop immediately when you hand disappears from
view.
Wave your hand briefly in front of one of the detectors. The SumoBot should
pivot for between 1/4 and 1/5 of a second before stopping.
Recycling sections and subroutines. This program was built by combining elements from
other programs following the same procedure introduced in Chapter 2, Activity #6. Elements
from the various declarations sections and subroutines were copied from two programs:
SensorsWithTempVariables.bs2 from Chapter 3, Activity #7, and
ServoControlWithLookup.bs2 from Activity #1 in this chapter.
Try incorporating TestResetButton.bs2 from Chapter 2, Activity #3. It'll make the
program a lot easier to test.