« flocking continued 12_16_04 | Main | Things to do (no order) »

December 17, 2004

searchingRight

Things tried troubleshooting a WHILE statement or "Seven steps to realize how stupid you can be."

Option 7 - final, for now
Lesson learned: a counter moves wicked faster than pulse count. Some stupid tax on this one.

searchingRight:
while (centerTransistor < lightThreshold) and (turnCounter < searchTimeOut)
ADCIN 3, centerTransistor
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 0
return

Option 6
wow. this is crazyness 10000 keeps it lit for maybe 2 sseconds, settled on 25000 and set a constant so can change it at the top
'-- counters
turnCounter var word
turnCounter = 0

searchingRight:
while (turnCounter < 10000)
ADCIN 3, centerTRANSISTOR
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 0
iFoundIt = 0
return

Option 5
wtf? this works. I mean I am counting to 13 (9 mississippi), not 3... is it variable overflow? if you comment out the turnCounter = 0 line it works? the turn counter is randomly reseting? raising only the while statement condition 6000 locks it out again. Is the chip reseting? am I crazy? Is it time to re-wire the board for serial...
'-- counters
turnCounter var word
turnCounter = 3001

searchingRight:
while (turnCounter > 3000)
ADCIN 3, centerTransistor
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 3000
iFoundIt = 0
return

Option 5
well aparently turnCounter is NEVER < 3000??? (releases as soon as the flashlight is off the transistor.) shhhht
searchingRight:
while (turnCounter < 3000)
ADCIN 3, centerTRANSISTOR
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 0
iFoundIt = 0
return

Option 4
Not suprisingly same as the last
searchingRight:
while (iFoundIt = 0)
ADCIN 3, centerTRANSISTOR
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
if (centerTransistor > 75) or (turnCounter > 3000) then
iFoundIt = 1
else
iFoundIt = 0
endif
wend
turnCounter = 0
iFoundIt = 0
return

Option 3
Releases as soon as the flashlighlight is off the right transistor. Commenting out last iFoundIt = 0 means the condition never finds true again so it is checking the while statement...
searchingRight:
while (iFoundIt = 0)
ADCIN 3, centerTRANSISTOR
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
if (centerTransistor < 75) AND (turnCounter < 3000) then
iFoundIt = 0
else
iFoundIt = 1
endif
wend
turnCounter = 0
iFoundIt = 0
return

Option 2
Light blinks on and off, one second interval? Never escapes
searchingRight:
while ((centerTransistor < 75) and (turnCounter < 3000))
ADCIN 3, centerTransistor
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 0
return

Option 1
works like a charm, stays turning until the flashlight shines on the middle phototransitor.
searchingRight:
while centerTransistor < 75
ADCIN 3, centerTransistor
'right wheel forward to turn left
PORTB = %00010000
wend
return

Posted by cm1002 at December 17, 2004 03:47 PM

Comments

Post a comment




Remember Me?