Based on work in the lab the group has opted to use and modify the second program to obtain the following:
______________________________________________________________________
high 0
high 1
high 2 'switchon LEDs
Main: 'switchstatement
If pin7 =0 then
'if pin7 (switch) =0 then carry out linefollowing program
Goto linefollowing
Else 'if pin7 (switch) =1 then carry out roadsymbol program
Goto roadsymbols
Endif
Goto main
linefollowing:
readadc 0, b1 'Sensor LEFT
readadc 1, b2 'Sensor MIDDLE
readadc 2, b3 'Sensor RIGHT
'keep checking the state of each of the analogue sensors before carrying on with the program to avoid unwanted loops
if b2 <= 20 then 'if b2 is above the magnetic strip then carry out the program
high 4
low 5
high 6
low 7
'time delay?
if b1 <= 20 and b2 <= 20 and b3 > 20 then
' Calibrate - if b1 and b2 are above the magnetic strip and b3 is not then turn left
high 4
low 5
low 6
high 7
pause 1000 'turn delay
goto linefollowing 'goto linefollowing and move forwards
elseif b1 > 20 and b2 <= 20 and b3 <= 20 then
' Calibrate - if b2 and b3 are above the magnetic strip and b1 is not then turn right
low 4
high 5
high 6
low 7
pause 1000 'turn delay -low to avoid missing the turn
goto linefollowing 'goto linefollowing and move forwards
endif
else 'if b2 is not on the magnetic strip motors don't run forwards and goes back to switchstatement (main)
low 4
low 5
low 6
low 7
goto main
endif
goto linefollowing
roadsymbols:
readadc 0, b1 'Sensor LEFT
readadc 1, b2 'Sensor MIDDLE
readadc 2, b3 'Sensor RIGHT
debug
'keep checking the state of each of the analogue sensors before carrying on with the program to avoid unwanted loops
if b2 <= 20 then ' middle sensor must be placed over magnetic strip line for the program to be executed or it returns to switchstatement
high 4
low 5
high 6
low 7
pause 500 'moves forward to read symbol
if b1 <= 20 and b2 <= 20 and b3 > 20 then ' Calibrate - if b1 and b2 are above the magnetic strip and b3 is not then carry out the following
high 4
low 5
high 6
low 7
pause 3000 'forward
low 4
high 5
high 6
low 7
pause 2000 ' 90deg left
high 4
low 5
high 6
low 7
pause 3000 'forward
goto stationary 'end symbolread and go back to switchstatement
elseif b1 <= 20 and b2 <= 20 and b3 <= 20 then ' Calibrate - if b1 and b2 and b3 are all above the magnetic strip then carry out the following
high 4
low 5
high 6
low 7
pause 3000 'forward
low 4
low 5
low 6
low 7
pause 2000 'stop
low 4
high 5
low 6
high 7
pause 3000 'reverse back to start
goto stationary 'end symbolread and go back to switchstatement
elseif b1 > 20 and b2 <= 20 and b3 <= 20 then ' Calibrate - if b2 and b3 are above the magnetic strip and b1 is not then carry out the following
high 4
low 5
high 6
low 7
pause 3000'forward
high 4
low 5
low 6
high 7
pause 2000 '90deg right
high 4
low 5
high 6
low 7
pause 3000 'forward
goto stationary 'end symbolread and go back to switchstatement
endif
else
goto stationary
endif
goto roadsymbols
stationary:
low 4
low 5
low 6
low 7
goto main
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment