Shop OBEX P1 Docs P2 Docs Learn Events
infrared + whiskers program problem — Parallax Forums

infrared + whiskers program problem

zack787zack787 Posts: 2
edited 2012-03-07 06:03 in Robotics
Hi. I'm a newb to this Boe-Bot stuff and I have come across a problem. I found a program that allows you to use both the infrared and the whiskers at the same time on the Boe-Bot. After noticing a few errors, I came up with the program below. The problem is that on this program, only the whiskers work. I have tested the infrared on another program with the current circuitry and it worked. But it doesnt even seem to work on this program.

Any ideas would be extremely helpful. Thanks a bunch.


' {$STAMP BS2}
' {$PBASIC 2.5}
FREQOUT 4, 2000, 3000
DO
FREQOUT 8, 1, 38500
FREQOUT 2, 1, 38500
IF (IN0 = 0) AND (IN9 = 0) AND (IN5 = 0) AND (IN7 = 0) THEN
PULSOUT 13, 650
PULSOUT 12, 850
ELSEIF (IN0 = 0) AND (IN9 = 0) THEN
PULSOUT 13, 650
PULSOUT 12, 850
ELSEIF (IN5 = 0) AND (IN7 = 0)· THEN
PULSOUT 13, 650
PULSOUT 12, 850
ELSEIF (IN0 = 0) AND (IN5 = 0) THEN
PULSOUT 13, 850
PULSOUT 12, 850
ELSEIF (IN7 = 0) AND (IN9 = 0)· THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSEIF (IN7 = 0) THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSEIF (IN9 = 0)· THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSEIF (IN0 = 0) THEN
PULSOUT 13, 850
PULSOUT 12, 850
ELSEIF (IN5 = 0)·· THEN
PULSOUT 13, 850
PULSOUT 12, 850
ELSEIF (IN0 <> 0) AND (IN9 <> 0) AND (IN5 <> 0) AND (IN7 <> 0)··· THEN
PULSOUT 13, 850
PULSOUT 12, 650
ELSEIF (IN0 <> 0) AND (IN9 <> 0)····· THEN
PULSOUT 13, 850
PULSOUT 12, 650
ENDIF
LOOP

