Chapter 4: Infrared Object Detection · Page 43
END
' -----[ Subroutines ]-----------------------------------------------------
Read_IR_Sensors:
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
HOW IT WORKS
This program is functionally similar to the line detection program. The IR sensors are
scanned and, due to variable aliasing, the state of both sensors is held in the Nibble
variable
irBits. If no target is detected the SumoBot will go into scanning mode. The
code at Scan will look for the opponent in the last known direction (held in the variable
lastIr). When a target is detected, the SumoBot will move quickly in the target direction.
The direction is stored in the event the target is lost so that the SumoBot will scan in the
last know target direction.
If you run the program with the power switch in position 1, the Debug Terminal will
display the program's logic based on a target placed in front of the SumoBot. If you run
the program with the power switch in position 2, the SumoBot will rotate in the direction
of the target or scan in the suspect direction.