Hi All,
I am currently working on code for my latest project being a sumobot style line detector. its actually my first wave before implementing a full scale sumobot. I have one issue currently that is bugging me and that has to do with the speed at which i am detecting and responding to the presence of a line. I have included my code below for general review and hints as to what I can change to make the line detection almost immediate.
Here is my code
setfreq m8
symbol LeftEye = 2
symbol RightEye = 1
symbol LeftWheelA = 7
symbol LeftWheelB = 6
symbol RightWheelA = 5
symbol RightWheelB = 4
; initialize default forward movement
low LeftWheelA
high LeftWheelB
low RightWheelA
high RightWheelB
pause 5000 ;5 second wait before starting up
main:
readadc LeftEye,b1
readadc RightEye,b2
sertxd("L (",#b1,") R (",#b2,")",13,10)
pause 500
if b1<50 OR b2 < 50 then ; determine if left eye or right eye sees a black line
gosub StopMoving
wait 1
gosub gobackward
wait 3
gosub StopMoving
wait 1
if b1 > b2 then
gosub turnleft
else
gosub turnright
end if
wait 2
gosub StopMoving
wait 1
gosub goforward
end if
goto main
StopMoving:
low LeftWheelA
low LeftWheelB
low RightWheelA
low RightWheelB
return
goforward:
low LeftWheelA
high LeftWheelB
low RightWheelA
high RightWheelB
return
gobackward:
high LeftWheelA
low LeftWheelB
high RightWheelA
low RightWheelB
return
turnleft:
high LeftWheelA
low LeftWheelB
low RightWheelA
high RightWheelB
return
turnright:
low LeftWheelA
high LeftWheelB
high RightWheelA
low RightWheelB
return