Shop OBEX P1 Docs P2 Docs Learn Events
sumo robot — Parallax Forums

sumo robot

I LOVE ROBOTI LOVE ROBOT Posts: 22
edited 2007-04-05 15:15 in Robotics
i build the sumo robots·and use 2·GP2Y0D02YK·sensor (digital output and active high) for the front. and·use 2 sensor lins for the border. it·working just fine. however, my sumo bot· does not work the way that i wanted. because·sometime can not see another·opponent.· and that program below i renew from SumoBot books. can·someone tell me how do i slove this problem. thankyou!! (i use bs2)

LMotor········· CON···· 13·················· ···· ' left servo motor
RMotor········· CON···· 12···················· · ' right servo motor
·
LLineSnsPwr···· CON···· 10··················· ' left line sensor power
LLineSnsIn····· ··CON·······9···················· ·' left line sensor input
RLineSnsPwr··· CON····· 7····················· ' right line sensor power
RLineSnsIn····· ·CON······ 8····················· ' right line sensor input
·
·
Speaker········ CON···· ·· 0····················· ' piezo speaker
StartLED······· CON····· 11····················· ' display start delay
·
'
[noparse][[/noparse] Constants ]

·
LFwdFast······· ·CON···· 1000················· ' left motor forward; fast
LFwdSlow······· CON···· 800·············· ·····' left motor forward; slow
LStop··········· · ·CON····· 750··················· ' left motor stop
LRevSlow······· CON····· 700··················· ' left motor reverse; slow
LRevFast······· ·CON····· 500··················· ' left motor reverse; fast
·
RFwdFast······ · CON····· 500··················· ' right motor forward; fast
RFwdSlow······· CON····· 700·················· ' right motor forward; slow
RStop············· ·CON····· 750··················· ' right motor stop
RRevSlow······· CON····· 800··············· ····' right motor reverse; slow
RRevFast······ ·· CON···· 1000················· ' right motor reverse; fast
·
'
[noparse][[/noparse] Variables ]

·
leftSense······ VAR···· Word··················· ' left sensor raw reading
rightSense····· VAR···· Word·················· ' right sensor raw reading
blackThresh···· VAR···· Word················ ' QTI black threshold setting
lineBits······· VAR···· Nib······················· ·' decoded sensors value
lineLeft······· VAR·· ··lineBits.BIT1
lineRight······ VAR···· lineBits.BIT0
··········
pulses········· VAR···· Byte··················· ' counter for motor control
temp··········· VAR···· Byte
·
'
[noparse][[/noparse] EEPROM Data ]

RunStatus······ DATA··· $00···················· ' run status
·
'
[noparse][[/noparse] Initialization ]

·
Run_Check:········································· ·· ' 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 Set_Threshold·······' run now?
· END················································· ··· '·· -- no ... next time
·
' Sets black threshold to 1/4 the average of the two sensor readings.
' SumoBot must be placed over black playing surface before this code runs.
·
Set_Threshold:· ································' set QTI black threshold
· GOSUB Read_Line_Sensors
· blackThresh = (leftSense / 8) + (rightSense / 8)
·
Start_Delay:··································· ' mandatory five second delay
· FOR temp = 1 TO 5
··· HIGH StartLED·························' show active
··· PAUSE 900
··· INPUT StartLED······················ ' blink each second
··· FREQOUT Speaker, 100, 2500, 3000········ ' beep each second
· NEXT
·
· GOTO Lunge································ ' start aggressive!
·
'
[noparse][[/noparse] Main Code ]

