Go Down

### Topic: Digital Servo Speed? (Read 3534 times)previous topic - next topic

#### bigdipper

##### Jan 19, 2009, 09:51 pm
I just received my Arduino Duemilanove earlier today and spent the past few hours digging in.  I have little programming experience regarding hardware, so I am pretty noobish here.  I ran through the LED tutorial; then wired up a servo and experimented with PWM movements, and then found the Servo Sweep tutorial.  While I will be adding some additional functionality to my current project, a continuously sweeping servo is at the core so I am quite excited to be up and running so quickly.

[glow]Is there any way to control the servo speed via the Arduino?  I need to slow the sweep down to a crawl.  [/glow]

I am using a Hitec HS-5475HB digital servo.  Hitec offers a servo programmer that can change the speed of their servo's in 10% steps, but it is fairly expensive at about \$150.  I am hoping to find a method around this via programming.  I noticed that the degree sweep method moves slower than the sweep that naturally occurs when calling out two distinct endpoints, so I tried reducing the sweep amount from 1 degree to a decimal value, which didn't work (I'm assuming an integer value is needed here).  Otherwise, given my lack of experience with both Servo's and C, I'm at a loss ... other than excessively coding each individual location with an intermittent delay.

Any ideas would be greatly appreciated.

Current code:

#include <Servo.h>

Servo laserservo;  // laser servo

int pos = 0;           // laser servo position variable

void setup()
{
laserservo.attach(9);  // laser servo PWM control - Arduino pin 9
}

void loop()
{
for(pos = 0; pos < 120; pos +=1)   // sweep from 0 to 120 degrees in steps of 1
{
laserservo.write(pos);           // sweep start position
delay(15);                            // 15ms delay for sweep
}
for(pos = 120; pos>=0; pos-=1)     // sweep from 120 to 0 degrees in steps of 1
{
laserservo.write(pos);           // sweep end position
delay(15);                            // 15ms delay for sweep
}
}

#### retrolefty

#1
##### Jan 20, 2009, 02:00 amLast Edit: Jan 20, 2009, 02:01 am by retrolefty Reason: 1
The two delay(15) functions are what is determining the rate of change for the servos. Change it to delay(150) will make the ramp 10 times slower, delay (1500) will make it 100 times slower.

Lefty

#### bigdipper

#2
##### Jan 20, 2009, 04:36 pm
Nice, that variable was right under my nose.  The idea crossed my mind last night, but then I figured  the delay had to do with the 20ms servo timing.  Thanks for the help, worked like you said.

It's not critical, but is there a way to increase the resolution higher than 1-degree?  At a 15ms delay, the rotation is fairly fluid, but when I drop down to 900ms, the 1-degree jumps become quite apparent.

Would modifying the code to use specific PWM values rather than degrees work?  Or is there an easier solution (ie. fractional degrees)?

#### retrolefty

#3
##### Jan 20, 2009, 06:10 pm
First keep in mind that PWM (pulse width modulation) is not the same or what is used to drive R/C type servos. PPM (pulse position modulation) is what the servo library uses to command servo position. PWM is a built in function used by the analog-write function while the servo PPM functions are supplied in the library function.

As far as obtaining better resolution, I don't really know. The servo library uses degrees as it's argument but internally the library converts this to the equivalent microseconds needed for each degree of increment or decrement value. You will have to see if some software wizard around here can tell us if there is a way to directly move servos in microsecond resolution?

Lefty

#### mem

#4
##### Jan 20, 2009, 06:30 pmLast Edit: Jan 20, 2009, 06:33 pm by mem Reason: 1
The library described in this thread uses microseconds instead of degrees: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230479947

Bear in mind that most hobby servos wont actually resolve to differences of one  microsecond but you should get better resolution.

#### combatdave

#5
##### Jan 20, 2009, 08:37 pm
you could maybe swap some of the gears around in the gearbox of the servo?

i should point out, however, that i dont have a clue what im talking about. today was the first time i saw the inside of a servo gearbox, and it was a youtube video. but still, maybe it will work.

Go Up