Page 50 · SumoBot – Mini Sumo Robotics
DIRS = $0000 ' disable all outputs
GOTO Reset ' reset for next round
' -----[ Subroutines ]-----------------------------------------------------
Read_Line_Sensors:
HIGH LLinePwr ' activate sensors
HIGH RLinePwr
HIGH LLineIn ' discharge caps
HIGH RLineIn
PAUSE 1
RCTIME LLineIn, 1, lLine ' read left sensor
RCTIME RLineIn, 1, rLine ' read right sensor
LOW LLinePwr ' deactivate sensors
LOW RLinePwr
' convert readings to bits
LOOKDOWN lLine, >=[1000, 0], lbLeft ' 0 = black, 1 = line
LOOKDOWN rLine, >=[1000, 0], lbRight
RETURN
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
Creep_Forward:
FOR pulses = 1 TO 20
PULSOUT LMotor, LFwdSlow
PULSOUT RMotor, RFwdSlow
PAUSE 20
NEXT
RETURN
HOW IT WORKS
After the Reset code for Run/Don't Run developed in the chapter 4, the SumoBot reads
the QTI sensors and calculates a suitable threshold level for the playing field that will be
used during the match. The net effect is to calculate the average sensor reading ((left +
right) / 2) and then divide this value by four. The
blackThresh variable holds this level
and is recalculated for each match (this works because the SumoBot starts in near the
center of the ring, over the black surface). Using this strategy, the SumoBot can deal
with variable ambient lighting conditions that may change from match to match.