Chapter 7: Navigating with Infrared Headlights
· Page 267
ENDIF ' its position.
PULSOUT 13,pulseLeft ' Apply the pulse.
PULSOUT 12,pulseRight
PAUSE 15 ' 5 ms for detectors
' Check IRs again in case object is moving
GOSUB Check_IRs
LOOP
' -----[ Subroutines ] ------------------------------------------------
Check_IRs:
FREQOUT 8, 1, 38500 ' Check IR Detectors
irDetectLeft = IN9
FREQOUT 2, 1, 38500
IrDetectRight = IN0
RETURN
P3.
The key to solving this problem is to combine "FastIrRoaming.bs2" and
"IrInterferenceSniffer.bs2" in a single program.
' -----[ Title ]-------------------------------------------------------
' Robotics with the Boe-Bot - RoamAndSniffBoeBot.bs2
' Boe-Bot roams around and sounds alarm when IR detected.
' {$STAMP BS2}
' {$PBASIC 2.5}
' -----[ Variables ]---------------------------------------------------
irDetectLeft VAR Bit ' Left IR sensor reading
irDetectRight VAR Bit ' Right IR sensor reading
pulseLeft VAR Word ' Pulses sent to servos
pulseRight VAR Word
counter VAR Nib ' Loop counter
' -----[ Initialization ]----------------------------------------------
DEBUG "Program Running!"
FREQOUT 4, 2000, 3000 ' Signal program
start/reset.
' -----[ Main Routine ]------------------------------------------------
Main:
DO
GOSUB Roam
GOSUB Sniff
LOOP