the duck

jinx

Senior Member
hi

thanks eclectic,
not got a schematic yet i'll work on it. my code is always evolving here's what i got so far
Code:
; *******************************
; ***** Sample Header File  *****
; *******************************
;    Filename:      Qduck		
;    Date:            10/6/12		
;    File Version:  001.1	
;    Written by:    jinx	
;    Function:        autonomous roving bot		
;    Last Revision:
;    Target PICAXE:20x2	
; ******************************* 




#picaxe 20x2
#no_data
#no_table


'**********floor sens**************************
symbol olsens = 7 
symbol lsens  = 8
symbol rsens  = 3
symbol orsens = 9 

symbol rgtvalue = b9
symbol lftvalue = b8
symbol OLvalue  = b7
symbol ORvalue  = b6

symbol oldrtval = b14
symbol olsetval = b18
symbol lsetval  = b15
symbol rsetval  = b16
symbol orsetval = b17


'****** srf005 ******************************
symbol ping  = b.1           ' Define output pin for Trigger pulse
symbol echo  = c.0            ' Define input pin for Echo pulse
symbol range = w10 

symbol caution = 20 
 '***** servo control ***********************
  '  pan servo
symbol pan = b.2
symbol rgt = 210
symbol cen = 150
symbol lft = 80

 '***** tilt servo **************************
 '*******************************************
symbol tilt  = b.0
symbol T_up  = 110
symbol T_dwn = 190
symbol Tcen  = 155


'********************************************
'          drive setting                                    
'********************************************

symbol l_back_slow = 153
symbol l_back_fast = 200
symbol l_off = 148
symbol l_forward_slow = 141
symbol l_forward_fast = 128

symbol r_back_fast = 95
symbol r_back_slow = 130
symbol r_off = 141
symbol r_forward_slow = 155
symbol r_forward_fast = 220

symbol r = b.4
symbol l = b.3


symbol delay = 1000
symbol delay1 = 500
symbol led = c.5



symbol counter = b1




init:servo pan,cen
     servo tilt,tcen
     servo r, r_off
     servo l, l_off
     pause 30
       gosub setsens
  pause 1000
    
 main:
        high led                                  ' floor led
          do
         for b1 =lft to rgt step 2
         servopos pan,b1
          readadc rsens,rgtvalue
          readadc lsens,lftvalue
      if rgtvalue < rsetval then gosub flturn
       if lftvalue < lsetval then gosub  frturn
          pause 10
          pulsout ping,2                 ' produce 20uS trigger pulse (must be minimum of 10uS)
          pulsin echo,1,range                ' measures the range in 10uS steps
         pause 10                           ' recharge period after ranging completes
     let range = range * 10 / 58 
       	if range > caution then
	gosub allclear                        'if nothing ahead, drive forward
	else
	gosub direction                        'if obstacle ahead then decide which way is better
	end if
      
             
                    ' now convert range to cm (divide by 5.8) or inches (divide by 14.8) 
       
   
        next b1
        
       for b1 =rgt to lft step -2
       servopos pan,b1
       readadc rsens,rgtvalue
       readadc lsens,lftvalue
      if rgtvalue < rsetval then gosub flturn
       if lftvalue < lsetval then gosub frturn
       pause 10
       pulsout ping,2                     ' produce 20uS trigger pulse (must be minimum of 10uS)
       pulsin echo,1,range                  ' measures the range in 10uS steps
       pause 10                            ' recharge period after ranging completes
       let range = range * 10 / 58          ' now convert range to cm (divide by 5.8) or inches (divide by 14.8) 
       if range < 10 then gosub rgt90 
        	if range > caution then
	gosub allclear                        'if nothing ahead, drive forward
	else
	gosub direction                        'if obstacle ahead then decide which way is better
	end if  
	next b1 
    
     
  loop



allclear: 'drive forward
       servopos r, r_forward_slow
       servopos l, l_forward_slow
          
	return
	
	
	
	
	

direction:

	gosub allstop  
	

	gosub llook                  'look to lft side
	pause 30 
	pulsout ping,2               'produce 20uS trigger pulse (must be minimum of 10Us)
	pulsin echo,1,range          'measures the range in 10uS steps
	pause 20                     'recahrge period after ranging completes
	let range = range*10/58         ' multiply by 10 then divide by 58
	w2 = range

	gosub allstop
		servopos pan,cen

	gosub rlook                   'look rgt side
	pause  30 
	pulsout ping,2              'produce 20uS trigger pulse (must be minimum of 10Us)
	pulsin echo,1,range         'measures the range in 10uS steps
	pause 20                    'recahrge period after ranging completes
	let range = range*10/58 ' multiply by 10 then divide by 58
	w3 = range

	gosub allstop
     	servopos pan,cen
     	if w2<caution and w3<caution then
	gosub bck
	else
	gosub decide
	end if
	return
		
	
