Chapter 3: SumoBot Sensors and Border Detection · Page 31
RStop CON 750 ' right motor stop
RRevSlow CON 800 ' right motor rev; slow
RRevFast CON 1000 ' right motor rev; fast
' -----[ Variables ]-------------------------------------------------------
lLine VAR Word ' left sensor raw reading
rLine VAR Word ' right sensor raw reading
lineBits VAR Nib ' decoded sensors value
lbLeft VAR lineBits.BIT1
lbRight VAR lineBits.BIT0
pulses VAR Byte ' counter for motor control
temp VAR Byte
' -----[ EEPROM Data ]-----------------------------------------------------
RunStatus DATA $00 ' run status
' -----[ Initialization ]--------------------------------------------------
Reset:
READ RunStatus, temp ' read current status
temp = ~temp ' invert status
WRITE RunStatus, temp ' save for next reset
IF (temp > 0) THEN END ' run now?
Start_Delay:
HIGH StartLED ' show active
PAUSE 5000 ' start delay
LOW StartLED ' LED off
' -----[ Program Code ]----------------------------------------------------
Main:
GOSUB Read_Line_Sensors
' sumo movement
BRANCH lineBits, [Go_Fwd, Spin_Left, Spin_Right, About_Face]
Go_Fwd:
PULSOUT LMotor, LFwdFast
PULSOUT RMotor, RFwdFast
GOTO Main
Spin_Left:
FOR pulses = 1 TO 20
PULSOUT LMotor, LRevFast
PULSOUT RMotor, RFwdFast
PAUSE 20
NEXT