![Parallax Boe-Bot Student Manual Download Page 279](http://html2.mh-extra.com/html/parallax/boe-bot/boe-bot_student-manual_3646721279.webp)
Chapter 7: Navigating with Infrared Headlights
· Page 265
' -----[ Main Routine ]------------------------------------------------
Main:
' Loop until something is detected
DO
GOSUB Check_IRs
LOOP UNTIL (irDetectLeft = 0) OR (irDetectRight = 0)
' Now start roaming -- this code from FastIrRoaming.bs2
DO
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseLeft = 650 ' Both detect
pulseRight = 850 ' Back up
ELSEIF (irDetectLeft = 0) THEN ' Left detect
pulseLeft = 850 ' Turn right
pulseRight = 850
ELSEIF (irDetectRight = 0) THEN ' Right detect
pulseLeft = 650 ' Turn left
pulseRight = 650
ELSE ' Nothing detected
pulseLeft = 850 ' Go forward
pulseRight = 650
ENDIF
PULSOUT 13, pulseLeft ' Apply the pulse.
PULSOUT 12, pulseRight
PAUSE 15
GOSUB Check_IRs ' Check IRs again
LOOP
' -----[ Subroutines ] ------------------------------------------------
Check_IRs:
FREQOUT 8, 1, 38500 ' Check IR Detectors
irDetectLeft = IN9
FREQOUT 2, 1, 38500
IrDetectRight = IN0
RETURN
P2.
This behavior is in many ways the opposite of the roaming behavior covered in
this chapter. Instead of avoiding objects, the Boe-Bot tries to go toward the
objects. For this reason, the main code can be derived from
"FastIrRoaming.bs2", with a bit added that spins the Boe-Bot slowly until an
object is detected.
In the solution below, once the Boe-Bot has spied an object, it will continue
forward even if the detectors both read "no object" (1) for a few loops. This is
because, as the Boe-Bot is maneuvering toward the object, sometimes the