Comments

  • A.C. fishingA.C. fishing Posts: 262
    edited 2006-03-25 23:45
    Hardware:
    make sure the Irs aren't touching the whiskers in any way.
    Software:
    Here is mine:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    DO
    freqout 2, 38500
    freqout 8, 38500
    IF (IN0 = 0) AND (IN9 = 0) AND (IN5 = 0) AND (IN7 = 0) THEN
    PULSOUT 13, 650
    PULSOUT 12, 850
    ELSEIF (IN0 = 0) AND (IN9 = 0) THEN
    PULSOUT 13, 850
    PULSOUT 12, 850
    ELSEIF (IN5 = 0) AND (IN7 = 0)  THEN
    PULSOUT 13, 650
    PULSOUT 12, 650
    ELSEIF (IN0 = 0) AND (IN5 = 0) THEN
    PULSOUT 13, 850
    PULSOUT 12, 850
    ELSEIF (IN7 = 0) AND (IN9 = 0)  THEN
    PULSOUT 13, 650
    PULSOUT 12, 650
    ELSEIF (IN7 = 0) THEN
    PULSOUT 13, 650
    PULSOUT 12, 650
    ELSEIF (IN9 = 0)  THEN
    PULSOUT 13, 650
    PULSOUT 12, 650
    ELSEIF (IN0 = 0) THEN
    PULSOUT 13, 850
    PULSOUT 12, 850
    ELSEIF (IN5 = 0)   THEN
    PULSOUT 13, 850
    PULSOUT 12, 850
    ELSEIF (IN0 <> 0) AND (IN9 <> 0) AND (IN5 <> 0) AND (IN7 <> 0)    THEN
    PULSOUT 13, 850
    PULSOUT 12, 650
    ELSEIF (IN0 <> 0) AND (IN9 <> 0)      THEN
    PULSOUT 13, 850
    PULSOUT 12, 650
    ENDIF
    LOOP
    
  • zack787zack787 Posts: 2
    edited 2006-03-26 05:33
    Thanks for the suggestion, but it didn't work. Any other ideas? Thanks.

    Also, I am pretty sure that I have wired everything on the board correctly, but is it possible, even though each system works fine independently,· that I could have wired it wrong for them to operate together?

    Post Edited (zack787) : 3/26/2006 5:39:26 AM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-03-27 00:41
    The IR collision detectors work by outputting a 38 Khz IR-LED signal, then trying to read the response from an IR-Detector which is looking for a IR signal blinking at 38 Khz. With a single-tasking unit like the BS2, this ONLY works because the detector continues to output a signal for a little while, even though the IR signal has gone away. But, this does mean you MUST read the IR-Detector signal IMMEDIATELY after sending the FREQOUT.

    In your code, it looks like you're "Blinking Left", then "Blinking Right", and only THEN trying to read the 'Left' detector, then the 'Right' detector. It doesn't surprise me that by the time your code FINALLY gets around to reading the IR-Detectors, they've gone back to idle.

    Not only that, but you're not SAVING THE STATE of the IR-Detectors. Once you gone through all those "ELSEIF" clauses, any reflection signal will be long gone.

    Sounds like time to get the concept of "variables". So:

    MyLeft VAR BIT
    MyRight VAR BIT

    FREQOUT 2, 38500
    MyLeft = IN0
    FREQOUT 8, 38500
    MyRight = IN9

    'Now, you can run your decision code based on "MyLeft" and "MyRight" 'hit' codes,
    which should be valid now since you'll be reading the IR-Detector immediatly after
    the FREQOUT.
  • dragonmantwodragonmantwo Posts: 3
    edited 2012-03-07 06:03
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}


    DEBUG "program running"


    irdetectleft VAR Bit
    irdetectright VAR Bit
    pulseleft VAR Word
    pulseright VAR Word
    loopcount VAR Byte
    pulsecount VAR Byte


    FREQOUT 15, 2000, 3000


    DO
    FREQOUT 8, 1, 38500
    irdetectleft = IN9
    FREQOUT 2, 1, 38500
    irdetectright = IN0


    IF (IN3 = 0) AND (IN7 = 0) THEN
    GOSUB Back_Up
    GOSUB Turn_Left
    GOSUB Turn_Left
    ELSEIF (IN3 = 0) THEN
    GOSUB Back_Up
    GOSUB Turn_Right
    ELSEIF (IN0 = 0) THEN
    GOSUB Back_Up
    GOSUB Turn_Left
    ENDIF


    IF (irdetectleft = 0) AND (irdetectright = 0) THEN
    pulsecount = 1
    pulseleft = 850
    pulseright = 650
    ELSEIF (irdetectright = 1) THEN
    pulsecount = 10
    pulseleft = 650
    pulseright = 650
    ELSEIF (irdetectleft = 1) THEN
    pulsecount = 10
    pulseleft = 850
    pulseright = 850
    ELSE
    pulsecount = 15
    pulseleft = 650
    pulseright = 850
    ENDIF


    FOR LOOPcount = 1 TO pulsecount
    PULSOUT 13, pulseleft
    PULSOUT 12, pulseright
    PAUSE 20
    NEXT
    LOOP




    'subrountines


    Turn_Left:
    FOR pulsecount = 0 TO 20
    PULSOUT 13, 650
    PULSOUT 12, 650
    PAUSE 20
    NEXT
    RETURN


    Turn_Right:
    FOR pulsecount = 0 TO 20
    PULSOUT 13, 850
    PULSOUT 12, 850
    PAUSE 20
    NEXT
    RETURN


    Back_Up:
    FOR pulsecount = 0 TO 40
    PULSOUT 13, 650
    PULSOUT 12, 850
    PAUSE 20
    NEXT
    RETURN


    i found this works, hav fun
Sign In or Register to comment.