decide:
	if w2<w3 then
	gosub rturn
	else
	gosub lturn
	end if 
	return
	
 Lturn:
         pause 30
         servopos l, l_off
         servopos r, r_off
         pause 30
         gosub bck
         pause 30
         gosub lft90
         
         return
         
   
  Rturn:
         pause 30
         servopos l, l_off
         servopos r, r_off
         pause 30
         gosub bck
         pause 30
         gosub rgt90
         
         return
       	
frturn:
  pause 30
         servopos l, l_off
         servopos r, r_off
         pause 30
         gosub bck
         pause 30
         gosub lft180
         
         return
   
    lft90:
         servopos r, r_off
         servopos l, l_off
         pause 30
         servopos l,l_back_slow
         servopos r,r_forward_slow
             
           pause delay
      
         return
    
   lft180:
          servopos r, r_off
          servopos l, l_off
          pause 30
           gosub bck
         pause 30
          servopos l,l_back_slow
          servopos r,r_forward_slow
          pause 4900
         
          return

         
  flturn:
         pause 30
         servopos l, l_off
         servopos r, r_off
         pause 30
         gosub bck
         pause 30
         gosub rgt180
         return
         
         
        
    rgt90:
       servopos r, r_off
       servopos l, l_off
       pause 30
       servopos l,l_forward_slow
       servopos r,r_back_slow
          
       pause delay
        
        return   
                         
   rgt180: 
         servopos r, r_off
         servopos l, l_off
         pause 30
         servopos l,l_forward_slow
         servopos r,r_back_slow
         pause 4900
         return    
   	

llook:
      servopos pan,lft
      pause 300
      return	
	
	
rlook:servopos pan,rgt
      pause 300	
      return
      
 bck:
        servopos r, r_back_slow
       servopos l, l_back_slow 
       pause 1000
       return
      
      
      
      
	
allstop:
     	   servopos r, r_off
         servopos l, l_off
         pause 30
     
	 return
	
	
	
	
	
	
	
	
	
	
	
	
	 
 setsens:

          sertxd("sensing floor",13,10)
          high led
     for counter = 1 to 3
   
       pause 500
        readadc lsens,lsetval
        readadc olsens,olsetval
        readadc rsens,rsetval
        readadc olsens,olsetval
     
          next counter
          rsetval = rsetval - 10
          lsetval = lsetval - 10
          olsetval = olsetval - 10
          orsetval = orsetval - 10
          
         pause 100
           
          return
the floor sensor routine needs a auto reset routine putting in hav'nt worked that bit out yet. I had such a grin on my face for day when i got that working.
 

erco

Senior Member
Jinx: the duck is FABULOUS! Great motion and your pan & tilt really adds some lively animation. Love it. A++++!
 

jinx

Senior Member
hello,
a black billed duck: update of a DUCK
The duck has evolved to use a PICAXE 28x2 " needed the extra IO pins to add an ERF module, light following also the extra ldr going to be used to set an auto calibration routine when i got the pennies " I've also got my head around setting the Interrupts and using the internal pullup on b.0,b.1,.b.2 for the bumper switchs.
The DUCK also got abit of colour I used acrylic based paint " Acrylic on plastic you say " the Acrylic will dry and stick to plastic but easily scratched off thats why i painted the underside of the plastic. Using the Acrylic this way means that it can almost be peelled of if i wont to change the colour scheme in a month or so. The ERF mount to-be on the other hand was painted then sandwiched in-between the plastic before cutting " it ain't never coming off " . Just waitng too see if the pigments fades.
Now i get to play around with programming

jinx
http://www.youtube.com/watch?v=MmariR8HFnQ&feature=plcp
duck piant 2 001.JPG
 

Attachments

Last edited:

jinx

Senior Member
hi,
more of an experiment than an update, playing with the idea ir remote to the duck in the past i used a serial 08M to the 28x2 worked well, this time I added the ir receiver the receiver directly to the 28x2 the duck went into a "spin". for half a day i was vexed so being I then placed the ir into a subroutine i turned the servo's off received the ir cmnd as thats where the timing conflicts were between ir and servo's "that's what am guessing at" so received the cmnd reanabled the servo's as the code returned the main programme and only looked for the ir cmnd at the end of the main code,
it's not a good solution but it works,
Code:
#picaxe 28x2

' Converted by X2 Conversion Wizard Version 2.0.5 (2010r4.1)

let dirsB = %11111111
let adcsetup = 0

