basic stamp sumobots
DiscoNugget
Posts: 2
in BASIC Stamp
my robotics teacher asked me to build an evasive sumo program out of PBASIC 2.5 FOR OUR BOE BOT SUMO BOTS NOT PARALLAX SUMOBOTS I don't know how
THIS IS THE ORIGINAL PROGRAM
(not the evasive)
THIS IS THE ORIGINAL PROGRAM
(not the evasive)
' {$STAMP BS2}
' {$PBASIC 2.5}
' ----------------------------
' MiniSumo.bs2
' convert Boe-Bot into SumoBot
' ----------------------------
' Parralax BOE BOT SumoBots competion
' Asher Haun
' S.C.E.C. Robotics
' ----------------------------
' .bs2
' Boe Bot serial
' ----------------------------
' DiscoNuggetDevelopment
' >_
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
LMotor CON 13
RMotor CON 12
LIrOut CON 11
LIrIn VAR IN14
RIrOut CON 1
RIrIn VAR IN0
startLed CON 15
Speaker CON 3
LFwdFast CON 848 'find correct numbers
LFwdSlow CON 775
LSTOP CON 750
LRevSlow CON 725
LRevFast CON 650
RFwdFast CON 650 'find correct numbers
RFwdSlow CON 725
RStop CON 750
RRevSlow CON 775
RRevFast CON 850
LeftTurnCount CON 25 ' counter value for 90 turn
RightTurnCount CON 35 ' counter value for 90 turn
AboutFaceCount CON 120 ' counter value for 180 turns
blackThresh VAR Word
qti VAR Nib
qtiLeft VAR qti.BIT1
qtiRight VAR qti.BIT0
irBits VAR Nib
IrLeft VAR irBits.BIT1
irRight VAR irBits.BIT0
LastIr VAR Nib
pulses VAR Byte
temp VAR Byte
RunStatus DATA %00
' Piano notes
FreqDetectable CON 3000
C6 CON 1047
D6 CON 1175
E6 CON 1319
F6 CON 1397
G6 CON 1568
A6 CON 1760
Be6 CON 1976
C7 CON 2093
D7 CON 2349
E7 CON 2637
F7 CON 2793
G7 CON 3136
A7 CON 3520
Be7 CON 3951
C8 CON 4186
' end of piano notes
Reset: ' user reset button as On-Off
READ RunStatus, temp ' read current status
temp = ~temp ' invert status
WRITE RunStatus, temp ' save status for next reset
IF (temp > 0) THEN END ' run now?
Set_Threshold:
GOSUB Read_Line_Sensors
blackThresh = (qtiLeft/10) + (qtiRight/10)
LOW LMotor
LOW Rmotor
Start_Delay:
FOR temp = 1 TO 5
HIGH StartLED
PAUSE 900
INPUT StartLed
FREQOUT Speaker, 100, 2500, 5000 ' signal start of match tone
NEXT
GOTO Lunge
' - program code -
Main:
GOSUB Read_Line_Sensors
' if not on shikiri (border) line, continue to look ofr opponent
' otherwise spin back towards center and resume search
BRANCH qti, [About_Face, Spin_Right, Spin_Left, Search_For_Opponent]
' - Border Avoidance -
Spin_Left: ' right QTI detects white
FOR pulses = 1 TO LeftTurnCount
PULSOUT LMotor, LRevFast
PULSOUT RMotor, RFwdFast
PAUSE 20
NEXT
lastIr = %11
GOTO Lunge
Spin_Right: ' left QTI detects white
FOR pulses = 1 TO rightTurnCount
PULSOUT LMotor, LFwdFast
PULSOUT RMotor, RRevFast
PAUSE 20
NEXT
lastIr = %11
GOTO Lunge
About_Face: ' both QTI detect white
FOR pulses = 1 TO 10 ' back up from edge
PULSOUT LMotor, LRevFast
PULSOUT RMotor, RRevFast
PAUSE 20
NEXT
FOR pulses = 1 TO 60 ' turn around
PULSOUT LMotor, LRevFast
PULSOUT RMotor, RRevFast
PAUSE 20
NEXT
lastIr = %11
GOTO Lunge
' - IR Processsing -
Search_For_Opponent:
GOSUB READ_IR_Sensors
' if opponent is not in sight scan in last known direction.
' turn toward opponent if seen by one eye, if both lunge forward
BRANCH irBits, [Scan, Follow_Right, Follow_Left, lunge]
scan:
BRANCH lastIr, [Move_Fwd, Scan_Right, Scan_Left]
Move_Fwd:
PULSOUT LMotor, LFwdFast
PULSOUT RMotor, RFwdFast
GOTO Main
Scan_Right:
FOR pulses = 1 TO 5
PULSOUT LMotor, LFwdSlow
PULSOUT RMotor, RRevSlow
PAUSE 20
NEXT
GOSUB Creep_Forward
GOTO Main
Scan_Left:
FOR pulses = 1 TO 5
PULSOUT LMotor, LRevSlow
PULSOUT RMotor, RFwdSlow
PAUSE 20
NEXT
GOSUB Creep_Forward
GOTO Main
Follow_Right:
PULSOUT LMotor, LFwdFast
PULSOUT RMotor, RRevFast
PAUSE 20
lastIr = qti
GOTO Main
Follow_Left:
PULSOUT LMotor, LRevFast
PULSOUT RMotor, RFwdFast
PAUSE 20
lastIr = qti
GOTO Main
Lunge:
FOR pulses = 1 TO 30
DEBUG "lunge", CR
PULSOUT LMotor, LFwdFast
PULSOUT RMotor, RFwdFast
GOSUB READ_LINE_Sensors
IF (qti = %00)THEN Match_Over
NEXT
GOTO Main
Match_Over:
FOR pulses = 1 TO 10
PULSOUT LMotor, LStop
PULSOUT RMotor, RStop
PAUSE 20
NEXT
INPUT LMotor
INPUT RMotor
FOR temp = 1 TO 10
HIGH StartLED
GOSUB Music
INPUT StartLED
PAUSE 100
NEXT
DIRS = %0000
GOTO Reset:
' - subroutines -
Read_Line_Sensors:
HIGH 4: PAUSE 1: qti.BIT0 = IN6: INPUT 4
HIGH 5: PAUSE 1: qti.BIT1 = IN6: INPUT 5
RETURN
read_IR_Sensors:
FREQOUT LIrOut, 1, 38500
IrLeft = ~LIrIn
FREQOUT RIrOut, 1, 38500
IrRight = ~RIrIn
RETURN
Creep_Forward:
FOR pulses = 1 TO 20
PULSOUT LMotor, LFwdSlow
PULSOUT RMotor, RFwdSlow
NEXT
RETURN
Music:
FREQOUT Speaker, 500,C7
PAUSE 10
FREQOUT Speaker, 500,C7
PAUSE 10
FREQOUT Speaker, 500,D7
PAUSE 10
FREQOUT Speaker, 500,E7
PAUSE 10
FREQOUT Speaker, 500,C7
PAUSE 10
FREQOUT Speaker, 500,E7
PAUSE 10
FREQOUT Speaker, 1000,D7
PAUSE 10
FREQOUT Speaker, 500,C7
PAUSE 10
FREQOUT Speaker, 500,C7
PAUSE 10
FREQOUT Speaker, 500,D7
PAUSE 10
FREQOUT Speaker, 500,E7
PAUSE 10
FREQOUT Speaker, 500,C7
PAUSE 10
FREQOUT Speaker, 1000,BE6
PAUSE 10
FREQOUT Speaker, 500,C7
PAUSE 10
FREQOUT Speaker, 500,C7
PAUSE 10
FREQOUT Speaker, 500,D7
PAUSE 10
FREQOUT Speaker, 500,E7
PAUSE 10
FREQOUT Speaker, 500,F7
PAUSE 10
FREQOUT Speaker, 500,E7
PAUSE 10
FREQOUT Speaker, 500,D7
PAUSE 10
FREQOUT Speaker, 500,C7
PAUSE 10
FREQOUT Speaker, 500,BE6
PAUSE 10
FREQOUT Speaker, 500,G6
PAUSE 10
FREQOUT Speaker, 500,A6
PAUSE 10
FREQOUT Speaker, 500,BE6
PAUSE 10
FREQOUT Speaker, 1000,C7
PAUSE 10
FREQOUT Speaker, 1000,C7
RETURN

Comments
Study your existing program. See what needs to change.
lunge, fast right, scan line sensors(if %00 then turn left160 degrees), round about 3/4 fast, lunge at side of opponent, start main program