ir sensors
We are having problems with our IR sensors. Our servo's shut down when we hit the corners. Can anyone help please.
Here's the code:
' Robotics with the Boe_Bot - FastIrRoaming.bs2
' Higher performance IR object detection assisted navigation
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
old9 VAR Bit
old0 VAR Bit
counter VAR Word
x VAR Word
FREQOUT 4, 2000, 3000
DO
FREQOUT 8, 1, 38500
irDetectLeft = IN9
FREQOUT 2, 1, 38500
irDetectRight = IN0
IF (IN0 = 0) AND (IN9 = 0) THEN
HIGH 10
HIGH 1
ENDIF
IF (irDetectLeft = 0)THEN
HIGH 10
ELSE
LOW 10
ENDIF
IF (irDetectRight = 0) THEN
HIGH 1
ELSE
LOW 1
ENDIF
IF (IN9 <> IN0) THEN
IF (old9 <> IN9) AND (old0 <> IN0) THEN
counter = counter + 1
old9 = IN9
old0 = IN0
IF (counter > 10) THEN
counter = 1
DO
GOSUB Backwards
GOSUB Right_turn
LOOP UNTIL (IN9 = 1) AND (IN0 = 1)
ENDIF
ELSE
counter = 1
ENDIF
ENDIF
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseLeft = 650
pulseRight = 850
ELSEIF (irDetectLeft = 0)THEN
pulseLeft = 850
pulseRight = 850
ELSEIF (irDetectRight = 0)THEN
pulseLeft = 650
pulseRight = 650
ELSE
pulseLeft = 850
pulseRight = 650
ENDIF
PULSOUT 13, pulseLeft
PULSOUT 12, pulseRight
PAUSE 15
LOOP
Backwards:
FOR x = 1 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Right_turn:
FOR x = 1 TO 40
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Here's the code:
' Robotics with the Boe_Bot - FastIrRoaming.bs2
' Higher performance IR object detection assisted navigation
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
old9 VAR Bit
old0 VAR Bit
counter VAR Word
x VAR Word
FREQOUT 4, 2000, 3000
DO
FREQOUT 8, 1, 38500
irDetectLeft = IN9
FREQOUT 2, 1, 38500
irDetectRight = IN0
IF (IN0 = 0) AND (IN9 = 0) THEN
HIGH 10
HIGH 1
ENDIF
IF (irDetectLeft = 0)THEN
HIGH 10
ELSE
LOW 10
ENDIF
IF (irDetectRight = 0) THEN
HIGH 1
ELSE
LOW 1
ENDIF
IF (IN9 <> IN0) THEN
IF (old9 <> IN9) AND (old0 <> IN0) THEN
counter = counter + 1
old9 = IN9
old0 = IN0
IF (counter > 10) THEN
counter = 1
DO
GOSUB Backwards
GOSUB Right_turn
LOOP UNTIL (IN9 = 1) AND (IN0 = 1)
ENDIF
ELSE
counter = 1
ENDIF
ENDIF
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseLeft = 650
pulseRight = 850
ELSEIF (irDetectLeft = 0)THEN
pulseLeft = 850
pulseRight = 850
ELSEIF (irDetectRight = 0)THEN
pulseLeft = 650
pulseRight = 650
ELSE
pulseLeft = 850
pulseRight = 650
ENDIF
PULSOUT 13, pulseLeft
PULSOUT 12, pulseRight
PAUSE 15
LOOP
Backwards:
FOR x = 1 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Right_turn:
FOR x = 1 TO 40
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Comments
FREQOUT 8, 1, 38500
irDetectLeft = IN9
FREQOUT 2, 1, 38500
irDetectRight = IN0
Change all your IN0's to irDetectRight and change all your IN9's to irDetectLeft.