Pbasic loop until
Jimi Freeman
Posts: 46
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- 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··that you may have and all of your time finding them
·
·
·
·
Sam
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- 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··that you may have and all of your time finding them
·
·
·
·
Sam