infrared + whiskers program problem
Hi. I'm a newb to this Boe-Bot stuff and I have come across a problem. I found a program that allows you to use both the infrared and the whiskers at the same time on the Boe-Bot. After noticing a few errors, I came up with the program below. The problem is that on this program, only the whiskers work. I have tested the infrared on another program with the current circuitry and it worked. But it doesnt even seem to work on this program.
Any ideas would be extremely helpful. Thanks a bunch.
' {$STAMP BS2}
' {$PBASIC 2.5}
FREQOUT 4, 2000, 3000
DO
FREQOUT 8, 1, 38500
FREQOUT 2, 1, 38500
IF (IN0 = 0) AND (IN9 = 0) AND (IN5 = 0) AND (IN7 = 0) THEN
PULSOUT 13, 650
PULSOUT 12, 850
ELSEIF (IN0 = 0) AND (IN9 = 0) THEN
PULSOUT 13, 650
PULSOUT 12, 850
ELSEIF (IN5 = 0) AND (IN7 = 0)· THEN
PULSOUT 13, 650
PULSOUT 12, 850
ELSEIF (IN0 = 0) AND (IN5 = 0) THEN
PULSOUT 13, 850
PULSOUT 12, 850
ELSEIF (IN7 = 0) AND (IN9 = 0)· THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSEIF (IN7 = 0) THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSEIF (IN9 = 0)· THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSEIF (IN0 = 0) THEN
PULSOUT 13, 850
PULSOUT 12, 850
ELSEIF (IN5 = 0)·· THEN
PULSOUT 13, 850
PULSOUT 12, 850
ELSEIF (IN0 <> 0) AND (IN9 <> 0) AND (IN5 <> 0) AND (IN7 <> 0)··· THEN
PULSOUT 13, 850
PULSOUT 12, 650
ELSEIF (IN0 <> 0) AND (IN9 <> 0)····· THEN
PULSOUT 13, 850
PULSOUT 12, 650
ENDIF
LOOP
Any ideas would be extremely helpful. Thanks a bunch.
' {$STAMP BS2}
' {$PBASIC 2.5}
FREQOUT 4, 2000, 3000
DO
FREQOUT 8, 1, 38500
FREQOUT 2, 1, 38500
IF (IN0 = 0) AND (IN9 = 0) AND (IN5 = 0) AND (IN7 = 0) THEN
PULSOUT 13, 650
PULSOUT 12, 850
ELSEIF (IN0 = 0) AND (IN9 = 0) THEN
PULSOUT 13, 650
PULSOUT 12, 850
ELSEIF (IN5 = 0) AND (IN7 = 0)· THEN
PULSOUT 13, 650
PULSOUT 12, 850
ELSEIF (IN0 = 0) AND (IN5 = 0) THEN
PULSOUT 13, 850
PULSOUT 12, 850
ELSEIF (IN7 = 0) AND (IN9 = 0)· THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSEIF (IN7 = 0) THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSEIF (IN9 = 0)· THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSEIF (IN0 = 0) THEN
PULSOUT 13, 850
PULSOUT 12, 850
ELSEIF (IN5 = 0)·· THEN
PULSOUT 13, 850
PULSOUT 12, 850
ELSEIF (IN0 <> 0) AND (IN9 <> 0) AND (IN5 <> 0) AND (IN7 <> 0)··· THEN
PULSOUT 13, 850
PULSOUT 12, 650
ELSEIF (IN0 <> 0) AND (IN9 <> 0)····· THEN
PULSOUT 13, 850
PULSOUT 12, 650
ENDIF
LOOP
Comments
make sure the Irs aren't touching the whiskers in any way.
Software:
Here is mine:
Also, I am pretty sure that I have wired everything on the board correctly, but is it possible, even though each system works fine independently,· that I could have wired it wrong for them to operate together?
Post Edited (zack787) : 3/26/2006 5:39:26 AM GMT
In your code, it looks like you're "Blinking Left", then "Blinking Right", and only THEN trying to read the 'Left' detector, then the 'Right' detector. It doesn't surprise me that by the time your code FINALLY gets around to reading the IR-Detectors, they've gone back to idle.
Not only that, but you're not SAVING THE STATE of the IR-Detectors. Once you gone through all those "ELSEIF" clauses, any reflection signal will be long gone.
Sounds like time to get the concept of "variables". So:
MyLeft VAR BIT
MyRight VAR BIT
FREQOUT 2, 38500
MyLeft = IN0
FREQOUT 8, 38500
MyRight = IN9
'Now, you can run your decision code based on "MyLeft" and "MyRight" 'hit' codes,
which should be valid now since you'll be reading the IR-Detector immediatly after
the FREQOUT.
' {$PBASIC 2.5}
DEBUG "program running"
irdetectleft VAR Bit
irdetectright VAR Bit
pulseleft VAR Word
pulseright VAR Word
loopcount VAR Byte
pulsecount VAR Byte
FREQOUT 15, 2000, 3000
DO
FREQOUT 8, 1, 38500
irdetectleft = IN9
FREQOUT 2, 1, 38500
irdetectright = IN0
IF (IN3 = 0) AND (IN7 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN3 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (IN0 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
ENDIF
IF (irdetectleft = 0) AND (irdetectright = 0) THEN
pulsecount = 1
pulseleft = 850
pulseright = 650
ELSEIF (irdetectright = 1) THEN
pulsecount = 10
pulseleft = 650
pulseright = 650
ELSEIF (irdetectleft = 1) THEN
pulsecount = 10
pulseleft = 850
pulseright = 850
ELSE
pulsecount = 15
pulseleft = 650
pulseright = 850
ENDIF
FOR LOOPcount = 1 TO pulsecount
PULSOUT 13, pulseleft
PULSOUT 12, pulseright
PAUSE 20
NEXT
LOOP
'subrountines
Turn_Left:
FOR pulsecount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulsecount = 0 TO 20
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulsecount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
i found this works, hav fun