luna :desktop bot

jinx

Senior Member
hi all,
DSCF0015.JPGAm learning to program,and this is my little bot too help me, at the heart is a 28x2 but am going to change that too a 20x2there is 14m2 which takes care of the input controls.i,ve added a vid on youtube.
http://youtu.be/8j0UJqrzUF4


the program rough at the mo am still tweeking but am having a lot fun with it.
jinx
 

Attachments

Last edited:

jinx

Senior Member
here's the program am working on
Code:
; *******************************
; ***** LUNA  *****
; *******************************
;    Filename:      luna,lives		
;    Date:         29 july 2012 			
;    File Version: 0,1 	
;    Written by:   jinx		
;    Function:     bot control		
;    Last Revision:
;    Target PICAXE: 28x2	
; ******************************* 

'### directives #######
#com3
#picaxe 28x2
#no_data
#no_table
#terminal 9600


'##### constants #######
symbol abit   =  500
symbol fromir = c.5
symbol toir   = c.1


symbol counter = b6

'#### variables #######

symbol irflag  = pinc.5
symbol cmnd    = b0


'**********************************************************
'         flooe sensor/rgb   
'**********************************************************
symbol r_led = c.6
symbol g_led = c.2
symbol b_led = c.7

'**********************************************************
'       srf05 ultrasound sensor                       
'**********************************************************
 
symbol  ping  = b.0                               ' Define output pin for Trigger pulse
symbol  echo  = c.0                               ' Define input pin for Echo pulse
symbol lrange = w10
symbol rrange = w11
symbol  range = w14

'**********************************************************
'               HEADSCAN
'**********************************************************
symbol pan = b.6
symbol rgt = 225
symbol lft = 85
symbol cen = 152

'**********************************************************
'           hood control
'**********************************************************
symbol      hood = b.7
symbol  openhood = 95
symbol closehood = 169

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

symbol l_back_slow = 157
symbol l_back_fast = 215
symbol l_off = 145
symbol l_forward_slow = 136   
symbol l_forward_fast = 75   

symbol r_back_fast = 117
symbol r_back_slow = 139
symbol r_off = 147
symbol r_forward_slow = 152  
symbol r_forward_fast = 171  

symbol r = b.5
symbol l = b.4


part two
Code:
init:
 
 servo r,r_off
 servo l,l_off
 servo hood,closehood
 servo pan,cen
 pause 30
  HI2cSetup i2cmaster, %11100000, i2cslow, i2cbyte 
  let b3 = 10                                           'send cmd to cylon
     HI2cOut 0,( b3 ) 
    high g_led
    pause 100
   
   


  main: 
  low   g_led
  high  b_led
  pause 100 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
do
   pause 100
   if irflag = 1 then gosub getdata
    select case cmnd
    case  1
       gosub roam
    case 2
      gosub closehod
     case 3
       gosub bck
     case 4
      gosub openhod
     case 5
        gosub rgtturn
     case 6
        gosub allstop
     case 7
        gosub lftturn  
   case 8
      gosub openhod 
     case 9
        gosub fwd
   '  case 10
    '  gosub scanlft 
      'case 22
     'gosub t1iput  
   end select
   loop
   

