Unclear code

Andrei IRL

Senior Member
Hi. I have finally finished my Autonomous Car.
I have used the code from a similar project and just adopted it for mine.
Im just a bit unclear on two lines.
1st. - Why are we using
Code:
high motorL,motorR
after
Code:
if distleft < blocked and distright < blocked then
I understand that we are using low command before hand to stop servos/car to get more accurate reading of the distance but not sure why we are setting servo pins HIGH after distance is compared?
Thanks very much in advance.
Code:
'picaxe 08m
disablebod
setfreq m4
		`Specifiyng Inputs and Outputs
symbol motorL=4		'servo output pins 		- pin 4
symbol motorR=2		'servo output pins 		- pin 2
symbol motorN=0		'servo output pins 		- pin 0
symbol sonic=1		'output pin for ultrasonic    - pin 1

		`Specifiyng Variables
symbol distance=w0	'result from ultrasonic
symbol distleft=w1	'distance when looking left
symbol distright=w2	'distance when looking righ

		`Specifiyng Constants
symbol forwardL=185	`Right servo position signal for forward
symbol forwardR=75	`Left servo position signal for forward
symbol reverseL=75	`Right servo position signal for reverse
symbol reverseR=185	`Left servo position signal for reverse
symbol spinaround=1000	`Delay 1 sec to spin 180 degrees
symbol turn=100		`Delay to turn left or right
symbol blocked=40		'minimum safe distance 40cm

		`Servo initiating
servo motorN,130
pause 1000
servopos motorN,200
pause 1000
servopos motorN,170
pause 1000	
servo motorL,forwardL	'set pins as servo outputs - forwards
servo motorR,forwardR		'set pins as servo outputs - forwards
pause 500
 


Main:
	gosub ping	    'check to see if anything is infront of the robot
	
	if distance>blocked then		' if nothing ahead
		gosub ahead				`then move forward
		goto main
	end if
	
	gosub jump		`if something is ahead go to jump Sub-routine
	goto main
end


jump:
	low motorL,motorR		`stop the car
	gosub look			`go to look sub-routine 

	if distleft < blocked and distright < blocked then
		high motorL,motorR
		gosub backwards
		gosub spin180		'path blocked - can't turn
		goto main
	end if
    
	if distleft>distright then				
		high motorL,motorR
		gosub turnleft
		goto main
	end if
	high motorL,motorR
	gosub turnright
	goto main


look:
	servopos motorN,200		' turn the head to the left
	pause 500
	gosub ping
	let distleft=distance
    
	servopos motorN,130	' turn the head to the right
	pause 600
	gosub ping
	let distright=distance
    
	servopos motorN,170		' return the head to centre
	pause 500
	return
    
ping:
	ultra sonic, distance 		
	pause 500
	return
    
ahead:
	servo motorL,forwardL
	servo motorR,forwardR
	return


backwards:
	servopos motorL,reverseL
	servopos motorR,reverseR
	pause 2000
	return

turnright:
	servo motorL,forwardL
	servo motorR,reverseR
	pause turn
	return
    
turnleft:
	servo motorL,reverseL
	servo motorR,forwardR
	pause turn
	return
    
spin180:
	servo motorL,75
	servo motorR,75
	pause spinaround
	return
 

inglewoodpete

Senior Member
Can you provide a link to the source of the code? Some members may be able to help but more information on the background of the code will be needed.
 

1968neil

Senior Member
it looks like
if distleft and distright is < (less than) than blocked (ie: no obstruction) then move forward ?

Just a thought
Regards
Neil
 
Top