; *******************************
; ***** Sample Header File  *****
; *******************************
;    Filename: Qduck slot3
;    Date: 	10/6/12
;    File Version: 001.1
;    Written by: 	jinx
;    Function:  autonomous roving bot
;    Last Revision:
;    Target PICAXE: 20x2
; *******************************











 '***** servo control ***********************
  '  pan servo
symbol pan = b.4
symbol rgt = 210
symbol cen = 150
symbol lft = 80

 '***** tilt servo **************************
 '*******************************************
symbol tilt  = b.5
symbol T_up  = 120
symbol T_dwn = 190
symbol Tcen  = 155


'********************************************
'          drive setting
'********************************************

symbol l_back_slow = 153
symbol l_back_fast = 200
symbol l_off = 148
symbol l_forward_slow = 141
symbol l_forward_fast = 128

symbol r_back_fast = 95
symbol r_back_slow = 130
symbol r_off = 141
symbol r_forward_slow = 155
symbol r_forward_fast = 220

symbol r = b.6
symbol l = b.7


symbol delay = 1000
symbol delay1 = 500
symbol led = c.1




symbol infra = b1





 main: do
   servo r, r_off
     servo l, l_off
     pause 20
 
 select case infra
	case 1
		gosub allstop
  	case 2
  		gosub lft90
	case 3
		gosub bck
	case 4
		gosub allstop
	case 5
		gosub fward
	case 6
	 	gosub rgt90

	end select
gosub getdata
	 loop





getdata:
      low b.6
      low b.7
      irin C.4, infra    ;wait for new signal
      pause 10
     
       return
      


fward:  sertxd(" forward   ",13,10)
       servopos r, r_forward_slow
       servopos l, l_forward_slow
       pause 1000

	return









    lft90:
         sertxd(" lft90  ",13,10)
         servopos r, r_off
         servopos l, l_off
         pause 30
         servopos l,l_back_slow
         servopos r,r_forward_slow
             pause 2200


         return



   lft180: sertxd(" lft180 ",13,10)
          servopos r, r_off
          servopos l, l_off


          pause 30
          servopos l,l_back_slow
          servopos r,r_forward_slow
          pause 4900

          return





    rgt90: sertxd(" rgt90  ",13,10)
          servopos r, r_off
         servopos l, l_off
         pause 30
         servopos l,l_forward_slow
         servopos r,r_back_slow

        pause 2200

        return

   rgt180:  sertxd(" rgt180  ",13,10)
         servopos r, r_off
         servopos l, l_off
         pause 30
         servopos l,l_forward_slow
         servopos r,r_back_slow
         pause 4900

         return




 bck:   sertxd("   bck    ",13,10)
        servopos r, r_back_slow
       servopos l, l_back_slow
       pause 1000

       return





allstop: sertxd(" allstop  ",13,10)
     	   servopos r, r_off
         servopos l, l_off
         pause 30

	 return
the codes worst than the video any ideas how i can improve it be glad too here.
 

hippy

Technical Support
Staff member
Looking at the code it seems you wait forever for an IR command and that will likely cause problems if one is not received. Perhaps adding a simple timeout will resolve things ? How were you doing it when not connected directly ?
 

jinx

Senior Member
hi,
Perhaps adding a simple timeout will resolve things ?
The first test code I tested was
Code:
symbol infra = b1
main:
irin [1000,main],C.4,infra 
   select case infra
	case 1
		gosub allstop
  	case 2
  		gosub lft90
	case 3
		gosub bck
sent the duck into a spin, removed the irin command the servo's was fine,when I put the irin into a subroutine then sent the servo's pin low got the irin cmd in.
How were you doing it when not connected
knowing that irin can compete for the timers that the servo's so I built a serial ir recieverirsender2 001.JPGirsender2 003.JPGsome time ago now and basicly 08m2 sits waiting for an input then the 08m2 then flags a pin on the 28x2 when ready send a byte. then the 28x2 used the " select case "
but am looking to use the hserin/out to the in the background if i finally add ir to the duck holding out for erf for communication for future builds
 

jinx

Senior Member
hi,
Well I used the IR peripheral device and sent the ir cmnds from the 08m sent serial to the 28x2, works well, that thing that appears to be a remote is infact a "ghost indicater" or will be in a couple of days for now it doubles as a remote!. The range is'nt great will build another soon for futher range.

I like the use of the IR peripheral because does away with the timing issue between the servo's an the IRIN cmnds
my test code :
Code:
init:

     servo pan,cen
     servo tilt,tcen
     servo r, r_off
     servo l, l_off
     pause 30
       
  pause 1000
 
 
 do
  pause 100
  if irflag = 1 then gosub getdata
      		
							' so go get it
		select case cmnd				' and move accordingly
			case 1
				gosub allstop
			case 2
				gosub T_rgt
			case 3
				gosub bck
		'	case 4
		'		gosub rgt90
			case 5
				gosub fward
			case 6
				gosub T_lft	
		
			    	
		
		end select
	

  loop
 
 
 '   
 
 '########### subroutines ###############
 
 
 getdata:
  pulsout toir,5
  serin fromir,n2400_8,cmnd
   pause 20
  return
  

  
  
  
 
  
