Author Topic: Arduino - Servo Speed Control Question  (Read 5429 times)

0 Members and 1 Guest are viewing this topic.

Offline LXETopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
Arduino - Servo Speed Control Question
« on: October 07, 2010, 06:12:39 AM »
How do you control the rotational speed of the servo with the Arduino?

I have a very vague algorithm that might not work.

while (i <> degree)
{
i = i + 1 // new servo position
servo.write(i); // rotate servo to position "i"
delay(x); // wait "x" amount of milliseconds
}

Offline knossos

  • Robot Overlord
  • ****
  • Posts: 278
  • Helpful? 14
Re: Arduino - Servo Speed Control Question
« Reply #1 on: October 07, 2010, 07:23:00 AM »
That looks like it would work.  But i would add some code to keep it from trying to go beyond the angle limits of your servo.  Not sure how necessary it would be, but I like to add error trapping in all my code.  Of course I'm used to programming PCs which the added memory usage is insignificant compared to potential problems.
"Never regret thy fall,
O Icarus of the fearless flight
For the greatest tragedy of them all
Is never to feel the burning light."
 
Oscar Wilde

Offline KurtEck

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: Arduino - Servo Speed Control Question
« Reply #2 on: October 07, 2010, 07:55:44 AM »
I did something similar to this with an Arduino Pro.  But I wrote a new library that did it for multiple servos and I had a set of functions that said move the following servos from their current location to a new location (angle) in this amount of time.

This library I did was write an ISR for a timer that overflowed every 16ms.  I then calculated for each servo how much change in the angle (in ms) should happen per interrupt.  The interrupt then updated all of the servos that needed updating.  If all of the servos are at their desired location the timer is disabled.  There are also functions to query to find out which servos are still moving. 

This code was not tested much but I did have a Lynxmotion Biped Brat walking using it.  I did the servo update code in the background as this allows me to go off and query the XBEE or PS2 for additional information and for example rotated the turret while it is still in the middle of a step.  I would share this if desired but remember it is simply a work in progress...

Kurt

Offline LXETopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
Re: Arduino - Servo Speed Control Question
« Reply #3 on: October 07, 2010, 04:48:25 PM »
That looks like it would work
I think I don't need the delay because servos tend to slow down when they are told to move to a position close to it.


Offline knossos

  • Robot Overlord
  • ****
  • Posts: 278
  • Helpful? 14
Re: Arduino - Servo Speed Control Question
« Reply #4 on: October 07, 2010, 05:16:33 PM »
I would start with a delay and reduce it until you have the desired speed.  Besides if you start with a larger delay it gives you more of an idea if it is doing what you want since it's going slower.  If you find the delay is unnecessary you can always comment it out later.
"Never regret thy fall,
O Icarus of the fearless flight
For the greatest tragedy of them all
Is never to feel the burning light."
 
Oscar Wilde

 


Get Your Ad Here

data_list