Shop OBEX P1 Docs P2 Docs Learn Events
Escaping corners activity limit to 3 min roaming time — Parallax Forums

Escaping corners activity limit to 3 min roaming time

Hi all,
I'm just going through the activities in the book. I'm new to programming and robotics.
I completed the Escaping corners activity in Ch 5. page 161.
The bot goes on in an infinite loop and I would like to limit the time it runs to stop at about 3 minutes. I don't care if it is exact.

Any pointers would be appreciated.

Comments

  • Here is the activity I am referring to from the book:

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

    DEBUG "Program Running"

    pulseCount VAR Byte
    counter VAR Nib
    old7 VAR Bit
    old5 VAR Bit

    FREQOUT 4, 2000, 3000

    counter = 1
    old7 = 0
    old5 = 1


    DO
    IF (IN7 <> IN5) THEN
    IF (old7 <> IN7) AND (old5 <> IN5) THEN
    counter = counter + 1
    old7 = IN7
    old5 = IN5
    IF (counter > 4) THEN
    counter = 1
    GOSUB back_up
    GOSUB turn_left
    GOSUB turn_left
    ENDIF
    ELSE
    counter = 1
    ENDIF
    ENDIF

    IF (IN5 = 0) AND (IN7 = 0) THEN
    GOSUB back_up
    GOSUB turn_left
    GOSUB turn_left
    ELSEIF (IN5 = 0) THEN
    GOSUB back_up
    GOSUB turn_right
    ELSEIF (IN7 = 0) THEN
    GOSUB back_up
    GOSUB turn_left
    ELSE
    GOSUB forward_pulse
    ENDIF
    LOOP

    forward_pulse:
    PULSOUT 13, 850
    PULSOUT 12, 650
    PAUSE 20
    RETURN

    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
  • mikegalin,

    Did you know that you can add a condition to a DO...LOOP?
    Refer to the DO...LOOP command in The BASIC Stamp Manual (bottom of Page 176).
    https://www.parallax.com/sites/default/files/downloads/27218-Web-BASICStampManual-v2.2.pdf

    Notice the END command after LOOP in the Demo program on page 177.
    The END command is explained on page 187.

    As for timing, do you see that each move routine has a PAUSE 20.
    The PAUSE command is on page 311.
    How many of these pauses would be in a minute?
    If you have a time variable increment (add 1 to it) after each PAUSE 20 then you will have a rough timer.

    Once your time variable hits the magic number your program will stop.

    This is optional but I like to use CONstants at the top of my program so I can easily make changes.
    The CON directive is explained on pages 94 to 96.
    The BOE-Bot uses a BASIC Stamp 2 (BS2) so ignore anything regarding the BS1.
Sign In or Register to comment.