Potential causes of Boe-Bot reset (other than brownout)
A program I'm running on my BASIC Stamp seems to be causing my Boe-Bot to repeatedly reset. I don't think it's brownout because it doesn't have this problem with any other program, and I replaced the batteries with fresh ones (twice). But I mostly copied this code out of the sourcebook I'm using, Robotics with the Boe-Bot by Andy Lindsay, and I don't see my error. Would someone be willing to take a look at my code and let me know if they see any errors?
I am fairly new to the robotics and CS communities, but it seems to be a done thing to post code for people to look at, so here it is:
I am fairly new to the robotics and CS communities, but it seems to be a done thing to post code for people to look at, so here it is:
' {$STAMP BS2} ' {$PBASIC 2.5} ' EscapingCorners.bs2 ' Boe-Bot navigates out of corners by detecting whisker presses DEBUG "Program running!" pulseCount VAR Byte ' FOR...NEXT loop counter. counter VAR Nib ' Counts alternate contacts. old7 VAR Bit ' Stores previous IN7. old5 VAR Bit ' Stores previous IN5. FREQOUT 4, 2000, 3000 counter = 1 ' Start alternate corner count. old7 = 0 old5 = 1 FOR pulseCount = 0 TO 100 GOSUB Forward_Pulse NEXT RETURN DO IF (IN7 <> IN5) THEN ' 1 (but not other) is pressed. IF (old7 <> IN7) AND (old5 <> IN5) THEN ' Different from previous. counter = counter + 1 old7 = IN7 ' Updating old7 - record this whisker press for future comparison. old5 = IN5 IF (counter > 4) THEN ' If alternate whisker count = 4 (since counter = 1 + alternate whisker count), counter = 1 ' reset whisker count GOSUB Back_Up ' and execute a U-turn. GOSUB Turn_Left GOSUB Turn_LEFT ENDIF ' Of (counter > 4). ELSE ' ELSE (old7 = IN7) or (old5 = IN5) counter = 1 ' Therefore not alternate. Reset counter. ENDIF ' Of (IN7 <> IN5). IF (IN5 = 0) AND (IN7 = 0) THEN ' Both whiskers detect obstacle GOSUB Back_UP ' Back up & U-turn (left twice) GOSUB Turn_Left GOSUB Turn_Left ELSEIF (IN5 = 0) THEN ' Only left whisker contacts GOSUB Back_Up GOSUB Turn_Right ELSEIF (IN7 = 0) THEN ' Only right whisker contacts GOSUB Back_Up GOSUB Turn_Left ELSE ' No problems (both whiskers 1) GOSUB Forward_Pulse ' Full steam ahead! ENDIF ENDIF LOOP ' Now we check again. Forward_Pulse: ' Send 1 forward pulse PULSOUT 13, 850 PULSOUT 12, 660 ' Right wheel is slow. PAUSE 20 RETURN Turn_Left: ' About a 90deg left turn FOR pulseCount = 0 TO 20 PULSOUT 13, 650 PULSOUT 12, 675 PAUSE 20 NEXT RETURN Turn_Right: ' About 90deg right FOR pulseCount = 0 TO 20 PULSOUT 13, 850 PULSOUT 12, 810 ' When turning, Boe-Bot swings faster right than left - how is this possible if right wheel is slow? May have misunderstood. PAUSE 20 NEXT RETURN Back_Up: FOR pulseCount = 0 TO 40 PULSOUT 13, 650 PULSOUT 12, 840 PAUSE 20 NEXT RETURN
Comments
This is written like a subroutine with a RETURN, but it's part of the main program. The RETURN without a GOSUB will cause the system to reset.
-Phil