Author Topic: cool servo program  (Read 4329 times)

0 Members and 1 Guest are viewing this topic.

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
cool servo program
« on: May 10, 2008, 08:46:26 PM »
Hello, after speading about 5 hours scruwing around with my atom, I came up with a program that can take a value from a pot and rotate a servo in the direct as long as the pot is that specific value. Also, the servo stays at that position when the pot is back to 0 degrees. (check out code  )
what my question is is that my program has the servo stop at my desired position but doesn't hold. If anyone has any idea how to get the servo value before it stops and have it hold that position instead of doing nothing.
Code: [Select]
'=========variables=============
yservo var sword
counter var sword
counter = 0
ttime var bit
ttime = 1

'=========maincode=============
  
loopit:
adin ax0,1,ad_ron,yservo

   if yservo < 700 then
      repeat
      counter = (counter - 25)
         servo p5, counter, ttime
         adin ax0,1,ad_ron,yservo
      until yservo > 700
    
   elseif yservo > 710
      repeat
      adin ax0,1,ad_ron,yservo
      counter = (counter + 25)
         servo p5, counter, ttime
      until yservo < 710
   else
   gosub nothing
   endif

goto loopit    
    
'===========subcommand==============
    
nothing:
   pause 1
   return    
  
 




Bane

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: cool servo program
« Reply #1 on: May 10, 2008, 11:01:01 PM »
Send 1.5ms, for example, to the servo will make it go to that position and hold. If it doesn't hold, it means you are applying more force than its maximum output torque.
I haven't checked your source code, but remember, the signal must be sent 50 times per second (even if your pot - input, has not changed). Don't send the signal only when the input changes!
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: cool servo program
« Reply #2 on: May 11, 2008, 04:36:31 AM »
Quote
I haven't checked your source code, but remember, the signal must be sent 50 times per second (even if your pot - input, has not changed). Don't send the signal only when the input changes!
Thats exactly what i'm trying figure out.  I have a three-way "if" statement regarding the pot input.  (center of pot is 707)   If x < 700 than add 15 to servo value and repeat until x >700.  Vise versa when x > 700.  If value is between 700 and 710 it does nothing.  Instead of nothing i want the servo to hold the (last value received). 
Oh wait ::), my servo variable doesn't reset its self being that i have it above the loop, so if i add or sub. from that value it should stay the same.  So all i have to do is put a servo position in place of the "nothing"

Bane

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: cool servo program
« Reply #3 on: May 11, 2008, 04:40:44 AM »
Ha :D that was easy!
Code: [Select]
'=========variables=============
yservo var sword
counter var sword
counter = 0
ttime var bit
ttime = 1

'=========maincode=============
 
loopit:
adin ax0,1,ad_ron,yservo

   if yservo < 700 then
    repeat
    counter = (counter - 25)
    servo p5, counter, ttime
    adin ax0,1,ad_ron,yservo
    until yservo > 700
   
   elseif yservo > 710
    repeat
    adin ax0,1,ad_ron,yservo
    counter = (counter + 25)
    servo p5, counter, ttime
    until yservo < 710
   else
   gosub hold
   endif

goto loopit   
   
'===========subcommand==============

hold:
servo p5, counter, ttime
return

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: cool servo program
« Reply #4 on: May 11, 2008, 04:43:40 AM »
The really cool thing about this program is that you can control a servos position by add or sub. from a pot or two buttons, even hold ;D.  (please tell me that this could be useful :o)

Bane

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,704
  • Helpful? 173
    • Society of Robots
Re: cool servo program
« Reply #5 on: May 24, 2008, 07:15:50 AM »
Quote
The really cool thing about this program is that you can control a servos position by add or sub.
This is very similar to how my Stampy robot controls the sharp IR servo, and how my ERP robot rotates it's head. ;D

Offline simpsonss

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
Re: cool servo program
« Reply #6 on: May 13, 2009, 03:51:06 AM »
The language u used is it BASCOM?

thanks.

 

SMF spam blocked by CleanTalk