Panning SRF005 without using the 'SERVO" commands

Bill.b

Senior Member
Hi I found that some commands effected the servo command, in my case it was the IR commands. The following
is a portion of code for a free roaming bot to control the panning of a SFR005 ultrasonic scanner.

Code:
Code:
'this is a part of a free roaming bot program (bot120  picaxe 20x2).  the following section controls the pan of 
'of a SRF005 ultrasonic scanner.
'the servo uses pulse out command in place of the usual servo commands.  this is
'because this bot also used IR commands for control. when the servo commands where used, an IR command would
'cause the servo move to the extreem left.  the pulse out command rectified this problem.

 setfreq = m8
Symbol trig 	      = C.4	'front range sensor ADC input
Symbol SERVO1           = b.0
Symbol leftPath           = w13             'Obstruction value on left side
Symbol rightPath          = w14             'Obstruction value on right side
Symbol range              = w12	'output from SRF005

Symbol SERVOLeft 	      = 150
Symbol SERVORight      = 350
Symbol SERVOCent       = 260






DistanceMessure:

	pulsout trig,2        		' produces about 20uS pulse (must be minimum of 10uS)
   	pulsin trig,1,range  		' measures the range in 10uS steps
    	pause 10               		' SRF005 mandatory 10mS recharge period after ranging completes
    	let range = range * 10 /58/2 	' multiply by 10 then divide by 58 then by 2 (8meg) 
   	If range > 20 then                           'all clear
		return
	endif
	let pinsb =%00001010    		'stop bot
	pause 200
	let pinsb =%10100000                      'Reverse bot
            pause 1000
	let pinsb =%00001010                      'stop bot
	for b50 = 1 to 10				'pulse output to servo 1
		pulsout SERVO1,SERVOLeft	             ' Turn head to look left
		pause 20
	next  b50             			 ' Turn head to look left
             Pause 200                          	              ' Wait for servo to move
            pulsout trig,2         			 ' produces about 20uS pulse (must be minimum of 10uS)
    	pulsin trig,1,leftPath   		             ' measures the range in 10uS steps
    	pause 10               			' SRF04 mandatory 10mS recharge period after ranging completes
    	let leftPath = leftPath * 10 /58/2 	             ' multiply by 10 then divide by 62 
    	for b50 = 1 to 20				'pulse output to servo 1
		pulsout SERVO1,SERVORight		' Turn head to look right
		pause 20
	next  b50 
        Pause 200             		             ' Wait for servo to move
        pulsout trig,2         		             ' produces about 20uS pulse (must be minimum of 10uS)
    	pulsin trig,1,rightPath    		' measures the range in 10uS steps
    	pause 10               			' SRF005 mandatory 10mS recharge period after ranging completes
    	let rightPath = rightPath * 10 /58/2          ' multiply by 10 then divide by 62 
	for b50 = 1 to 20				'pulse output to servo 1
		pulsout SERVO1,SERVOCent	         ' Turn head to look forward
		pause 20
	next b50
      If leftPath < rightPath Then 
        	gosub turnleft               ' Turn in the direction that has more room
      Else
          	gosub turnright
      Endif 
       
	return
Regards Bill
 
Last edited:
Top