Shop OBEX P1 Docs P2 Docs Learn Events
Pbasic loop until — Parallax Forums

Pbasic loop until

Jimi FreemanJimi Freeman Posts: 46
edited 2009-01-07 00:44 in BASIC Stamp
Hello everyone. I am new to robotting. I recently purchased and completed all of the excersices in the boe-bot activities book. In one of the activities you are asked to build a program that has the bot sit still until the IR detects motion, then proceed towards it. It uses the DO LOOP UNTIL commands to accomplish this. The problem is, LOOP UNTIL (irLeft = 0 ) OR (irRight=0) is invalid? If at any point when the bot is moving forward it "loses sight" it stops. How can this be avoided? I have coupled the IR sensors w/ the PING ultra sonic ))) sensor, (without the mounting bracket). The problem is, the bot sits still until it sees something, once it sees it it proceeds forward, and uses the ping sensors to navigate from there. It seems that as the program iterates and completes itself, it jumps back to the DO LOOP UNTIL. I have tried creating a DO LOOP UNTIL then creating a Main: subroutine, that keeps GOSUBing to MAIN, but it still seems to execute the LOOP UNTIL bit. Any recommendations?

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2009-01-06 00:44
    Mr. Freeman

    Post the code Your using and We'll go from there.


    _________________$WMc%____________

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there·········································· E=$WMc%2
  • Jimi FreemanJimi Freeman Posts: 46
    edited 2009-01-06 00:47
    I didnt really have specific code saved, but maybe something like this?
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    irDetectLeft VAR Bit
    irDetectRight VAR Bit
    
    pulseLeft VAR Word
    pulseRight VAR Word
    
    DO
    FREQOUT 8,1,38500
    irDetectLeft = IN9
    
    FREQOUT 2,1,38500
    irDetectRight = IN0
    
    PAUSE 100
    LOOP UNTIL (irDetectRight = 0 ) OR (irDetectLeft = 0 ) 
    
    DO
    
    FREQOUT 8,1,38500
    irDetectLeft = IN9
    
    FREQOUT 2,1,38500
    irDetectRight = IN0
    
    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
    
  • FranklinFranklin Posts: 4,747
    edited 2009-01-06 01:55
    If you have no code you can't program the bot. Please ATTACH the code you are loading into the stamp to make it do what it does. The code you included in your previous post works just fine. Take off the ping and get one thing working before you add new hardware.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Jimi FreemanJimi Freeman Posts: 46
    edited 2009-01-06 02:07
    That makes no sense frank. The code is fine. The ping sensors are fine. The robot waits until it receives data back from the IR system. Once it receives it, it begins to move forward. HOWEVER, if it loses the signal, it stops and waits until it finds it again. I only want the DO LOOP UNTIL loop to iterate the first time the program is loaded, and not load again until the program is reset. Also, the code I pasted was the code I attempted to run. It works perfectly, accept the continuous loop.
  • FranklinFranklin Posts: 4,747
    edited 2009-01-06 02:14
    In the code you listed there are no ping sensors and what do you mean by looses signal and how do you know it does this? Put a debug statement before the first do and see if it gets there more than once in the program. If it does your program is restarting and you need to find out why (usually power problems or loose connections)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Jimi FreemanJimi Freeman Posts: 46
    edited 2009-01-06 02:20
    I posted what i thought were the relevant bits.

    irDetectLeft VAR Bit
    irDetectRight VAR Bit

    pulseLeft VAR Word
    pulseRight VAR Word

    DO

    FREQOUT 8,1,38500
    irDetectLeft = IN9

    FREQOUT 2,1,38500
    irDetectRight = IN0


    PAUSE 100

    LOOP UNTIL (irLeft = 0 ) or (irRight = 0 )


    DO


    PULSOUT 9, 1
    PULSIN 9, 1, time


    FREQOUT 2,1,38500


    IF (time > 550 ) THEN
    pulseCount = 10
    GOSUB Forward
    ENDIF





    IF (time < 450 ) THEN
    pulseCount = 20
    GOSUB Left
    ENDIF

    Forward:
    FOR loopCount = 1 TO pulseCount
    PULSOUT 13,850
    PULSOUT 12,650
    PAUSE 20
    NEXT
    RETURN

    Left:
    FREQOUT 7,500,4000
    FOR LOOPCount = 1 TO 300
    PULSOUT 13,650
    PULSOUT 12,850
    NEXT
    FREQOUT 7,500,4000

    FOR loopCount = 1 TO pulseCount
    PULSOUT 13,650
    PULSOUT 12,650
    PAUSE 20
    NEXT
    RETURN


    LOOP



    If I run it w/ debug statements inside the do loop until portion, it constantly says it until the IR receives and sees an object. Then it leaves the loop and continutes down the rest of the code. The problem is, if it loses the initial object, it stops until the IR 'sees' something. i just want to use the IR as a start control, and then let PING take over from there.
  • FranklinFranklin Posts: 4,747
    edited 2009-01-06 02:26
    Please go to the "Post Reply" button and "ATTACH" your actual .bs file so we can see the REAL code. The code you posted is trying to do the loop until on two variables you have not declared and do not populate. It would not even compile as you posted it so I can't help you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Jimi FreemanJimi Freeman Posts: 46
    edited 2009-01-06 02:33
    Sorry, i didnt realize I could upload. I have been typing it in manually. Also, english is not my first language, so bare with me. Thank you.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-01-06 03:10
    Is this the routine that your from

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • Jimi FreemanJimi Freeman Posts: 46
    edited 2009-01-06 03:17
    Unfortunately, I did not see that code, although I wish I had now. I just used the PBASIC manual that came w/ my kit, and some online documentation to do the PING portion. Any ideas why it continues the loop until after each iteration of the second DO?
  • FranklinFranklin Posts: 4,747
    edited 2009-01-06 03:19
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    irDetectLeft VAR Bit
    irDetectRight VAR Bit
    pulseLeft VAR Word
    pulseRight VAR Word
    time VAR Word
    pulseCount VAR Word
    loopCount VAR Word
     
    DO
    FREQOUT 8,1,38500
    irDetectLeft = IN9
    FREQOUT 2,1,38500
    irDetectRight = IN0
    
    PAUSE 100
    LOOP UNTIL (irDetectLeft = 0 ) OR (irDetectRight = 0 )
    
    DO
    
    PULSOUT 9, 1
    PULSIN 9, 1, time
    
    FREQOUT 2,1,38500
    
    IF (time > 550 ) THEN
    pulseCount = 10
    GOSUB Forward
    ENDIF                    <<< subroutine forward returns here
     
     
    IF (time < 450 ) THEN
    pulseCount = 20
    GOSUB Left   
    ENDIF                     <<< subroutine left returns here
     
     
    <<<<<<<<<<<<<<<< you want to loop here BEFORE you fall through the routines
     
    Forward:
    FOR loopCount = 1 TO pulseCount
    PULSOUT 13,850
    PULSOUT 12,650
    PAUSE 20
    NEXT
    RETURN
    Left:
    FREQOUT 7,500,4000
    FOR LOOPCount = 1 TO 300
    PULSOUT 13,650
    PULSOUT 12,850
    NEXT
    FREQOUT 7,500,4000
    FOR loopCount = 1 TO pulseCount
    PULSOUT 13,650
    PULSOUT 12,650
    PAUSE 20
    NEXT
    RETURN
    
    LOOP                       <<< this should be BEFORE the subroutines !!!
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-01-06 03:38
    · Jimi Freeman

    Franklin·is right about where the routine start and stop and where you put your LOOP command

    That makes a different where you put it and how it will work

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • Jimi FreemanJimi Freeman Posts: 46
    edited 2009-01-07 00:44
    Thank you for the help everyone.
Sign In or Register to comment.