My Code for my school Project is messed up, and I don't know why
Statz
Posts: 28
Its a long line of code, but I'll point you out to specifically where it is messing up
Here is where Its messing up
What's happenning is the Middle Sensor goes extra buggy and crazy. It isn't properly detected 1 and 0. I don't even know why.
' {$STAMP BS2} ' {$PBASIC 2.5} '{1 to 6 with a pause 20 is equivalant to 1 inch) irDetectLeft VAR Bit pulseLeft VAR Word pulseRight VAR Word loopCount VAR Byte irDetectMiddle VAR Bit hit VAR Nib FINISH CON 4 'Just a constant of if a square is made turn VAR Nib 'Will increase if a full corner turn is predicted measure VAR Byte '===debug variables=== horiz VAR Byte vert VAR Byte firstWidth VAR Byte firstLength VAR Byte secondWidth VAR Byte secondLength VAR Byte DO FREQOUT 8, 1, 43000 irDetectLeft = IN10 FREQOUT 2, 1, 42000 irDetectMiddle = IN0 DEBUG CRSRXY, 2, 3, BIN1 irDetectLeft, CRSRXY, 9, 3, BIN1 irDetectMiddle IF (irDetectLeft = 0) THEN 'If the left eye sees a wall, boe-bot goes straight pulseLeft = 850 pulseRight = 650 GOSUB Move ELSEIF (irDetectMiddle = 0) THEN 'If the front eye sees something, boe-bot will turn to the right DO FREQOUT 2, 1, 43000 irDetectMiddle = IN0 DEBUG CRSRXY, 2, 3, BIN1 irDetectLeft, CRSRXY, 9, 3, BIN1 irDetectMiddle PULSOUT 13, 790 PULSOUT 12, 750 PAUSE 20 hit = hit + 1 LOOP UNTIL (irDetectMiddle = 1) 'Repeat the loop until the left eye sees a wall and the front doesn't '===If hit is more than 4 then the boe-bot is most likely turning a long enough turn to hit 90 degrees=== ' IF hit > 4 THEN ' turn = turn+1 'Add one to the turn variable to tell how many times it turned ' measure = 0 'The measuring resets ' ENDIF ELSE 'Should turn slightly to the left if both eyes don't see anything, just until the left sees a wall pulseLeft = 780 pulseRight = 650 GOSUB Move ENDIF '=====Check if Boe-Bot made a square or rectangle==== IF (turn = FINISH) THEN EXIT ENDIF hit = 0 'reset hit LOOP END '===Statement for printing out the drawing and calculating measurement=== debug_Rectangle: SELECT turn CASE 0 vert = measure firstLength = measure DEBUG CRSRXY, 0,vert, "|" CASE 1 horiz = measure firstWidth = measure DEBUG CRSRXY, horiz,0,"-" CASE 2 vert = measure secondLength = measure DEBUG CRSRXY, horiz, vert,"|" CASE 3 horiz = measure secondWidth = measure DEBUG CRSRXY, horiz, vert,"-" CASE ELSE 'When turn = 4, the debug prints out the info DEBUG CRSRXY, horiz+2, vert+2,"Area is between : ",DEC (firstWidth*firstLength), " and ", DEC (secondWidth*secondLength) DEBUG CRSRXY, horiz+2, vert+3,"Perimeter is between ",DEC ((2*firstWidth)+(2*firstLength)), " and", DEC ((2*secondWidth)+(2*secondLength)) ENDSELECT RETURN Move: FOR loopCount = 1 TO 5 PULSOUT 13, pulseLeft PULSOUT 12, pulseRight measure = measure + 1 'Counts how many inches is traveled PAUSE 20 NEXT RETURN
Here is where Its messing up
DO FREQOUT 8, 1, 43000 irDetectLeft = IN10 FREQOUT 2, 1, 42000 irDetectMiddle = IN0 DEBUG CRSRXY, 2, 3, BIN1 irDetectLeft, CRSRXY, 9, 3, BIN1 irDetectMiddle IF (irDetectLeft = 0) THEN pulseLeft = 850 pulseRight = 650 GOSUB Move ELSEIF (irDetectMiddle = 0) THEN DO FREQOUT 2, 1, 4500 irDetectMiddle = IN0 DEBUG CRSRXY, 2, 3, BIN1 irDetectLeft, CRSRXY, 9, 3, BIN1 irDetectMiddle PULSOUT 13, 790 PULSOUT 12, 750 PAUSE 20 hit = hit + 1 LOOP UNTIL (irDetectMiddle = 1) ELSE pulseLeft = 780 pulseRight = 650 GOSUB Move ENDIF
What's happenning is the Middle Sensor goes extra buggy and crazy. It isn't properly detected 1 and 0. I don't even know why.
Comments