VarSpeedServo - a modified Servo library with speed control

How are you powering your servo? Not from the Arduino 5V pin, I hope. Have you tried the "Sweep" example from the Servo library?

Thanks for your reply. The sweep example works but when I try and add the myservo.slowmove the servo stops working.

Please post your most recent code.

The code is in my first post but here it is again.

#include <VarSpeedServo.h>

VarSpeedServo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int speed = 0;

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo.slowmove(pos,speed); 
}

void loop() {
  for (pos = 0; pos <= 92; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);
    myservo.slowmove(pos, speed);  // tell servo to go to position in variable 'pos'
    delay(20);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 92; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees              // tell servo to go to position in variable 'pos'
    myservo.write(pos);
    myservo.slowmove(pos, speed);
    delay(20);                       // waits 15ms for the servo to reach the position
  }
}

Please let us know how to control continuous rotation servo motor - To run CW rotation ( 10 turns) then it stopped until we send another command CCW rotation (3 turns)

How can i move slowly to a position when i power up the Arduino?
writeMicroseconds does not take 3 argument's and "write" always goes fast to the middle position before going to the given value on startup.

On attach, the servo moves to it's current position. So do a write before you attach.

I am also trying this library but most of the time after i upload the new position value to the servo, first it moves very fast than only it moves at given speed. My program is:

#include <VarSpeedServo.h>

VarSpeedServo servo1;
VarSpeedServo servo2;
VarSpeedServo servo3;
int pos;
uint8_t speed = 20;
void setup() {
  servo1.attach(5); 
  servo2.attach(8);
  servo3.attach(6);

  Serial.begin(9600);
}

void loop() {
     pos = 0;
     servo1.slowmove (pos, speed/2);
     servo2.slowmove (pos, speed);
     servo3.slowmove (pos, speed*2); 
}

There's not much you can do about that, it's just what servos do. When the power is first applied they centre themselves at full speed and only then do they look at the input signal to see where to move next.

In fact normal servos always move at full speed. VarSpeedServo.slowmove() or the equivalent write(value, speed) makes many small moves to give the appearance of moving slowly.

At least that's been true of all the servos I've worked with over the years.

Steve

Hi, i`m new to this so please be kind. LOL

I`m trying to control the speed of my me arm with the following sketch.

#include <VarSpeedServo.h>

VarSpeedServo servo1;
VarSpeedServo servo2;
VarSpeedServo servo3;
VarSpeedServo servo4;

const int Servo1Pin=5;
const int Servo2Pin=6;
const int Servo3Pin=9;
const int Servo4Pin=10;

void setup()
{
Serial.begin(9600);
servo1.attach(Servo1Pin); // attaches the servo on pin 5 to the middle object
servo2.attach(Servo2Pin); // attaches the servo on pin 6 to the left object
servo3.attach(Servo3Pin); // attaches the servo on pin 9 to the right object
servo4.attach(Servo4Pin); // attaches the servo on pin 10 to the claw object
}

void loop()
{
servo1.write(90, 255, true); // sets the servo position according to the value(degrees)
servo2.write(90); // does the same
servo3.write(120); // and again
servo4.write (120); // yes you've guessed it
delay(300); // doesn't constantly update the servos which can fry them
}

When I try to add the speed in the write command I get a compliation error as follows.

C:\Users\paul-emile.roy\Documents\Arduino\MeArm_Calibration\VarSpeedServo\VarSpeedServo.ino:30:29: note: candidate is:

In file included from C:\Users\paul-emile.roy\Documents\Arduino\MeArm_Calibration\VarSpeedServo\VarSpeedServo.ino:1:0:

C:\Users\paul-emile.roy\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:130:8: note: void VarSpeedServo::write(int)

void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds

^

C:\Users\paul-emile.roy\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:130:8: note: candidate expects 1 argument, 3 provided

exit status 1
no matching function for call to 'VarSpeedServo::write(int, int, bool)'

What am I doing wrong?

Thanks

Paulroy2011:
What am I doing wrong?