getdata:
        pulsout toir,5
         serin fromir,n2400_8,cmnd
         sertxd(#cmnd,cr,lf)
         return
       
       
       
       
 '#### luna's drive subroutines ##############     


    fwd:
             
            ' sertxd("  forward  ",cr,lf)
          
             high  r_led
             low   g_led
             low   b_led
                pause 100 
             servopos r, r_forward_slow
             servopos l, l_forward_slow
             
             return              
             
   
       bck:
           
             'sertxd("   backwards   ",cr,lf)
              low   r_led
              high  b_led
               low   g_led
               pause 100 
               servopos r, r_back_slow
               servopos l, l_back_slow
            
             
             return     

         
      allstop: 
               
            ' sertxd("  allstop  ",cr,lf)
              low   b_led
              low   r_led
              low   g_led
            
             servopos r, r_off
             servopos l, l_off 
             
             return 
             


  rgtturn:
              
            ' sertxd("rightturn",cr,lf)
              low   b_led
           high  g_led
             pause 10
             
       servopos l,l_forward_slow
       servopos r,r_back_slow
       
           
             return
   
  
        
     
             
       
     lftturn:  
             
         '  sertxd(" leftturn  ",cr,lf)
             low   b_led
           high  g_led
           
            servopos l,l_back_slow
            servopos r,r_forward_slow
            
             return 
             
      
     
 lft90:
      gosub allstop
   
'servopos l,l_back_slow
'servopos r,r_back_slow
       pause 30
servopos l,l_back_slow
servopos r,r_forward_slow
       pause 1300
       gosub allstop
       return
       
 
 lft180:
      gosub allstop
   
'servopos l,l_back_slow
'servopos r,r_back_slow
       pause 30
servopos l,l_back_slow
servopos r,r_forward_slow
       pause 2500
       gosub allstop
       return    
             
          
rgt90:
       gosub allstop
   
       pause 30
 'servopos l,l_back_slow
 'servopos r,r_back_slow
       servopos l,l_forward_slow
       servopos r,r_back_slow
       pause 1300
      gosub allstop
      pause 30
  return   
  
  
 rgt180:
      gosub allstop
   
'servopos l,l_back_slow
'servopos r,r_back_slow
       pause 30
servopos r,r_back_slow
servopos l,l_forward_slow
       pause 2500
       gosub allstop
       pause 30
       return    
             
  
              
     
       
             
             
             
     
                  
'###### luna hood subroutines##########                  
  openhod:
         
     pause 10
       gosub cylonl
       pause 10
       for b6 =closehood to openhood step -2
       servopos hood,b6
       pause 200
       next b6 
       let cmnd = 0
       return
  
  
      
 closehod:
      pause 10
       gosub split1
       pause 10
       for b9 =openhood to closehood step 2
       servopos hood,b9
       pause 200
       next b9 
       let cmnd = 0
       return
  
        

 
 roam:
   high b_led
   pause 10
   gosub openhod

     for counter = 1 to 3
     servopos r, r_forward_slow
     servopos l, l_forward_slow
        
    for b4 = lft to rgt   step 2
    servo pan,b4
    pulsout ping,4                                      ' produce 20uS trigger pulse (must be minimum of 10uS)
    pulsin echo,1,range : range = range * 2             ' measures the range in 10uS steps
                                           ' recharge period after ranging completes
    let range=range*10/ 115
    if range < 25 then gosub rgt90
    if range < 15 then gosub lft180
    pause 30
      next b4

        for b4 = rgt to lft step - 2
        
        servopos r, r_forward_slow
        servopos l, l_forward_slow
        servo pan,b4
        pulsout ping,4                                      ' produce 20uS trigger pulse (must be minimum of 10uS)
        pulsin echo,1,range : range = range * 2             ' measures the range in 10uS steps
                                                  ' recharge period after ranging completes
       let range=range*10/ 115
        if range < 25 then gosub lft90
       if range < 15 then gosub rgt180
       
       pause 30
        next b4
    next counter
          servopos pan,cen
          pause 30
           gosub allstop
          pause 30
          gosub closehod
          pause 30
          

     return
 
 
 
 '######### I2C camds   ##################################
 ' following subrotines using i2c setup sends the values b3 hi2cout slot 0 
 ' the 20x2 led module receives the cammand is sent three times           
             
             
             
             
   cylonl:
       for  counter = 1 to 3
       let b3 = 10                                           'send cmd to cylon
     HI2cOut 0,( b3 ) 
     sertxd("sent cylon ",#b3,13,10) 
     next counter
     return       
     
     
     
      split1:
      for  counter = 1 to 3
       let b3 = 30                                           'send cmd to cylon
     HI2cOut 0,( b3 ) 
     sertxd("sent split ",#b3,13,10) 
     next counter
     return
its rough but it works
 

erco

Senior Member
Beautiful Bot, jinx! Great features and it looks great. The moving dome and ultrasonic servo sweep are fabulous. Keep up the good work and submit that as a project in the monthly contest. You'll win!
 

jinx

Senior Member
hi,
thanks erco for your comments, still tweeking bits of the programs,as for winning the monthly contest i could'nt win a waffle even if i was the only one buying the tickets.you clicked to the name change it's a sad story i explain it later.
thanks jinx
 

jinx

Senior Member
hi,
well i entered luna " three times i think":confused: into the monthly contest, although the link to the video at picaxe.com seems broken to me keeps saying error 404, think i may need to change a setting in utube. would anyone please try the link,if it it blocked does anyone now how i unblock the link.
jinx
 

erco

Senior Member
You have a period at the end of the link, which causes the 404 error. Take it out and it does go to youtube, but it says there's a validation error.
 

jinx

Senior Member
thanks erco dont know how the period got into the link,as for the validation error not got a clue yet the link at start of this thread work and it was a cut'n'paste job from here and i don't appear i can edit the post now it submitted going send an email see if some one can edit over at picaxe.com.
 

erco

Senior Member
At home, I have the name & email of a very helpful fellow at Rev-Ed, I'll find that for you tonight. I'm sure he can assist.
 
Last edited by a moderator:

hippy

Technical Support
Staff member
We will update link in the Project Gallery. We normally check that video links etc are working once a project is published on the gallery but that one seems to have been missed.
 

hippy

Technical Support
Staff member
www.youtube.com/watch?v=8j0UJqrzUF4 seem to work would you please add this link
Aha; multiple corrections needed to the original. All done now so ignore the email sent to you earlier.
 

jinx

Senior Member
am running this part of the code on the 14m2 "input controls".
Code:
#picaxe14m2

symbol toluna   = c.0						' serout line to master processor
symbol fromluna = c.4

symbol bone  = b.5
symbol btwo  = b.4
symbol bthree= b.3
symbol bfour = b.2
symbol bfive = b.1


symbol led = c.2

symbol cmd = b14
symbol junk= w10

main:do

touch16 bone,w1 
  if w1 > 3710 then
   sertxd (#w1,cr,lf)     
   gosub irint
 endif

touch16 btwo,w2                                          ; read value into w0
   if w2 > 4000 then
   sertxd (#w2,cr,lf)     
   let cmd = 22
   gosub senddata
 endif

touch16 bthree,w3                                       ; read value into w0
   if w3 > 3850 then
    sertxd (#w3,cr,lf)     
   let cmd = 4
   gosub senddata
 endif

touch16 bfour,w4                                     ; read value into w3
   if w4 > 4070 then
    sertxd (#w4,cr,lf)     
   let cmd = 1
   gosub senddata
 endif

touch16 bfive,w5                              ; read value into w4
  if w5> 4460 then
   sertxd (#w5,cr,lf)     
  let cmd = 2 
  gosub senddata
endif

loop


senddata:
 pause 10
 high led
 sertxd (#cmd,cr,lf)
 high toluna										' tell MP that data is available
 pulsin fromluna,1, junk				                         ' junk is junk; we're just waiting
  low toluna										' prepare to send data
   serout toluna,N2400_4,(cmd) 
  let cmd = 0
 low led
 pause 30  	
 return
 
 irint: 
   
 do 
  irin c.1, infra
  
  select case infra
   case < 13 
     inc infra
     
     case 14
     
     infra = 0
      
     case < 22
       
     infra = infra -6
       
     else
       goto skip
  end select
  
  
  high toluna
  high led
  pulsin fromluna,1,junk
  low toluna
  serout toluna,n2400_4,(infra)
   sertxd (#infra,cr,lf)
  pause 20
  low led
   if infra = 11 then gosub exit1
   
  skip:
       pause 500
        loop   
  
  
   exit1:
   high led
   pause 10
    sertxd ("exit",cr,lf)
    low led
    goto main
now the touch inputs work's but they will need to be calibrated at some time three of the buttons i have another method which does not require a manual cali. but the two buttons i use too open and close the hood cant use it as the sensativity wont pass through both plastic when the hood is open.but it takes litlle time to manual change those two.this is why i kept the sertxd cmd in the code as it indicates which sensor giving the faulse press.
 

thomasfoltz

New Member
Nice features. I've never worked with the touch sensing. What's involved there, a capacitive sensor hooked up the touch sensor pin?
 

jinx

Senior Member
poor mite

hi,
thx the poor mite been sat on my desk far to long, its awaiting a new 3D printed chassis, in the coming weeks
jinx
 
Top