Hi,
I have built myself a simple car that will move around and avoid obstacles. It's based on the LMR "Start Here" robot which is where I have shamelessly copied the code from. The only difference is where I have used the SRF05 sensor and had to substitute the code to accommodate it. I used the same "debug" code that I have previously tested on it's own.
I am getting a Syntax error on the line highlighted in red. There may be others but until I have this one sorted I cannot move on to find others. The board is a 28x1 project board.
Thankyou in advance,
Paul
I have built myself a simple car that will move around and avoid obstacles. It's based on the LMR "Start Here" robot which is where I have shamelessly copied the code from. The only difference is where I have used the SRF05 sensor and had to substitute the code to accommodate it. I used the same "debug" code that I have previously tested on it's own.
I am getting a Syntax error on the line highlighted in red. There may be others but until I have this one sorted I cannot move on to find others. The board is a 28x1 project board.
Thankyou in advance,
Paul
Code:
symbol dangerlevel=20 'how far away should things be before we react?
symbol turn=300 'this sets how much should be turned
symbol servo_turn=700 'this sets for how long time we should wait for the servo to turn
symbol trig= 3 'define output pin for trigger pulse
symbol echo= 6 'define input pin for echo pulse
symbol range= w1 '16 bit word variable for range
main: ' the main loop
pulsout trig,2 'produce 20uS trigger pulse (must be minimum of 10Us)
pulsin echo,1,range 'measures the range in 10uS steps
pause 10 'recahrge period after ranging completes
'now convert range to cm (divide by 5.8) or inches (divide by 14.8)
'as picaxe cannot use 5.8, multiply by 10 then divide by 58 instead
let range = range*10/58 ' multiply by 10 then divide by 58
debug range 'display range via debug command
if range < dangerlevel then
gosub nodanger 'if nothing ahead, drive forward
else
gosub whichway 'if obstacle ahead then decide which way is better
end if
goto main 'end of main loop, all others are sub-routines
nodanger: 'drive forward
high 4 : low 5 : high 6 : low 7
return
whichway:
gosub totalhalt 'first stop!
'look one way
gosub lturn 'look to one side
pause servo_turn ' wait for the servo to be finished turning
pulsout trig,2 'produce 20uS trigger pulse (must be minimum of 10Us)
pulsin echo,1,range 'measures the range in 10uS steps
pause 10 'recahrge period after ranging completes
'now convert range to cm (divide by 5.8) or inches (divide by 14.8)
'as picaxe cannot use 5.8, multiply by 10 then divide by 58 instead
let range = range*10/58 ' multiply by 10 then divide by 58
[COLOR="Red"]debug range, b1 'display range via debug command[/COLOR]
gosub totalhalt
'look the other way
gosub rturn 'to another side
pause servo_turn
pulsout trig,2 'produce 20uS trigger pulse (must be minimum of 10Us)
pulsin echo,1,range 'measures the range in 10uS steps
pause 10 'recahrge period after ranging completes
'now convert range to cm (divide by 5.8) or inches (divide by 14.8)
'as picaxe cannot use 5.8, multiply by 10 then divide by 58 instead
let range = range*10/58 ' multiply by 10 then divide by 58
debug range, b2 'display range via debug command
gosub totalhalt
'decide which is the better way
if b1<b2 then
gosub body_lturn
else
gosub body_rturn
end if
return
body_lturn:
high 4 : low 5 : high 7 : low 6
pause turn : gosub totalhalt
return
body_rturn:
high 5 : low 4 : high 6 : low 7
pause turn : gosub totalhalt
return
rutrn:
servo 0, 200
return
lturn:
servo 0, 100
return
totalhalt:
low 4 : low 5 : low 6 : low 7
servo 0, 150
wait 2
return