Page 266 ·
Robotics with the Boe-Bot
detectors read "no object" for brief moments, but this is not reason enough to
give up the chase.
' Robotics with the Boe-Bot - SumoBoeBot.bs2
' Search for object, lock onto it and push it.
' {$STAMP BS2}
' {$PBASIC 2.5}
irDetectLeft VAR Bit ' Left IR reading
irDetectRight VAR Bit ' Right IR reading
pulseLeft VAR Word ' pulse values for servos
pulseRight VAR Word
' -----[ Initialization ]----------------------------------------------
DEBUG "Program Running!"
FREQOUT 4, 2000, 3000 ' Signal start/reset.
' -----[ Main Routine ]------------------------------------------------
Main:
' Spin around slowly until an object is spotted
DO
PULSOUT 13, 790 ' Rotate slowly
PULSOUT 12, 790
PAUSE 15 ' 5 ms for detectors
GOSUB Check_IRs ' While looking for object
LOOP UNTIL (irDetectLeft = 0) OR (irDetectRight = 0)
' Now figure out exactly where the object is and go toward it
DO
' Object in both detectors -- go forward
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseLeft = 850 ' Forward
pulseRight = 650
' Object on left - go left
ELSEIF (irDetectLeft = 0) THEN
pulseLeft = 650 ' Left toward object
pulseRight = 650
' Object on right - go right
ELSEIF (irDetectRight = 0) THEN
pulseLeft = 850 ' Right toward object
pulseRight = 850
' No object -- go forward anyway, because the detectors will
ELSE ' momentarily show
pulseLeft = 850 ' "no object" as the
pulseRight = 650 ' Boe-Bot is adjusting