Shop OBEX P1 Docs P2 Docs Learn Events
Combining whisker and IR — Parallax Forums

Combining whisker and IR

justmejustme Posts: 2
edited 2010-12-04 14:40 in BASIC Stamp
I am fairly new to the boe bot, i just got mine in last week. I have been doing some of the sample codes in the book but i want to try and combine them.

Specifically, I am trying to combine the roaming with whisker and avoid table edge. I cant seem to make them work right. Can anyone help?

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-12-04 13:24
    Sure, attach your code and we can help.
  • justmejustme Posts: 2
    edited 2010-12-04 13:32
    DEBUG "Program Running!"
    ' variables

    irDetectLeft VAR Bit ' Variable declarations.
    irDetectRight VAR Bit
    pulseLeft VAR Word
    pulseRight VAR Word
    loopCount VAR Byte
    pulseCount VAR Byte

    FREQOUT 4, 2000, 3000 ' Signal program start/reset.

    DO ' Main Routine.

    '
    IR program

    FREQOUT 8, 1, 38500 ' Check IR detectors.
    irDetectLeft = IN9

    FREQOUT 2, 1, 38500
    irDetectRight = IN0
    ' Decide navigation.

    IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
    pulseCount = 1 ' Both detected,
    pulseLeft = 850 ' one pulse forward.
    pulseRight = 650

    ELSEIF (irDetectRight = 1) THEN ' Right not detected,
    pulseCount = 10 ' 10 pulses left.
    pulseLeft = 650
    pulseRight = 650

    ELSEIF (irDetectLeft = 1) THEN ' Left not detected,
    pulseCount = 10 ' 10 pulses right.
    pulseLeft = 850
    pulseRight = 850

    ELSE ' Neither detected,
    pulseCount = 15 ' back up and try again.
    pulseLeft = 650
    pulseRight = 850

    ENDIF
    FOR loopCount = 1 TO pulseCount ' Send pulseCount pulses
    PULSOUT 13,pulseLeft
    PULSOUT 12,pulseRight
    PAUSE 20
    NEXT
    LOOP

    '
    [ whisker ]

    IF (IN5 = 0) AND (IN7 = 0) THEN ' Both whiskers detect obstacle
    GOSUB Back_Up ' Back up & U-turn (left twice)
    GOSUB Turn_Left
    GOSUB Turn_Left

    ELSEIF (IN5 = 0) THEN ' Left whisker contacts
    GOSUB Back_Up ' Back up & turn right
    GOSUB Turn_Right

    ELSEIF (IN7 = 0) THEN ' Right whisker contacts
    GOSUB Back_Up ' Back up & turn left
    GOSUB Turn_Left

    ELSE ' Both whiskers 1, no contacts
    GOSUB Forward_Pulse ' Apply a forward pulse

    ENDIF ' and check again
    LOOP

    '
    [ Subroutines ]
    Forward_Pulse: ' Send a single forward pulse.
    PULSOUT 13,850
    PULSOUT 12,650
    PAUSE 20
    RETURN

    Turn_Left: ' Left turn, about 90-degrees.
    FOR pulseCount = 0 TO 20
    PULSOUT 13, 650
    PULSOUT 12, 650
    PAUSE 20
    NEXT
    RETURN

    Turn_Right:
    FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
    PULSOUT 13, 850
    PULSOUT 12, 850
    PAUSE 20
    NEXT
    RETURN

    Back_Up: ' Back up.
    FOR pulseCount = 0 TO 40
    PULSOUT 13, 650
    PULSOUT 12, 850
    PAUSE 20
    NEXT
    RETURN
  • FranklinFranklin Posts: 4,747
    edited 2010-12-04 14:40
    OK, first thing is the whisker part will never run because the ir part is a loop that never allows the program to get there. Since the whisker part has the better written (subroutines) code just add the code from the ir (if irdetectleft...... ) into the code as an OR statement
    DO
    If whisker_left = hit OR ir_left = toclose then
    GOSUB move_more_right
    LOOP
    
Sign In or Register to comment.