Shop OBEX P1 Docs P2 Docs Learn Events
Boe-bot > stop with sensors (need help for school) — Parallax Forums

Boe-bot > stop with sensors (need help for school)

LauwereysMLauwereysM Posts: 1
edited 2009-05-03 22:12 in BASIC Stamp
Hey, I have a boe-bot and I use the boe-bot for a project on school, but I have a problem.
I wan't to have it like this > I make a program that he for example first ride straight and then ride to the left ...
But when something is in front of the sensors, the boe-bot needs to stop. I already make a program for the project and the sensors and they worked both, but they need to work together.
I don't know how to put those two projects together. So he is do the project (left, right, ...) and he stops when something is in front of it.

Here you see my project:

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

FREQOUT 5, 1000, 3000

pulsecount VAR Byte

PAUSE 2000

' Start from the base.
FOR pulsecount = 1 TO 141
PULSOUT 13, 850 + pulsecount
PULSOUT 12, 650 - pulsecount
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 100
PULSOUT 14, 500
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 20
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 100
PULSOUT 14, 1000
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 20
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 40
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 35
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 50
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 100
PULSOUT 14, 500
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 20
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 100
PULSOUT 14, 1000
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 40
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 50
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 120
PULSOUT 13, 850 + pulsecount
PULSOUT 12, 650 - pulsecount
PAUSE 20
NEXT

PAUSE 200

FOR pulsecount = 1 TO 40
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT

FREQOUT 5, 200, 3000
PAUSE 50
FREQOUT 5, 200, 3000

END

This is for the sensors (I hope that this is good)

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

irdetectleft VAR Bit
irdetectright VAR Bit
pulseleft VAR Word
pulseright VAR Word
loopcount VAR Byte
pulsecount VAR Byte

DO

FREQOUT 8, 1, 38500
irdetectleft = IN9
FREQOUT 4, 1, 38500
irdetectright = IN3

ELSEIF (irdetectleft = 0) OR (irdetectright = 0) THEN
pulsecount = 0
pulseleft = 750
pulseright = 750
ENDIF

FOR loopcount = 1 TO pulsecount
PULSOUT 13,pulseleft
PULSOUT 12,pulseright
PAUSE 20
NEXT

LOOP


Ok, I need to combinate those two. The course of the boe-bot needs to stay.

THX

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-05-03 22:12
    The simplest hack would be to simple put an GOSUB in each loop that will call the detection subroutine, and if it detects an object to END. The more elegant solution would be to have each of your motions be contained in three lookup tables (one each for the servos, and one for the counter), and have a master loop that does the lookups and the small movement routine (again, inside of which you'll have the GOSUB).
Sign In or Register to comment.