First, you are hijacking a thread. It will be better if you start your own post.
Second, you need to re-read the "how to use this forum" sticky post at the top of the forum.
Third, you need to use code tags when posting code (one of the items covered in the "how to use" thread.
Fourth, you should post a link to the library you used.

Edit: just guessing since I do not know which library you used, but the prototype for the write in at least one library by that name looks like this:
void VarSpeedServo::write(int value, uint8_t speed, bool wait)
Perhaps declare a speed variable as uint8_t, assign it your speed value and pass it in to the write command.

MrGlasspoole:
How can i move slowly to a position when i power up the Arduino?
writeMicroseconds does not take 3 argument's and "write" always goes fast to the middle position before going to the given value on startup.

Hello,

i think you can modify the servo.
Open the Servo and look for the potentiometer that give the position to the Servocontrol.
Measure the output to find out the correct pin.
!!! Make sure that the max output is not over 5V !!!

Soldering a wire to it and connect it to a analog input.
look here: http://www.mafu-foto.de/elektronik/servos/104-servos-um-positionsrueckmeldung-erweitern

At the setup read first the input from the servopotentiometer and calculate the position.
Then move to this position.

I hope it works in the beginning of the sketch.
If is not working to eliminate the fast movement at the startup than you have at least
a position feedback :wink:

I will test it in the evening......

1 Like

Hi All,
Does anyone know if anybody has successfully modified this library (or any other), to operate with an ESP8266 and provide variable speed servo operation using the Arduino IDE?
This library "as is" is not compatible, and gives errors when you try to compile.
The standard servo library works, but I want variable speed.
Due to other factors, any of the other solutions using loops and delays to smooth servo movement are not acceptable (other libraries I use cannot work with the delay command).

Kindest Regards

Bob

You do not need to use delay() to slow down the servo movement.
Have you read through Robin2's Demonstration code for several things at the same time?

I am not saying that varspeedservo would not be a nice tool for you. Many people use it and appreciate the simplicity.

But I just wanted to point out that you can skip the use of delay() and still have slow servo movement with the standard library.

Hello,
First of all, thank you for a great library!

My question is whether it is possible to get the servo to run with a smooth, continuously movement when at low speeds. I want it to move on the lowest speed, but right now it is doing this by moving small, incremental steps.
Anybody knows if this is possible by using this library?

Thanks!

No. But the problem is with the servo itself not the library. Servos have no speed control, they always move at full speed. So the only way to get them to seem to move slowly is by making small steps with gaps between, which is what VarSpeedServo does. But at very slow speeds the gaps are very noticeable.

The smoothest slow move you can get with a standard servo is to change the signal in 1 microsecond increments with a pause between each. To see what this is like try this modified Sweep example from the IDE:

// Sweep using microsecond increments rather than degrees

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int pos = 0;    // variable to store the servo position (microseconds)

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 800; pos <= 2200; pos += 1) { // from 800 microseconds to 2200 in 1us steps
    myservo.writeMicroseconds(pos);             // tell servo to go to position in variable 'pos'
    delayMicroseconds(500);                         // Change this value to get the speed you want
  }
  for (pos = 2200; pos >= 800; pos -= 1) {  // goes from 2200 microseconds 800     
    myservo.writeMicroseconds(pos);             // tell servo to go to position in variable 'pos'
    delayMicroseconds(500);                         // Change this value to get the speed you want  
  }
}

If that's not smooth enough then you can't use a standard servo.

Steve

Hey man, just wanted to send a thank you for this. I have a project coming up where I needed to a servo I could control the speed of. What's even better, I've never worked with servos before ... now, and this was easy as can be to implement.

That being said I have noticed that on movement there tends to be a pause after I do one of the movements, and I see the servo slowly, "ticking", as if still trying to move. So it's almost like it moves to quick, then there's down time

Thank you again for this.

Hi Korman,

I'm using your library for an exam project. First of all, good job with the library, is amazing! By the way, I'm using two servos D980TW (D980TW Servo-Clockwise (stock)-Stock Rotation - ServoCity) and I can't find the values for limit the speed (I'm referring the 127 that you have wrote on the speed limit of your servos). Can you help me?

Thanks since now,

Is there a way to use the varspeedservo library with timer 2 instead of timer 1? timer 1 is causing some occasional twitches on my servo and timsk0=0 solves the issue but Im curious if timer 2 will work with this library. Thanks