fward: 
      servopos r, r_forward_slow
      servopos l, l_forward_slow
     	return


 T_lft:
      servopos l,l_back_slow
      servopos r,r_forward_slow
       return

 T_rgt:
       servopos l,l_forward_slow
       servopos r,r_back_slow
       return

 


 bck:
     servopos r, r_back_slow
     servopos l, l_back_slow
      return





allstop: 
   servopos r, r_off
      servopos l, l_off
     	 return
I think using this method adds for an overall smooth transitions in movement and directions without the stop to look to see if a new signal recieved .
 

jinx

Senior Member
hi,
I've been adding touch " a touchy duck " using a 14m2 to detect the touch then send a cmnd to the master picaxe similar to the ir remote setup.
still very much early development of the idea. I observed that where i put the hot glue into the tube to hold it in place I get much higher reading in the touch. The code is rough " as usual " will post soon.
jinx


Code:
; *******************************
; ***** Sample Header File  *****
; *******************************
;    Filename: 		
;    Date: 			
;    File Version: 	
;    Written by: 		
;    Function:		
;    Last Revision:
;    Target PICAXE:	
; ******************************* 


#picaxe 18m2
#com 3



symbol cmnd = b14
symbol junk= w10

symbol toduck   = c.6
symbol fromduck = c.7



symbol trsens = w3
symbol tlsens = w5
symbol    lts = b.7
symbol    rts = b.6





symbol  delay = 100



init: pause 100
      gosub setTsens
      pause 100
      
      
      
main: 
do
     touch16 rts,w3
         if w3 > w1 then 
          let cmnd = 20
         gosub senddata
       pause  10 
      endif
      
      
     touch16 lts,w5
         if w5 > w2 then 
          let cmnd = 10
         gosub senddata
       pause  10 
      endif
      
      
      
   loop





     
     
     
     
     
     
 senddata:  
            
        pause 10
    	high toduck										' tell MP that data is available
	pulsin fromduck,1, junk				                         ' junk is junk; we're just waiting
	low toduck										' prepare to send data
	
	serout toduck,N2400_4,(cmnd) 
	pause 10
	return
         let cmnd = 0
        
               return
 
  
 
 
 
 setTsens:
         
         touch16 b.6,w1                         'set right sensor
          let w1 = w1 + 150
           pause 10
          
         touch16 b.7,w2                         'set left  sensor
          let w2 = w2 + 200
          pause 10
          
          
          return
some test code I been working on thinking of adding " drawing pin " each time it triggers the program will jump to " setTsens" and hopeful it will stop false triggers on the other sensors when the room temperture increases
 
Last edited:

jinx

Senior Member
quick update,
Well the touch is going fine made a board that takes care of the touch and infra-red inputs the final version uses a 18m2 for six T inputs and the ir again it sends via serial comms.the touch mod 001.JPG
here's a quick vid turning in circle's it's just a test:
 

Paix

Senior Member
Very good video Jinx, the duck looks to be very substantial.

I couldn't make head or tail of your circuit in post 12, which is entirely down to to me, but I did notice that following the positive and negative leads from C1 and C2 to the bottom of the diagram, as shown, they both end up at a ground symbol. That can't be quite right, can it?

Perhaps I have missed or misread something? still a great project though.
 

jinx

Senior Member
hi

but I did notice that following the positive and negative leads from C1 and C2 to the bottom of the diagram, as shown, they both end up at a ground symbol
paix not sure i follow the schematic could have been better " AM at chapter 2 of the designspark manual the symbols of the bottom is the ground"right" and battery input on the left. Both c.2 and c.5 are the pins on the master picaxe 28x2, The one mistake I 've seen in the layout for the bi-led it's connected to b.3 and b.0 not the ground as indicated "had no tipex".
 

Paix

Senior Member
I'll buy that Jinx, but at the bottom of the diagram I managed to see two Ground connections. I now accept that the one on the left was supposed to be a positive battery connection, but, and please feel free to ignore or correct me as necessary - it's really quite minor :)

They look startlingly similar unless looked at particularly carefully as the one on the left looks like a crook Ground connection, but as a battery symbol, it should be connected to something on the other end, or at least have a stubby bit of lead from the negative end for it to be a battery symbol. Putting diagrams on their side so that the orientation is non-standard doesn't help either. As I said, it's minor and certainly doesn't detract from a lovely project. Just confuses the bejesus out of me from time to time.

Probably best to ignore me :)
 
Top