Shop OBEX P1 Docs P2 Docs Learn Events
ir sensors — Parallax Forums

ir sensors

joy1joy1 Posts: 32
edited 2011-10-21 15:24 in Robotics
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

Comments

  • ercoerco Posts: 20,256
    edited 2011-10-21 15:15
    Specify more precisely when your robot shuts down. Is it when both IR sensors are triggered? Also, add many comments to your code and tell us what you are trying to do. Also, what's on pins 1 and 10... LEDs? Pin 4 is a speaker?
  • ercoerco Posts: 20,256
    edited 2011-10-21 15:24
    Also, you mistakenly keep looking at IN0 and IN9 long after your have sent your IR pulsouts. The reading has changed by then, so you'll always get 1s. Try this. After:

    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.
Sign In or Register to comment.