·
Main:
· GOSUB Read_Line_Sensors
·
·· IF lineBits = 0 THEN search_for_opponent
·· IF lineBits = 1 THEN SPIN_LEFT
·· IF lineBits = 2 THEN SPIN_RIGHT
·· IF lineBits = 3 THEN ABOUT_FACE
' --[noparse][[/noparse] Border Avoidance ]--
·
Spin_Left:····································· ' right sensor was active
· FOR pulses = 1 TO 20
··· PULSOUT LMotor, LRevFast
··· PULSOUT RMotor, RFwdFast
··· PAUSE 20
· NEXT
·
· GOTO Lunge
·
Spin_Right:········· ···························' left sensor was active
· FOR pulses = 1 TO 20
··· PULSOUT LMotor, LFwdFast
··· PULSOUT RMotor, RRevFast
··· PAUSE 20
· NEXT
·· GOTO Lunge
·
About_Face:···································· ' both sensors on Shikiri line
· FOR pulses = 1 TO 10·················· ' back up from edge
··· PULSOUT LMotor, LRevFast
··· PULSOUT RMotor, RRevFast
··· PAUSE 20
· NEXT
· FOR pulses = 1 TO 30························· ' turn around
··· PULSOUT LMotor, LFwdFast
··· PULSOUT RMotor, RRevFast
··· PAUSE 20
· NEXT
··· GOTO Lunge
·
' --[noparse][[/noparse] IR Processing ]--
·
Search_For_Opponent:
·
· IF (IN15=1)AND(IN14=1) THEN Lunge········· 'GP2Y0D02YK condition front sensors
· IF (IN15=1) THEN Follow_Left
· IF (IN14=1) THEN Follow_Right
· IF (IN15=0)AND(IN14=0)THEN· Move_Fwd
·
Move_Fwd:
·
··· PULSOUT LMotor, LFwdFast
··· PULSOUT RMotor, RFwdFast
··· PAUSE 20
· GOTO Main
·
Follow_Right:
·
·FOR pulses = 1 TO 7································· ' spin right, fast
· PULSOUT LMotor, LFwdFast
· PULSOUT RMotor, RRevSlow
· PAUSE 20
· NEXT
·· GOSUB lunge
· GOTO Main
·
Follow_Left:
·· FOR pulses = 1 TO 7······························ ' spin left, fast
· PULSOUT LMotor, LRevSlow
· PULSOUT RMotor, RFwdFast
· PAUSE 20
· NEXT
·· GOSUB lunge
· GOTO Main
·
Lunge:
··· FOR pulses = 1 TO 15
··· PULSOUT LMotor, LFwdFast
··· PULSOUT RMotor, RFwdFast
··· GOSUB Read_Line_Sensors
··· IF (lineBits = %11) THEN Match_Over········ ' in sight and we're on the line
··· NEXT
·· ··GOTO Main
·
' If SumoBot can see the opponent with both "eyes" and both QTIs are
' detecting the border, we must have pushed the opponent out.
·
Match_Over:
· FOR pulses = 1 TO 10························· ' stop motors
··· PULSOUT LMotor, LStop
··· PULSOUT RMotor, RStop
··· PAUSE 20
· NEXT
· INPUT LMotor
· INPUT RMotor
·
· FOR temp = 1 TO 10··························· ' make some noise
··· HIGH StartLED
··· FREQOUT Speaker, 100, 2500, 3000··········· ' beep
··· INPUT StartLED····························· ' blink LED
··· PAUSE 100
· NEXT
·
· DIRS = $0000································· ' disable all outputs
· GOTO Run_Check ·······························' reset for next round
·
'
[noparse][[/noparse] Subroutines ]

·
Read_Line_Sensors:
· HIGH LLineSnsPwr····························· ' activate sensors
· HIGH RLineSnsPwr
· HIGH LLineSnsIn······························ ' discharge QTI caps
· HIGH RLineSnsIn
· PAUSE 1
· RCTIME LLineSnsIn, 1, leftSense·············· ' read left sensor
· RCTIME RLineSnsIn, 1, rightSense············· ' read right sensor
· LOW LLineSnsPwr···················· ··········' deactivate sensors
· LOW RLineSnsPwr
·
· ' convert readings to bits
· lineBits = %00
· LOOKDOWN leftSense, >=[noparse][[/noparse]blackThresh, 0], lineLeft
· LOOKDOWN rightSense, >=[noparse][[/noparse]blackThresh, 0], lineRight
· RETURN

Comments

  • c-moneyc-money Posts: 4
    edited 2007-04-05 15:15
    yeah ummm double check the looker things the sensors cause I put it in mine and it worked like a dream. $$$bling bling$$$
Sign In or Register to comment.