Pbasic loop until
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
Post the code Your using and We'll go from there.
_________________$WMc%____________
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there·········································· E=$WMc%2
' {$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▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
' {$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
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·
·
·
·
·
Sam