Shop OBEX P1 Docs P2 Docs Learn Events
hooking up more than one system of navigation — Parallax Forums

hooking up more than one system of navigation

Rorygal2991Rorygal2991 Posts: 1
edited 2007-01-05 18:55 in BASIC Stamp
i'm in a high school robotics class and have no idea what i'm doing. is there any way to hook up the whiskers system along with the photoresistors? i need to get the Boe-Bot through a maze then do a few circles at the end when it senses a light at the end. also, here is the code I'm usingfor the whiskers. is there any way(s) i can improve it? Thank You

'
[noparse][[/noparse] Title ]
'Robotics with the Boe-Bot - EscapingCorners.bs2
'Boe-Bot navigate out of corners by detecting alternating wisker presses.

'{$STAMP BS2} ' Stamp directive
'{$PBASIC 2.5} ' PBASIC directive

DEBUG "Program Running!"

'
[noparse][[/noparse] Variables ]

pulseCount VAR Byte 'FOR...NEXT loop counter.
counter VAR Nib 'Counts alternate contacts.
old7 VAR Bit 'Stores previous IN7.
old5 VAR Bit 'Stores previous IN5.


'
[noparse][[/noparse] Initialization ]

FREQOUT 4, 2000, 3000 'Signal program start/reset.
counter = 1 'start alternate corner count.
old7 = 0 'Make up old values.
old5 = 1

'
[noparse][[/noparse] Main Routine ]

DO

' --- Detect Consecutive Alternate Corners
'See the "How EscapingCorners.bs2 Works" section that follows this program.

IF (IN7 <> IN5) THEN ' One or other is pressed.
IF (old7 <> IN7) AND (old5 <> IN5) THEN ' Different form previous.
counter = counter + 1 ' Alternate whisker count +1.
old7 = IN7 ' Record this whisker press
old5 = IN5 ' for next comparison.
IF (counter > 4) THEN ' If alternate whisker count = 4
counter = 1 ' reset whisker counter.
FREQOUT 4, 750, 3000
GOSUB Back_Up ' and execute a U-turn.
GOSUB Turn_Left
GOSUB Turn_Left
ENDIF ' ENDIF counter > 4.
ELSE ' ELSE (old7=IN7) or (old5=IN5),
counter = 1 ' not alternate, reset counter.
ENDIF ' ENDIF (old7<>IN7) and
' (old5<>IN5).
ENDIF ' ENDIF (IN7<>IN5).

' --- Same navigation routine from RoamingWithWhiskers.bs2

