alleykat
01-30-2007, 08:53 AM
I am currently using the parallax emitter/detector pair and two microswitches for collision avoidance and
collision detection·for my robot. I was wondering if threre is a more efficient way to test the IR·and bumper
sensors than what I am doing ? What I want the robot to do is
irdetectleft and irdetectright = 0 then, back and turn right
irdetectleft = 0 then, turn right
irdetectright = then, turn left
bumpswitch (IN6 =0), back and turn right
bumpswitch (IN7=0), back and turn left
If IR and micro-switches detect nothing, go forward
' {$STAMP BS2}
' {$PBASIC 2.5}
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
I VAR Byte
pulseCount VAR Byte
DO
GOSUB IR_TEST
FOR I = 1 TO 30
GOSUB Pulsout_Move
NEXT
GOSUB TEST_BUMP
LOOP
IR_TEST:
FREQOUT 3, 1, 38500
irDetectLeft = IN2
FREQOUT 1, 1, 38500
irDetectRight = IN0
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
HIGH 4
HIGH 5
pulseLeft = 650
pulseRight = 850
ELSEIF (irDetectLeft = 0) THEN
HIGH 5
pulseLeft = 850
pulseRight = 850
ELSEIF (irDetectRight = 0) THEN
HIGH 4
pulseLeft = 650
pulseRight = 650
ELSE
LOW 4
LOW 5
pulseLeft = 850
pulseRight = 650
ENDIF
RETURN
PULSOUT_MOVE:
PULSOUT 12,pulseLeft
PULSOUT 13,pulseRight
PAUSE 15
RETURN
TEST_BUMP:
IF (IN6 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (IN7 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
ELSE
GOSUB Forward_Pulse
ENDIF
RETURN
·Forward_Pulse:
PULSOUT 12,850
PULSOUT 13,650
PAUSE 20
RETURN
Turn_Left:
FOR pulseCount = 0 TO 20
PULSOUT 12, 650
PULSOUT 13, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20
PULSOUT 12, 850
PULSOUT 13, 850
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 40
PULSOUT 12, 650
PULSOUT 13, 850
NEXT
RETURN
Post Edited (alleykat) : 1/30/2007 2:26:25 AM GMT
collision detection·for my robot. I was wondering if threre is a more efficient way to test the IR·and bumper
sensors than what I am doing ? What I want the robot to do is
irdetectleft and irdetectright = 0 then, back and turn right
irdetectleft = 0 then, turn right
irdetectright = then, turn left
bumpswitch (IN6 =0), back and turn right
bumpswitch (IN7=0), back and turn left
If IR and micro-switches detect nothing, go forward
' {$STAMP BS2}
' {$PBASIC 2.5}
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
I VAR Byte
pulseCount VAR Byte
DO
GOSUB IR_TEST
FOR I = 1 TO 30
GOSUB Pulsout_Move
NEXT
GOSUB TEST_BUMP
LOOP
IR_TEST:
FREQOUT 3, 1, 38500
irDetectLeft = IN2
FREQOUT 1, 1, 38500
irDetectRight = IN0
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
HIGH 4
HIGH 5
pulseLeft = 650
pulseRight = 850
ELSEIF (irDetectLeft = 0) THEN
HIGH 5
pulseLeft = 850
pulseRight = 850
ELSEIF (irDetectRight = 0) THEN
HIGH 4
pulseLeft = 650
pulseRight = 650
ELSE
LOW 4
LOW 5
pulseLeft = 850
pulseRight = 650
ENDIF
RETURN
PULSOUT_MOVE:
PULSOUT 12,pulseLeft
PULSOUT 13,pulseRight
PAUSE 15
RETURN
TEST_BUMP:
IF (IN6 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (IN7 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
ELSE
GOSUB Forward_Pulse
ENDIF
RETURN
·Forward_Pulse:
PULSOUT 12,850
PULSOUT 13,650
PAUSE 20
RETURN
Turn_Left:
FOR pulseCount = 0 TO 20
PULSOUT 12, 650
PULSOUT 13, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20
PULSOUT 12, 850
PULSOUT 13, 850
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 40
PULSOUT 12, 650
PULSOUT 13, 850
NEXT
RETURN
Post Edited (alleykat) : 1/30/2007 2:26:25 AM GMT