
9
Parallax, Inc.
•
Boe-Bot Tank Tread Kit (#28106)
03/2004
irBits VAR Nib ' ir detection bits
irLeft VAR irBits.BIT1 ' left IR detection
irRight VAR irBits.BIT0 ' right IR detection
xAxis VAR Word ' x-axis tilt reading
yAxis VAR Word ' y-axis tilt reading
' -----[ EEPROM Data ]-----------------------------------------------------
' -----[ Initialization ]--------------------------------------------------
Reset:
LOW LMotor ' initialize motor outputs
LOW RMotor
' -----[ Program Code ]----------------------------------------------------
Main:
DO
GOSUB Check_Level ' verify terrain okay
' navigate around obstacles
GOSUB Read_IR_Sensors
ON irBits GOSUB Forward, Go_Left, Go_Right, U_Turn
LOOP
END
' -----[ Subroutines ]-----------------------------------------------------
Check_Level:
PULSIN TiltY, IsHigh, yAxis ' check longitudinal tilt
yAxis = yAxis / 100 ' filter reading
IF (yAxis =< YThresh) THEN ' if terrain too steep
GOSUB U_Turn ' ... and turn around
ENDIF
RETURN
Read_IR_Sensors:
irBits = %00
FREQOUT LfIrOut, 1, 38500 ' modulate left IR LED
irLeft = ~LfIrIn ' read input (1 = target)
FREQOUT RtIrOut, 1, 38500 ' modulate right IR LED
irRight = ~RtIrIn ' read input (1 = target)
RETURN
Forward: ' move tank forward
FOR pulses = 1 TO 5
PULSOUT LMotor, LFwd
PULSOUT RMotor, RFwd
PAUSE 20
NEXT
RETURN