Syntax errors using Debug command.

pjl83

Member
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

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
 

KeithRB

Senior Member
Since the variable is only a dummy - you get all the variables, anyway - maybe it does not like having two there, try using debug range.
 

pjl83

Member
I'm not sure I understand what you mean :confused:

The servo move the "eyes" they need to turn left and read the distance (b1) , then turn right and read the distance (b2) and then compare the 2 to decide which way to move. If I only use debug range then how do I get the programme to compare the 2 seperate readings :confused:
 

KeithRB

Senior Member
debug does this:
"Function:
Display variable information in the debug window when the debug command is
processed. Byte information is shown in decimal, binary, hex and ASCII notation.
Word information is shown in decimal and hex notation.
Information:
The debug command uploads the current variable values for *all* the variables
via the download cable to the computer screen. This enables the computer screen
to display all the variable values in the microcontroller for debugging purposes.
Note that the debug command uploads a large amount of data and so
significantly slows down any program loop."

The debug command simply displays the current state of all the variables on the screen. It does no comparison of any data.
 

pjl83

Member
I see, thankyou. I'll have a play and try to use readadc.

I was probably just being lazy trying to use the same debug code as I had before.

Thankyou
 

pjl83

Member
This is the code that I copied. Although this robot uses a different type of sensor.

Code:
Symbol dangerlevel = 70 ' how far away should thing 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 (depending on it´s speed) before we measure distance

main: ' the main loop
[COLOR="Red"]readadc 0, b1 ' read how much distance ahead[/COLOR]
if b1 < 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 ' this ends the loop, the rest are only sub-routines


nodanger:' this should be your combination to make the robot drive forward, these you most likely need to adjust to fit the way you have wired your robots motors
high 5 : high 6 : low 4 : 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
[COLOR="red"]readadc 0, b1[/COLOR]
gosub totalhalt


'Look the other way:
gosub rturn ' look to another side
pause servo_turn ' wait for the servo to be finished turning
[COLOR="red"]readadc 0, b2[/COLOR]
gosub totalhalt

' Decide which is the better way:
[COLOR="red"]if b1<b2 then[/COLOR]
gosub body_lturn
else
gosub body_rturn
end if
return

body_lturn:
high 6 : low 5 : low 7 : high 4 ' this should be your combination that turns the robot one way
pause turn : gosub totalhalt
return

body_rturn:
high 5 : low 6 : low 4 : high 7 ' this should be your combination that turns the robot the other way
pause turn : gosub totalhalt
return

rturn:
servo 0, 100 ' look to one side
return

lturn:
servo 0, 200 ' look to the other side
return

totalhalt:
low 4 : low 5 : low 6 : low 7 ' low on all 4 halts the robot!
Servo 0,150 ' face forward
wait 1 ' freeze all for one second
return
I've highlighted the b1's in red. I need then head to turn left, and remember the value. Then turn right and remember the value. This is how it decides which way to turn before moving again.

I think I need to move from pin 6 to pin 5 if I am to use the readadc command. here's my latest attempt.

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 (depending on it's speed) before we measure distance
symbol trig= 3 'define output pin for trigger pulse
symbol echo= 5 '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
	[COLOR="red"]readadc range 'display range via debug command[/COLOR]
	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
	readadc 5, b1 'display range via debug command
	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
	readadc 5, 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
	
rturn:
	servo 0, 200
	return
	
lturn:
	servo 0, 100
	return
	
totalhalt:
	low 4 : low 5 : low 6 : low 7
	servo 0, 150
	wait 2
	return
I now have a syntax on the readadc range line. (in red)

Thanks
 

eclectic

Moderator
Suggestion 1.
Simplify.
You don't need readadc with an SRF05.

Take a reading. "Remember it".

Say w2 = range

Take another reading. "Remember it".
Say W3 = range.

If w2 > w3
or
if W3 > w2

then start the checking again.

e
 

pjl83

Member
would these replace the readadc lines? there is a symbol at the top that calls w1 "range" is this still correct?
 

eclectic

Moderator
would these replace the readadc lines? there is a symbol at the top that calls w1 "range" is this still correct?
Keep it simple.
Start again.
Blank paper / program.

Read the range.
Remember it. (W2)

Read another range.
Call it w3
and so on.

Or, I'm walking down this path.
Now, I'm a metre from the edge.
Then, I'm a centimetre from the edge.
Which way do I go?
 

pjl83

Member
In the main section I have

fire the pulse out,
read the echo and call it range,
if range is less than dangerlevel then both motors forward,
else decide which way
whichway:
look left and remeber "range = w2"
look right and remember "range = w3"

if left is greater then turn left
if not then turn right.

does this sound ok?
 

pjl83

Member
I got fed up in the end and went to bed. :(

I think I need to take everything a step at a time. I'll ignore the the code that I've copied and start from scratch as you suggested.
 

pjl83

Member
A Big Thanks!

Thanks goes to KeithRB and eclectic for their kind help.

Thanks to the advice above and for making it obvious that I should do more reading I have managed to get my first robot working.

It's a simple car that drives until it sees something in it's path, then looks both ways before deciding which way to turn. If the range still isn't long enough ahead then it repeats until it is, otherwise it carries on ahead.

Code:
symbol dangerlevel=50 'how far away should things be before we react?
symbol turn=1000 'this sets how much should be turned
symbol servo_turn= 1000 '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


servo 0, 150
wait 1

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
	debug range
	w2 = range
	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
	w3 = range
	gosub totalhalt

'decide which is the better way
	if w2<w3 then
	gosub body_lturn
	else
	gosub body_rturn
	end if 
	return

rturn:
	servo 0, 200
	pause servo_turn
	return

lturn:
	servo 0, 100
	pause servo_turn
	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

totalhalt:
	low 4 : low 5 : low 6 : low 7
	servo 0, 150
	pause servo_turn
	return
I turned most of the code into comments and tested a small step at a time. I made sure that I understood each bit too rather than just copying it and checking that it works. I just need to adjust times to make the turns and the servo movements quicker and then I can start adding some led's and maybe even some sound effects before building a final body to house everything.

Thanks again,
Paul ;)
 
Top