I cant get the led's to flash on my boe-bot
walice_drel
Posts: 81
I set up my boe-bot just like it was pictured in the manual for roaming, everything works correctly but the led's wont flash. Here is the code I used.
'
[noparse][[/noparse] Title ]
' Robotics with the Boe-Bot - RoamingWithIr.bs2
' Adapt RoamingWithWhiskers.bs2 for use with IR pairs.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
'
[noparse][[/noparse] Variables ]
counter VAR Nib
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseCount VAR Byte
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
'
[noparse][[/noparse] Main Routine ]
DO
FREQOUT 8, 1, 38500 ' Store IR detection values in
irDetectLeft = IN9 ' bit variables.
FREQOUT 2, 1, 38500
irDetectRight = IN0
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up ' Both IR pairs detect obstacle
GOSUB Turn_Left ' Back up & U-turn (left twice)
GOSUB Turn_Left
ELSEIF (irDetectLeft = 0) THEN ' Left IR pair detects
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN ' Right IR pair detects
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' Both IR pairs 1, no detects
GOSUB Forward_Pulse ' Apply a forward pulse
ENDIF ' and check again
LOOP
'
[noparse][[/noparse] Subroutines ]
IF (IN0 = 0) OR (IN9 = 0) THEN
FOR counter = 1 TO 5
HIGH 1
HIGH 10
FREQOUT 6, 200, 4000
LOW 1
LOW 10
PAUSE 20
NEXT
ENDIF
RETURN
Forward_Pulse: ' Send a single forward pulse.
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
RETURN
Turn_Left: ' Left turn, about 90-degrees.
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up: ' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Can someone please tell me what I am doing wrong.
'
[noparse][[/noparse] Title ]
' Robotics with the Boe-Bot - RoamingWithIr.bs2
' Adapt RoamingWithWhiskers.bs2 for use with IR pairs.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
'
[noparse][[/noparse] Variables ]
counter VAR Nib
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseCount VAR Byte
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
'
[noparse][[/noparse] Main Routine ]
DO
FREQOUT 8, 1, 38500 ' Store IR detection values in
irDetectLeft = IN9 ' bit variables.
FREQOUT 2, 1, 38500
irDetectRight = IN0
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up ' Both IR pairs detect obstacle
GOSUB Turn_Left ' Back up & U-turn (left twice)
GOSUB Turn_Left
ELSEIF (irDetectLeft = 0) THEN ' Left IR pair detects
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN ' Right IR pair detects
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' Both IR pairs 1, no detects
GOSUB Forward_Pulse ' Apply a forward pulse
ENDIF ' and check again
LOOP
'
[noparse][[/noparse] Subroutines ]
IF (IN0 = 0) OR (IN9 = 0) THEN
FOR counter = 1 TO 5
HIGH 1
HIGH 10
FREQOUT 6, 200, 4000
LOW 1
LOW 10
PAUSE 20
NEXT
ENDIF
RETURN
Forward_Pulse: ' Send a single forward pulse.
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
RETURN
Turn_Left: ' Left turn, about 90-degrees.
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up: ' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Can someone please tell me what I am doing wrong.
Comments
It's been a while since I did the BoE-bot experiments, but I seem to remember a set-up that had normal LEDs that indicated whether a high or low signal was being received from the IR detectors. If this is what you're talking about, then check that the LEDs are in the right way, if they're wired in backwards they don't light up.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
'
[noparse][[/noparse] Title ]
' Robotics with the Boe-Bot - RoamingWithIr.bs2
' Adapt RoamingWithWhiskers.bs2 for use with IR pairs.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
'
[noparse][[/noparse] Variables ]
counter VAR Nib
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseCount VAR Byte
'
[noparse][[/noparse] Initialization ]
DEBUG "Testing piezospeaker..."
FREQOUT 4, 2000, 3000
DEBUG CLS,
"IR DETECTORS", CR,
"Left Right", CR,
"
"
'
[noparse][[/noparse] Main Routine ]
DO
FREQOUT 8, 1, 38500 ' Store IR detection values in
irDetectLeft = IN9 ' bit variables.
FREQOUT 2, 1, 38500
irDetectRight = IN0
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up ' Both IR pairs detect obstacle
GOSUB Turn_Left ' Back up & U-turn (left twice)
GOSUB Turn_Left
ELSEIF (irDetectLeft = 0) THEN ' Left IR pair detects
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN ' Right IR pair detects
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' Both IR pairs 1, no detects
GOSUB Forward_Pulse ' Apply a forward pulse
ENDIF ' and check again
LOOP
'
[noparse][[/noparse] Subroutines ]
IF (IN0 = 0) OR (IN9 = 0) THEN
FOR counter = 1 TO 5
HIGH 1
HIGH 10
FREQOUT 6, 200, 4000
LOW 1
LOW 10
PAUSE 20
NEXT
ENDIF
RETURN
Forward_Pulse: ' Send a single forward pulse.
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
RETURN
Turn_Left: ' Left turn, about 90-degrees.
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up: ' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
and I wired it the same as the pic in the manual on page 243.
[noparse][[/noparse] Subroutines ]
line, see if you can figure it out on your own. If you don't, we'll tell you, but go ahead and try.
Take it easy, do all the projects in the book one by one, and I guarantee by the time you get to page 243 you'll understand what you did wrong.
IF (IN0 = 0) OR (IN9 = 0) THEN
has a return statement but is missing a label
Jeff T.
***************************
-main program
DO
GOSUB SayHello
GOSUB SayBye
LOOP
-subroutines definitions
SayHello:
Type hello on the screen
SayBye:
Type bye on the screen
ShakeHands:
Shake your hand and smack you on the butt.
***************************
The the code is processed, it goes line by line. The first line is SayHello. The GOSUB command is like a GOTO that makes the compiler 'jump' to where SayHello is defined, run that code, and then it jumps back to where it left off. Next would be Saybye, so again, the program 'jumps' down to where SayBye is defined, types bye on the screen, then it jumps back up to the next line, LOOP, which repeates the whole thing.
Now, you notice the third routine there ShakeHands ? It's never called in the DO LOOP, so it's never processed.
So, the problem with your code: 1) you have code outside of the DO LOOP part so it's never processed, and 2) the code isn't part of a subroutine. You can either make it a subroutine and call it with GOSUB, or incorporate it in the main code as is.
Hope that helps.
EDIT: yes, just like unsoundcode said, it's missing a label. You know why? Because you just copied and pasted code from the book and slapped it together. That's not the way to learn, my friend, but it's the way to get frustrated very easily.
Post Edited (OSOK) : 8/9/2007 6:01:04 AM GMT