Author Topic: Theory of servo control?  (Read 2692 times)

0 Members and 1 Guest are viewing this topic.

Offline klimsTopic starter

  • Robot Overlord
  • ****
  • Posts: 190
  • Helpful? 2
Theory of servo control?
« on: December 23, 2008, 09:13:56 PM »
Hi guys,

Up until now I have never attempted to control servos in C, and Its been a while since I have coded in C. I have been using the basicATOM and it uses the basic laguage to control servos. It's way easy.
So I think I understand the fundamentals of how servos work and how to control them, but I was wondering how you guys are going about coding this up. So here are the questions I was thinking about. I know I'm a noob so if these questions have been asked and answered before(I cant find them) please direct me to the right place.
Are you using interrupts to control servos? This would limit the number of servos you can run right?
Do you have separate h files written that you use to control servos each servo? Or just one file that controls all?
If you are not using interrupts, can you still get servo control running in the 'background'?
How do you correlate the processor speed to pulse width? (how many instructions per second... etc)

Thanks for your help guys. I would like to get this straight in my head before I dive in and make a mess of it.

Andrew.

Offline bulkhead

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 0
Re: Theory of servo control?
« Reply #1 on: December 24, 2008, 03:48:41 AM »
Interrupts should be the only way to directly control servos; there's no other way to generate that type of strict timing.  There may be an upper limit on how many servos you can run if the rest of your code is very time consuming, but it wouldn't be impossible to control as many servos as I/O pins and still be able to do other processing.  This would involve sorting the servo pulses from shortest to longest, finding the time interval between each two pulses, converting that time interval into clock cycles/counter increments and then setting a timer to interrupt after that amount of cycles/increments has elapsed.  If you need to control multiple servos, just get a servo controller ($30-$40); it will allow you to just "set and forget" the servo position and it will constantly update the servo.  Many servo controllers also have automatic ramping, so you can set the rate that it goes to any given position (without a servo controller, this would be accomplished with a for loop).

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Theory of servo control?
« Reply #2 on: December 24, 2008, 09:08:37 AM »
also I just wanted to note that hardware PWM is also set and forget . The ATmega168 for example has 6 Hardware PWM pins so you can control 6 servos in the set and forget manner.
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Theory of servo control?
« Reply #3 on: December 27, 2008, 03:50:12 AM »
Lots of different ways . . . PWM, interrupts, and simple delays.

Delays are the easiest but waste processing time.

Interrupts are the hardest to debug because they can interfere with other interrupts.

PWM is the most accurate, simplest, and doesn't interfere with other code. However PWM pins are very limited so won't work if you use a lot of servos.

Offline klimsTopic starter

  • Robot Overlord
  • ****
  • Posts: 190
  • Helpful? 2
Re: Theory of servo control?
« Reply #4 on: December 28, 2008, 07:54:47 AM »
Thanks for the input guys. I think I might start off with PWM and work my way up to interrupts. I bought a cheapo microcontroller to practice on. Ideally I would like to be able to control my biped (17 DOF) so I think interrupts will be the way to go.


Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Theory of servo control?
« Reply #5 on: December 28, 2008, 08:04:55 AM »
have you thought of connecting the axon to a dedicated servo controller like this one - http://www.lynxmotion.com/Product.aspx?productID=395 - its $40 and you can control up to 32 servos. You communicated with the servo controller through the Axon's UART port.
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline klimsTopic starter

  • Robot Overlord
  • ****
  • Posts: 190
  • Helpful? 2
Re: Theory of servo control?
« Reply #6 on: December 29, 2008, 08:02:16 PM »
I didn't even realise that was possible! It would seem like a good solution because I would have more time free for computation.
Thanks for the suggestion airman00!

 


Get Your Ad Here

data_list