Go Down

Topic: VarSpeedServo - a modified Servo library with speed control (Read 98020 times) previous topic - next topic

tarff

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

outsider


tarff

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

Code: [Select]

#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
  }
}

pradeepkumar669

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)

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.

wildbill

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

dineshlama

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:
Code: [Select]
#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);

slipstick

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

Paulroy2011

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

vinceherman

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.

Ghosti46

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 ;)

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

Go Up