Go Down

### Topic: Servo speed control/variation smoothly with Arduino (Read 2856 times)previous topic - next topic

#### digitAlex

##### Jul 08, 2011, 03:48 pm
Hello,

I need to control the speed of a standard servo (not continuous) using Arduino and a R/C radio. I found a lot of example on the web but in most of cases are not suitable for my case.

My need is to control the speed of the servo proportionally to the stick movemente, as follow:

- stick forward slightly: servo turns slowly
- stick full forward: servo turns quickly (speed proportional to the stick)
- stick in the center: servo stops in the position where it is.
I have no problem to read stick position from R/C using PulseIn.

In the doc I found also the Servo library that however is not suitable. My idea is to increase PWM width proportionally to the stick angle in order to move the servo until it arrives to maximum position or the stick turns to center position. I can't use the servo.write() function because it accepts only an integer parameter from 0 to 180 corresponding to the servo angle. I need to control speed very smooth, using fraction of degrees.

How can I solve it?

#### Cylindric

#1
##### Jul 08, 2011, 04:00 pm
That's kind of how servo's work - you tell them the angle to go to, and they try and get there as fast as they can.

You'll have to write some code that'll moves it in steps.

So instead of a single "Turn to 90 degrees" command, issue a set of

Turn to 1 degree
wait a tiny bit
Turn to 2 degrees
wait a tiny bit
Turn to 3 degrees
...

A "Tiny Bit" varies depending on how fast you want to move the servo.
Current Projects: Rodentometer - Hamster Endurance Moni

#### digitAlex

#2
##### Jul 08, 2011, 04:08 pm

That's kind of how servo's work - you tell them the angle to go to, and they try and get there as fast as they can.

You'll have to write some code that'll moves it in steps.

So instead of a single "Turn to 90 degrees" command, issue a set of

Turn to 1 degree
wait a tiny bit
Turn to 2 degrees
wait a tiny bit
Turn to 3 degrees
...

A "Tiny Bit" varies depending on how fast you want to move the servo.

Yes, correct, this is exactly what I want to do but in order to have a smooth movement I need to turn servo with fraction of degrees:

Turn to 0,3 degree
wait a tiny bit
Turn to 0,6 degree
wait a tiny bit
Turn to 0,9 degree
wait a tiny bit

and servo.write() function doesn't accept decimal values. How can I do?

#### Cylindric

#3
##### Jul 08, 2011, 04:19 pm
Less than one degree?  That's pretty fine.  From 12:00 to 12:01 on my watch is 6 degrees.

I'm not sure on the detailed internals of servos, but you could roll-your-own servo control and calculate your own PWM pulses, I guess.

That's assuming you're using something more clever than a little £5 hobby-servo.  Some of those rattle by more than what you're looking for
Current Projects: Rodentometer - Hamster Endurance Moni

#### digitAlex

#4
##### Jul 08, 2011, 04:30 pm

Less than one degree?  That's pretty fine.  From 12:00 to 12:01 on my watch is 6 degrees.

I'm not sure on the detailed internals of servos, but you could roll-your-own servo control and calculate your own PWM pulses, I guess.

That's assuming you're using something more clever than a little £5 hobby-servo.  Some of those rattle by more than what you're looking for

You are right

Less then one degree because I'm working on a camera gimbal and I'm using a digital servo metal gear to control tilt movement, if I move the camera support of one degree step-by-step probably video quality is not good (vibration). That's the reason why I need a smooth movement, maybe with a smaller angle.

#### Cylindric

#5
##### Jul 08, 2011, 04:40 pm
Interesting.  Are you moving your camera one step, then stopping for a noticeable while, then another step, etc?  Or is it a smooth-but-slow pan?  I'm just curious if the momentum of the kit would keep it smooth enough, even at 1 degree steps.

Have you tried it?  I only ask, as the risk of prematurely 'optimising' the thing to milli-degree angles might not be necessary.
Current Projects: Rodentometer - Hamster Endurance Moni

#### Cylindric

#6
##### Jul 08, 2011, 04:51 pm
Forgot to add, if it is, then you could experiment by sending your own pulses to the servo using your own timings.

Look in the Servo.cpp include to see how it's done.  Some scary timing considerations in there

Oh, or try the Servo.writeMicroseconds() instead.  That allows for fine-grained control, you just need to know your servo's parameters.
Current Projects: Rodentometer - Hamster Endurance Moni

#### digitAlex

#7
##### Jul 08, 2011, 05:01 pm

Interesting.  Are you moving your camera one step, then stopping for a noticeable while, then another step, etc?  Or is it a smooth-but-slow pan?  I'm just curious if the momentum of the kit would keep it smooth enough, even at 1 degree steps.

Have you tried it?  I only ask, as the risk of prematurely 'optimising' the thing to milli-degree angles might not be necessary.

My need is to have a smooth-but-slow pan. The camera gimbal is a part of an hexacopter drone for aerial video. For pan rotation I modified a servo removing the potentiometer for a continous movement up to 360°, speed is controlled directly by the radio proportionally to the stick. But for tilt I can't do the same because I need to limit the maximum angle to 180°, so in this case I think that smooth-but-slow movement is the right solution.

I found this library: http://arduino.cc/forum/index.php/topic,61586.0.html
Does anyone tried it?

#### Cylindric

#8
##### Jul 08, 2011, 05:11 pm
Not me, but check out the writeMicroseconds.  It would seem to offer the sub-degree rotation you require.
Current Projects: Rodentometer - Hamster Endurance Moni

Go Up

Please enter a valid email to subscribe