Page 250 · Robotics with the Boe-Bot
irDetectLeft = IN9
The
statements were modified so that they look at the variables that store the IR
IF...THEN
pair detections instead of the whisker inputs.
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (irDetectLeft = 0) THEN
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
ELSE
GOSUB Forward_Pulse
ENDIF
Example Program – RoamingWithIr.bs2
√
Open RoamingWithWhiskers.bs2
√
Modify it so that it matches the program below.
√
Reconnect power to your board and servos.
√
Save and run it.
√
Verify that, aside from the fact that there's no contact required, it behaves like
RoamingWithWhiskers.bs2.
' -----[ Title ]--------------------------------------------------------------
' Robotics with the Boe-Bot - RoamingWithIr.bs2
' Adapt RoamingWithWhiskers.bs2 for use with IR pairs.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
' -----[ Variables ]----------------------------------------------------------
irDetectLeft
VAR
irDetectRight VAR
pulseCount
VAR
' -----[ Initialization ]-----------------------------------------------------
' Stamp directive.
' PBASIC directive.
Bit
Bit
Byte