how do i?
I'm trying to make my bot turn right then left after the same event.
I have sub routines that make it go right, left and forward. I’m using inferred to detect something in front of it. So it should be moving forward and when it sees the thing in front it should turn right and keeps moving. If it sees something in front of it again, it should turn left and keep moving. Any help on what to put in the do loop?
I have sub routines that make it go right, left and forward. I’m using inferred to detect something in front of it. So it should be moving forward and when it sees the thing in front it should turn right and keeps moving. If it sees something in front of it again, it should turn left and keep moving. Any help on what to put in the do loop?
Comments
' {$STAMP BS2}
' {$PBASIC 2.5}
irdetect VAR Bit
pulse VAR Byte
DO
GOSUB move
GOSUB forward
LOOP
move:
FREQOUT 4, 1, 38500
irdetect = IN6
IF (irdetect = 0) THEN
GOSUB right
ENDIF
forward:
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
RETURN
right:
· FOR· pulse = 0 TO 20
·· PULSOUT 13, 850
·· PULSOUT 12, 850
·· PAUSE 20
· NEXT
· RETURN
left:
· FOR· pulse = 0 TO 20
·· PULSOUT 12, 650
·· PULSOUT 13, 650
·· PAUSE 20
· NEXT
· RETURN
Create another bit VAR called "last" or something. When you have turned right set the bit to 1, when left, set it to zero. Check it each time before deciding which way to turn.
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
I'm not sure if you guys understand what i'm trying to accomplish. The bot will be moving forward...when it sees something, it turns right and continue moving forward... when it sees something for a second time it turns left and continue mocing forward... and it keeps alternating between the two.
my code so far:
' {$STAMP BS2}
' {$PBASIC 2.5}
irdetect VAR Bit
pulse VAR Byte
last VAR Bit
last = 0
DO
GOSUB forward
GOSUB move
DEBUG DEC last
LOOP
move:
FREQOUT 4, 1, 38500
irdetect = IN6
IF (irdetect = 0) THEN
GOSUB right
last = last + 1
ENDIF
RETURN
forward:
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
RETURN
right:
FOR pulse = 0 TO 20
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
left:
FOR pulse = 0 TO 20
PULSOUT 12, 650
PULSOUT 13, 650
PAUSE 20
NEXT
RETURN
IF (irdetect = 0) THEN
GOSUB right
last = 1
ENDIF
RETURN
should i keep the RETURN or should I do this:
IF (irdetect = 0) THEN
GOSUB right
last = 1
ELSE
GOSUB forward
ENDIF
Now what should i do after i do that? you said " If this variable is a one, change the variable to zero, call the turn left routine, then continue." What variable are you talking about? my "last" variable? It got changed to a 1 and returned to the loop. Now what?
This block of code goes between the "IF (irdetect = 0) THEN" and the matching "ENDIF"
The other case (variable is zero) is done the same way.
The BoeBot moves forward, checks for an obstacle, and goes either left or right on alternate attempts.