IF (IN5 = 0) AND (IN7 = 0) THEN 'Both whiskers detect obstacle
GOSUB Back_Up 'Back up & U-turn (left twice)
GOSUB Turn_Right
GOSUB Turn_Right
ELSEIF (IN7 = 0) THEN 'Left whisker contacts
GOSUB Back_Up 'Back up & turn right
GOSUB Turn_Right
GOSUB Turn_Right
ELSEIF (IN5 = 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

'
[noparse][[/noparse] Subroutine ]

Forward_Pulse: 'Send a single forward pulse.
PULSOUT 13, 1000
PULSOUT 12, 500
PAUSE 20
RETURN

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

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

Back_Up: 'Back up.
FOR pulseCount = 0 TO 20
PULSOUT 13, 500
PULSOUT 12, 1000
PAUSE 20
NEXT
RETURN

Comments

  • AImanAIman Posts: 531
    edited 2007-01-05 18:55
    Yes

    First - indent your code, makes it more readable.

    Example:

    Your posted code -

    IF (IN7 <> IN5) THEN ' One or other is pressed.
    IF (old7 <> IN7) AND (old5 <> IN5) THEN ' Different form previous.
    counter = counter + 1 ' Alternate whisker count +1.
    old7 = IN7 ' Record this whisker press
    old5 = IN5 ' for next comparison.
    IF (counter > 4) THEN ' If alternate whisker count = 4
    counter = 1 ' reset whisker counter.
    FREQOUT 4, 750, 3000
    GOSUB Back_Up ' and execute a U-turn.
    GOSUB Turn_Left
    GOSUB Turn_Left
    ENDIF ' ENDIF counter > 4.
    ELSE ' ELSE (old7=IN7) or (old5=IN5),
    counter = 1 ' not alternate, reset counter.
    ENDIF ' ENDIF (old7<>IN7) and
    ' (old5<>IN5).
    ENDIF ' ENDIF (IN7<>IN5).

    Redone with indents -

    IF (IN7 <> IN5) THEN ' One or other is pressed.
    ·· IF (old7 <> IN7) AND (old5 <> IN5) THEN ' Different form previous.
    ····· counter = counter + 1 ' Alternate whisker count +1.
    ····· old7 = IN7 ' Record this whisker press
    ····· old5 = IN5 ' for next comparison.
    ········ IF (counter > 4) THEN ' If alternate whisker count = 4
    ··········· counter = 1 ' reset whisker counter.
    ··········· FREQOUT 4, 750, 3000
    ··········· GOSUB Back_Up ' and execute a U-turn.
    ··········· GOSUB Turn_Left
    ··········· GOSUB Turn_Left
    ········ ENDIF ' ENDIF counter > 4.
    ····· ELSE ' ELSE (old7=IN7) or (old5=IN5),
    ········ counter = 1 ' not alternate, reset counter.
    ····· ENDIF ' ENDIF (old7<>IN7) and·(old5<>IN5).
    ENDIF ' ENDIF (IN7<>IN5).

    Second - and most importantly - over comment everything. Repeat after me - over comment everything. Be CLEAR on your comments. You used GOSUB Back_Up ' and execute a U-turn. You could say - Gosub Back_Up ' Makes robot back up and do a U-Turn.
    More wording but easier to read.

    Third·- Why do you need to compare old whisker readings?
    Whiskers are only tripped or not tripped there is no in-between. Do you have a reason to keep the old readings? I don't keep mine so I would simply strip those out. Keeping old IR, Sonar or light readings I can see but I don't understand keeping the old whisker readings.

    Lastly - try to run as few variables as possible. Saves memory and tends to keep things more simple. Follow the KISS method or the PHD method. (KISS - Keep It Simple Stupid. PHD - Push Here Dummy.)

    If you are only going to use whiskers with a photoresistor then simply expect things to be a little slower for reaction times and take a lot longer. If possible upgrade to IR or sonar instead of using whiskers.

    My Arobot by Arrick Robotics ran on whiskers when I got it and it sucked. If it was in a place like the bathroom it could miss the door for a very long time before the correct angle was acheived simply because it was backing up and turning with no way to find the correct location to exit. Using IR or Sonar can greatly aid in·detecting a open door and are much easier and save time - not to mention your frustrationg level being reduced and hair saved because it didn't get pulled out.

    Whats a Microcontroller goes into how to hook up photoresistors as does a couple of other books - think the BOE BOT book does as well. Regardless, hook up your photoresistor to run and then run sonar or IR off a couple of other pins. When you code it code each item for the pins set up. If you are using sonar there is a posting I had about the SRF04 that has at least 4 different code sources posted. If you are using IR then the BOE BOT book - chapter 7 I think - has how to hook up IR headlights. Either way, you hook up all three to different pins and code so that the correct stuff goes to the correct pin. Its not nearly as complex as it sounds, just gets a little frustrating the first few times you try it.

    There is also a demo and sample code posted for how Parallax ran a Boe Bot that used sonar to find and center on the neaerest object.

    By using the books listed (both are free for download from the Parallax website) you can make light tracking programs and learn about using IR, Servos, Photoresistors and various other stuff.

    Maze solving can be fun stuff but can also be VERY frustrating if you have to use things like whiskers because of the extra time to wait for a robot to wander around an empty spot before figuring out where the exit is at.

    Post Edited (AIman) : 1/5/2007 6:59:41 PM GMT
Sign In or Register to comment.