Arduino Forum

Using Arduino => Motors, Mechanics, and Power => Topic started by: Korman on May 18, 2011, 08:43 pm

Title: VarSpeedServo - a modified Servo library with speed control
Post by: Korman on May 18, 2011, 08:43 pm
Attached to this message is the library VarSpeedServo, a modified version of the Servo library with one additional function slowmove() which is a replacement of write with an additional speed parameter.

Speed=0: Write is used, full speed
Speed=1: Slowest
Speed=255: Fastest. With the servos I have, with values above 127 I couldn't see any difference to write because the mechanical speed of the servo was the limiting factor.

Everything that works with Servo works with VarSpeedServo too. Important: Don't use Servo.h and VarSpeedServo.h at the same time, it will create conflicts.

Example:
Code: [Select]
#include <VarSpeedServo.h>
VarSpeedServo myServo;
...
myServo.attach (mainPin, ServoMin, ServoMax);
...
myServo.slowmove (newpos, speed);
...


Have fun with it.

Korman
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: 3dprinter on May 18, 2011, 10:20 pm
Thank you. Saved me reinventing that particular wheel. Well, I already did it, but this is more elegant. To Be Tested   ]:)
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: robtillaart on May 18, 2011, 10:55 pm
Very nice addition, good work!

Shouldn't it be just added to the servo lib? 
Or be a derived class from Servo?

Quote
Speed=0: Write is used, full speed
Speed=1: Slowest
Speed=255: Fastest. With the servos I have, with values above 127 I couldn't see any difference to write because the mechanical speed of the servo was the limiting factor.

Would it be more natural to let speed go from 1-100% ? Granularity is not as fine, but maybe fine enough?

just thinking out loud,
Rob
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Korman on May 18, 2011, 11:34 pm
I thought about this, but in the end I didn't find any useful measure for the speed, as the actual movement speed of the servo is unknown.  50% or 1% wouldn't match the reality either, so I just went with one byte speed indicator as compromise between data overhead in the Servo-library, processing overhead in the interrupt function and granularity for the speed regulation. It was good enough for what I needed - lowering model aircraft landing gears in a realistic manner.

Korman
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Friekje on Jun 05, 2011, 09:56 pm
Hi there,

Looks like this library would be the solution to my problem.
So I downloaded the library, installed it and created the following code:
Code: [Select]
#include <VarSpeedServo.h>

VarSpeedServo servo1;
VarSpeedServo servo2;

void setup() {
  servo1.attach(9); 
  servo2.attach(10);

  Serial.begin(19200);
  Serial.println("Ready");
}

void loop() {

  static int v = 0;

  if ( Serial.available()) {
    char ch = Serial.read();

    switch(ch) {
case '0'...'9':
  v = v * 10 + ch - '0';
  break;
case 'R':
  servo1.slowmove(v,50);
  v = 0;
  break;
case 'L':
  servo2.write(v);
  v = 0;

  break;
        case 'Z':
          servo1.write(90);
          servo2.write(90);
          break;
       
    }
  }


But it gives the following error when compiling:
Code: [Select]
cameraCodeArduino.cpp.o: In function `__static_initialization_and_destruction_0':
C:\Users\s070099\AppData\Local\Temp\build7343566564887365634.tmp/cameraCodeArduino.cpp:6: undefined reference to `VarSpeedServo::VarSpeedServo()'
C:\Users\s070099\AppData\Local\Temp\build7343566564887365634.tmp/cameraCodeArduino.cpp:7: undefined reference to `VarSpeedServo::VarSpeedServo()'
cameraCodeArduino.cpp.o: In function `loop':
C:\Users\s070099\AppData\Local\Temp\build7343566564887365634.tmp/cameraCodeArduino.cpp:29: undefined reference to `VarSpeedServo::slowmove(int, unsigned char)'
C:\Users\s070099\AppData\Local\Temp\build7343566564887365634.tmp/cameraCodeArduino.cpp:33: undefined reference to `VarSpeedServo::write(int)'
C:\Users\s070099\AppData\Local\Temp\build7343566564887365634.tmp/cameraCodeArduino.cpp:38: undefined reference to `VarSpeedServo::write(int)'
C:\Users\s070099\AppData\Local\Temp\build7343566564887365634.tmp/cameraCodeArduino.cpp:39: undefined reference to `VarSpeedServo::write(int)'
cameraCodeArduino.cpp.o: In function `setup':
C:\Users\s070099\AppData\Local\Temp\build7343566564887365634.tmp/cameraCodeArduino.cpp:10: undefined reference to `VarSpeedServo::attach(int)'
C:\Users\s070099\AppData\Local\Temp\build7343566564887365634.tmp/cameraCodeArduino.cpp:11: undefined reference to `VarSpeedServo::attach(int)'


I have no idea how to solve this, do you have any idea what's going wrong here?

Thanks in advance
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Korman on Jun 05, 2011, 10:10 pm
I would have guessed the including didn't work properly. Did you place the library in the proper directory and import it as described here: http://www.arduino.cc/en/Reference/Libraries

Korman
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Friekje on Jun 05, 2011, 10:15 pm
Hi Korman,

Yes, I have placed it correctly and it shows up in my Arduino, Sketch -> Import Library... -> VarServoSpeed. Imported it from there as well
Using Arduino 0022 btw, on Windows 7 computer.. maybe does that make any difference?
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Friekje on Jun 05, 2011, 10:21 pm
Ah never mind
Typo somewhere. Testing it now and it works fine! Thanks so much!
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: mem on Aug 04, 2011, 05:55 am
I have just come across this, nice job Korman.

Do you think this is a capability I should add to the core Servo library?

BTW, I posted an example sketch using this library here: http://arduino.cc/forum/index.php/topic,68305.msg504226.html#msg504226


Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Korman on Aug 04, 2011, 02:13 pm
Hi Mem,

it's nice to know, that you like it. Whether to add it to the main Servo-library should be considered carefully. From my point of view, you're welcome to add the code or any modification from it. However, please consider a few things first:


In short, it was mostly a quick hack to get landing gears on model aircraft extend and retract at a more more realistic pace. Going by the general feedback, it seems to be of use for some applications. If you think part of my work is useful to be added to the main library, feel free to go ahead.

Korman
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: mem on Aug 04, 2011, 02:28 pm

Hi Mem,

it's nice to know, that you like it. Whether to add it to the main Servo-library should be considered carefully. From my point of view, you're welcome to add the code or any modification from it. However, please consider a few things first:

  • The speed control adds more memory to the servo structure. It's just a few bytes, but in large setup with many servos, you should check if this causes problems

  • The speed parameter doesn't relate to any real time measure. It's just a number and you can set some speeds but others not. For many applications, like moving something at a pleasant speed to look at, this is good enough. If some specific speeds are necessary, the model I used might not offer enough granularity.

  • I didn't really check if the interaction of the position update and attach/detach works in a reasonable manner. What happens if one detaches the servo while on a slow move and then reattaches it?

  • The method-name slowMove is clumsy and not really in line with the rest of the rest of the methods

  • Some proper documentation and samples are also necessary.



In short, it was mostly a quick hack to get landing gears on model aircraft extend and retract at a more more realistic pace. Going by the general feedback, it seems to be of use for some applications. If you think part of my work is useful to be added to the main library, feel free to go ahead.

Korman


Hi Korman,

I agree with all your points. But this thread and the other one I linked below got me thinking about possibly adding a sweep function with user setable speed that I may be able to do using just one more byte of RAM per servo. I would be interested to hear if this is something that would be generally useful and will start a new thread to discuss this if enough people are interested.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Korman on Aug 04, 2011, 02:35 pm
To answer your question: I needed this kind of function, so I wrote the extension. From time to time, questions about moving things slowly come up, mostly for visual reasons. I think having such a function in the servo library would be a good idea if the library doesn't suffer from it.

NB: I added one more point about the speed control to my previous message.

Korman
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: mem on Aug 04, 2011, 02:46 pm
I am interested to know if adding variable speed sweep would be good enough for most applications?  Most of the additional RAM needed in VarSpeedServo is for the target position, but this is not needed if the sweep is between the min and max positions set in the attach method because only the speed and current direction need to be stored and these can be held in a single byte if the max speed is limited to 127.

Would something like that be useful or will most people want the capability to control speed when moving the servo to any given?
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: 3dprinter on Aug 04, 2011, 10:22 pm
Quote
Would something like that be useful or will most people want the capability

I am not "most people", despite my inflated ego :) But as you see from my reply earlier, I would have found that usefull.

My sweep used a millis() timer construct. For me - not a big hassle to program, but I know from many of the threads here, that it will be too much for many people to "do more than one thing" (ie let the sweep progress without disturbing other processing.) As I do not (yet) have any experience in accessing the hardware timers I do not know how much hassle it is to add that in the timer/interrupt code - or if it would limit the max number of servos.

(My sweep code has an advantage that I can do something synchronized with two servos. In an built in function one would need to change the sweep rate for each "ratio".)

The alternative is to let the sweep be "blocking", ie calling servo.write with asweep value will take the time it takes. I would not like a servo.updatesweep() to be called "often" for the sweep to work.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: mem on Aug 04, 2011, 11:17 pm

(My sweep code has an advantage that I can do something synchronized with two servos. In an built in function one would need to change the sweep rate for each "ratio".)


What do you mean by the ratio? Perhaps you can say more about the functionality.

I don't want to hijack this thread so I have created a new thread here: http://arduino.cc/forum/index.php/topic,68474.0.html
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: elrico on Nov 20, 2011, 02:29 pm
Gday all


just a quick question, just recently started with arduino and i am having trouble woth the VarSpeedServo library and slowmove.

Is there anywhere where it has been incorporated with a sweeep sketch to provide sweep at various speeds?

Thanks for the time, I could not find anything anywhere else

Cheers

Rick
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Korman on Nov 21, 2011, 12:23 pm
There might be one, you'd have to check. Here's the test-code I use for this library. It should be fairly simple to extend.

Code: [Select]
/*
ServoFollowPot

This little program controls a servo with a potentiometer.
The button moave the servo from one end to the other, the potentiometer
sets the speed. 0 = full speed, 1 slowest, 255 fastest.
When pressing the button, the led is turned on to exercise it a little.
Every few seconds the current postion of the servos is reported on the
serial line and whenever the button is pressed.

The circuit:
* LED attached from pin 13 to ground: Button led
* Pushbutton attached to pin 2 from GND
* Linear Potentiometer attached to analog pin 2 from GND and +5V acting
  as a voltage splitter. Any value from 10 kOhm to 100 kOhm will work.
* Servo control line attached to pin 12.

* Note: on most Arduinos there is already an LED on the board
attached to pin 13.

*/

#include <VarSpeedServo.h>

const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin =  13; // the number of the LED pin
const int potPin =  16; // the number of the potentiometer pin (Analog 0)
const int mainPin = 12; // Main servo control line
const int ServoMin = 1000; // Minimum pulse width for servos in ms.
const int ServoMax = 2000; // Maximum pulse width for servos in ms.
const int PotiMin = 0; // Minimum value read from potentiometer
const int PotiMax = 1023; // Maximum value read from potentiometer
const int ButtonDelay = 100; // Time in ms to press button to activate tuning mode


VarSpeedServo myServo; // Servo

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);     

// initialize the pot and button pin as an input:
pinMode(potPin, INPUT);
pinMode(buttonPin, INPUT);

// Activate internal pull up resistor for tuning button
digitalWrite(buttonPin, HIGH);

// Initialise Servos
myServo.attach (mainPin, ServoMin, ServoMax);

// Initialise Serial communication
Serial.begin (9600);
}

void loop() {
static unsigned long debounce = 0;         // variable for reading the pushbutton status
static int buttonstate = HIGH;         // variable for reading the pushbutton status
static unsigned long lasttick;

// Report position;
if (millis () - lasttick > 5000) {
lasttick = millis ();
Serial.print ("Position=");
Serial.println (myServo.readMicroseconds());
}

// Read button and debounce.
int buttonnow = digitalRead(buttonPin);
if (millis() - debounce >= ButtonDelay
&& buttonnow != buttonstate) {
buttonstate = buttonnow;
debounce = millis();
switch (buttonstate) {
case LOW:
// Button has just been pressed
digitalWrite(ledPin, HIGH);

// Set the servos
{
int potlast = analogRead (potPin); // Read potentiometer
int speed = map (potlast, PotiMin, PotiMax, 1, 256) & 0xff;
myServo.slowmove ((myServo.readMicroseconds() > ServoMin + 400
? ServoMin + 100 : ServoMax - 100), speed);
// Report pot position
Serial.print ("Speed=");
Serial.println (speed);
}

break;
case HIGH:
// Button has just been released
digitalWrite(ledPin, LOW);
break;
}
}

// Slow down
// delay (50);
}


Korman
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: terryking228 on Nov 21, 2011, 12:24 pm
Hi, Great work on this!

Question: would this work as acceleration control on continuous-rotation servos?? Newpos sets top speed, speed sets acceleration?

Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Korman on Nov 21, 2011, 04:16 pm

Question: would this work as acceleration control on continuous-rotation servos?? Newpos sets top speed, speed sets acceleration?


Terry, it well could be, but to be honest I don't know. The library just increases continuously the position of the target until the set target value is reached. The consequence is that the PWM pulse increases or decreases in length over time. If the speed on continuous rotation servos is the same as the position for  a regular servo, the speed parameter would be the acceleration.

Perhaps someone with access to such a servo could try that out?

Korman
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: terryking228 on Nov 21, 2011, 04:28 pm
Hi Korman,

I have a small 2-wheel robot that I will try it on.  Maybe be a day+ as I'm busy with The Work Thing..

If it's dynamically changing the POS value, that should work. Within a reasonable range, Continuous-Rotation servos speed is proportional to the POS offset from 90 in both directions...

Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Korman on Nov 22, 2011, 02:58 pm
Thanks Terry, that'll be interesting to know. If I understand it right, if you use slowmove with different speed parameters but the same position for each wheel, the robot should accelerate in a spiral.

Korman
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: terryking228 on Nov 22, 2011, 04:13 pm
Quote
the robot should accelerate in a spiral.


Cool! Gotta try that....
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Stimps on Nov 24, 2011, 02:07 pm
Hi Korman, great work!
Im going to give it a go over thru my ECU code.
one advantage I love is the easy way I can slowly raise the speed the motor for my gas turbine starter.
One question I have as you seem the guru in all things servoish....

what happens in situations when there is alot of other code processing going on, and the servo gets "noisy".
I used a simple for command to slowly raise the servo output.
to test it, I plug in a standard hobby servo, but my intended use is for a brushless motor controller.
I have a project that has an interupt watching a input, measuring RPM.
also a large LCD display and several other things going on, temperature measurment, button menu inputs, etc etc goes on and on (using a Mega 2560 and a 240x320 LCD).
Im using the Servo output to feed a Brushless motor controller input drive to slowly increase the speed of the motor to start a gas turbine.
but the servo output im getting is jittery, noisy. Is this because the processor isnt fast enough to keep up with the PWM pulses the motor requires?
On the oscilliscope, i see alot of "topping off" between the pulses. is there any practices I can apply to my code that will help avoid this?
I stripped away bits of my code untill the LCD touchscreen code was removed before the servo drive got clean, but it was still not perfect.
I did try to break up my code into sections so it always goes back to the servo drive command without too much delay.

What I am guessing, is maybe this is an application where an arduino such as a standalone arduino needs to be setup as a dedicated controller?

keen to hear your thoughts.
cheers.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Korman on Nov 25, 2011, 11:38 am

One question I have as you seem the guru in all things servoish....


Sorry to disappoint you here, we have no guru here. The last thing that made guru-guru ended after a short sting in the oven on the table at thanksgiving.


what happens in situations when there is alot of other code processing going on, and the servo gets "noisy".
I used a simple for command to slowly raise the servo output.


Hi John,

as long as you have just one single interrupt going on the the servo is pretty stable, no matter what you do in your main loop.  To test that out, create a program that leaves the servo in a fixed position and does other processing meanwhile. The servo should only have occasional minimal movements. Check that out with various servo positions, not only the extremes.

In my experience, the servos start to get jittery once you have multiple interrupt functions or you have functions that disable interrupts periodically. Then the pulse length isn't constant in the situations where another interrupt (or cli / sei instructions) are delaying the servo interrupt and thus lengthening the PWM impulse. This can be a hairy problem.

If the rpm-counter is bothering your servo, you might want to look into using your rpm-signal as an external clock reference so that you can use timer2 as a counter. (This is all from memory, I don't have the Atmel datasheet on me at the moment). For very high frequencies, consider adding an external counter chip you then can read at your leisure. As usual, the problem lies in the details.

When I'm back at home, I will have a closer look at the matter.

Korman
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: maninn on Nov 27, 2011, 06:50 pm
Hello, I was trying to make the servo go back and fourth 180 degrees with speed at 1 but it doesn't work, it just goes to one direction and is stuck there, what is wrong in the code?

Code: [Select]
#include <VarSpeedServo.h>

// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.




int pos = 0;    // variable to store the servo position
VarSpeedServo myServo;
void setup()
{
myServo.attach (9);
}


void loop()
{
  for(pos = 0; pos < 180; pos += 180)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
  myServo.slowmove (pos,1);             // tell servo to go to position in variable 'pos'
   
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=180)     // goes from 180 degrees to 0 degrees
  {                               
    myServo.slowmove (pos,1);
 
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: wildbill on Nov 27, 2011, 08:15 pm
Looks like you're not giving the servo enough time to reach 180 at the slow pace before you order it back. Put a substantial delay between the two for loops. Why you're using those loops at all given the 180 degree increments is a bit of a mystery too.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: LuckyWolf19 on Mar 22, 2012, 02:05 am
I just installed the library and referenced it. Upon build I get the following compile error. I use the latest Arduino 1.0 compiler running on Windows 2008 server with Arduino MEGA2560. Any thoughts?

Code: [Select]

C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:56:23: error: WProgram.h: No such file or directory
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In function 'void handle_interrupts(timer16_Sequence_t, volatile uint16_t*, volatile uint16_t*)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'LOW' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'digitalWrite' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'HIGH' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'digitalWrite' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:126: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: At global scope:
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:266: error: 'boolean' does not name a type
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In constructor 'VarSpeedServo::VarSpeedServo()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:283: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'uint8_t VarSpeedServo::attach(int, int, int)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'OUTPUT' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'pinMode' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:304: error: 'isTimerActive' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::detach()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:315: error: 'isTimerActive' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::write(int)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:326: error: 'map' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::writeMicroseconds(int)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: 'byte' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: expected `;' before 'channel'
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:335: error: 'channel' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:343: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::slowmove(int, uint8_t)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:377: error: 'map' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: 'byte' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: expected `;' before 'channel'
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:381: error: 'channel' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:388: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::read()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:407: error: 'map' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::readMicroseconds()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:414: error: 'clockCyclesPerMicrosecond' was not declared in this scope
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: dxw00d on Mar 22, 2012, 08:55 am
Yes. That library has not been updated for IDE 1.0. Read the IDE release notes for the solution.

http://arduino.cc/en/Main/ReleaseNotes
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Korman on Mar 22, 2012, 03:06 pm
Thanks for the pointer. I'll produce an updated version in a few days.

Korman
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: E40racer on Mar 22, 2012, 09:40 pm
I've used the varspeedservo library in Arduino 1.0. I just changed WProgram.h to Arduino.h in one of the library files.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: hangtime21 on Nov 24, 2012, 07:05 pm

I just installed the library and referenced it. Upon build I get the following compile error. I use the latest Arduino 1.0 compiler running on Windows 2008 server with Arduino MEGA2560. Any thoughts?

Code: [Select]

C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:56:23: error: WProgram.h: No such file or directory
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In function 'void handle_interrupts(timer16_Sequence_t, volatile uint16_t*, volatile uint16_t*)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'LOW' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'digitalWrite' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'HIGH' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'digitalWrite' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:126: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: At global scope:
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:266: error: 'boolean' does not name a type
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In constructor 'VarSpeedServo::VarSpeedServo()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:283: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'uint8_t VarSpeedServo::attach(int, int, int)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'OUTPUT' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'pinMode' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:304: error: 'isTimerActive' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::detach()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:315: error: 'isTimerActive' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::write(int)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:326: error: 'map' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::writeMicroseconds(int)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: 'byte' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: expected `;' before 'channel'
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:335: error: 'channel' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:343: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::slowmove(int, uint8_t)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:377: error: 'map' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: 'byte' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: expected `;' before 'channel'
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:381: error: 'channel' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:388: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::read()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:407: error: 'map' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::readMicroseconds()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:414: error: 'clockCyclesPerMicrosecond' was not declared in this scope



gives me the same error. Using 1.0.1 and installed it in right directory

*edit: replaced WProgram.h in the varspeedservo.cpp to Arduino.h
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: w5jdx on Dec 30, 2012, 07:16 pm
I had the same problem with a Uno rev.3. Same solution. In VarSpeedServo.cpp, replace  #include <WProgram.h>  with  #include <Arduino.h> .
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: timcki on May 06, 2013, 03:51 am

I've used the varspeedservo library in Arduino 1.0. I just changed WProgram.h to Arduino.h in one of the library files.


Thank you... I forgot about this little trick to get the libraries going with the 1.0+ IDE
I was beating my head for an hour,wondering what I am doing wrong,  before I read your post.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: theassassinpig on May 06, 2013, 05:33 am
I am builduing a quadcopter with my arduino uno and using a bluetooth setup.  I just need help with this speed control.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: timcki on May 10, 2013, 05:17 am
I seem to notice getting full range out of the servo seems tricky..
Maybe it is my hobby people servos but unless I put:


servo1.attach(5,555,180); this is the only way I can get 180 degrees.
but the speeds work fine.

I am trying to make a pan and tilt camera for on top of a rover.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: eintsius on Jun 18, 2013, 12:07 am
Hello!

I tried to apply also VarSpeedServo lib, but for some reason my code doesnt work. Whats wrong w/ it? DonĀ“t mind the estonian comments between :).

Code: [Select]
#include <VarSpeedServo.h>
int BlueLed = 13;
VarSpeedServo servo1;  //Create a servo object

void setup() {
     // put your setup code here, to run once:
  servo1.attach(4); //Lisab servo PIN 1 servo objektile
   //configure pin2 as an input and enable the internal pull-up resistor
  pinMode(2, INPUT_PULLUP);
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop() {
   int speed = 10;
   int angle = 45;
   int angle2 = 0;
   int speed2 = 30;
   int sensorVal = digitalRead(2);
   //valjastab miskile registrile sensorVal sisu
   Serial.println(sensorVal);
   switch (sensorVal) {
     case LOW:
       servo1.slowmove(angle2, speed2);
       break;
     case HIGH:
       servo1.slowmove (angle, speed);
       break;
     }




Tnx in advance!
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: timcki on Jun 18, 2013, 06:03 am
not exactly sure, but where you have your servo1.attach (4);

your are going to need something like : servo1.attach (4, 0, 180);

4 is the pin you are attaching to
0 is the minimum rotation
180 is the maximum rotation

If  your problem is that you cannot get it to compile read earlier in this thread about
editing varspeedservo.cpp

replace WProgram.h in the varspeedservo.cpp to Arduino.h
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: eintsius on Jun 19, 2013, 11:06 am
Hi,

I replaced the attach with 0-180 degree limit and also overwrote inside VarSpeedServo.cpp lib include "WProgram.h" with "Arduino.h". But it still gives me errors. The error list is as follows:

Code: [Select]






C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In function 'void handle_interrupts(timer16_Sequence_t, volatile uint16_t*, volatile uint16_t*)':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'LOW' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'digitalWrite' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'HIGH' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'digitalWrite' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:126: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: At global scope:
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:266: error: 'boolean' does not name a type
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In constructor 'VarSpeedServo::VarSpeedServo()':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:283: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'uint8_t VarSpeedServo::attach(int, int, int)':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'OUTPUT' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'pinMode' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:304: error: 'isTimerActive' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::detach()':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:315: error: 'isTimerActive' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::write(int)':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:326: error: 'map' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::writeMicroseconds(int)':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: 'byte' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: expected `;' before 'channel'
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:335: error: 'channel' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:343: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::slowmove(int, uint8_t)':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:377: error: 'map' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: 'byte' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: expected `;' before 'channel'
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:381: error: 'channel' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:388: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::read()':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:407: error: 'map' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::readMicroseconds()':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:414: error: 'clockCyclesPerMicrosecond' was not declared in this scope



Code: [Select]
#include <VarSpeedServo.h>
int BlueLed = 13;
VarSpeedServo servo1;  //Create a servo object

void setup() {
     // put your setup code here, to run once:
  servo1.attach(4, 0, 180); //Lisab servo PIN 1 servo objektile
   //configure pin2 as an input and enable the internal pull-up resistor
  pinMode(2, INPUT_PULLUP);
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop() {
   int speed = 10;
   int angle = 45;
   int angle2 = 0;
   int speed2 = 30;
   int sensorVal = digitalRead(2);
   //valjastab miskile registrile sensorVal sisu
   Serial.println(sensorVal);
   switch (sensorVal) {
     case LOW:
       servo1.slowmove(angle2, speed2);
       break;
     case HIGH:
       servo1.slowmove (angle, speed);
       break;
     }


   
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: timcki on Jun 19, 2013, 06:43 pm
What ide are you using??
Download the latest and try again...
I am using 1.0.5 and it compiles on mine just fine.
Did you install the library correctly?
Did you point your IDE to look in the the correct directory?

Sorry I do not have an extra arduino to run the code right now
but like I said  it compiles....
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: eintsius on Jun 20, 2013, 11:47 am
Hi,

Tnx Timcki! Got it running. The library, when taken from downloaded unpacked folder was copied to inside multiple same-named folders. I removed the intermittent useless folders and now it compiles nicley!

:)

Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: timcki on Jun 20, 2013, 05:00 pm
Glad to hear it!!
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: sanok on Sep 13, 2013, 08:28 am
Hi everyone
I'm totally new to robotics and would like to know how to use VarSpeedServo when using Wire library, as my servos will be connected to servo control board.
Below is a simple sketch, can someone add to this sketch the varspeedservo example so I can use it as a template please?

Thanks for any help

#include <Wire.h>

#define ADDRESS 0x61                   // The address of the SD21
#define SERVO 0x43        
void setup(){
 Wire.begin();
}

void loop(){
 Wire.beginTransmission(ADDRESS);
   Wire.write(SERVO);
   Wire.write(255);
   Wire.endTransmission();
 delay(1000);
 
}
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: deadmoonrising on Oct 02, 2013, 05:13 am
Hi, i'm new to the Arduino world and need some help understanding this library. i've the done the LED and Servo examples that come standard with the software. My project involves controlling 2 servos with a PS2 controller. i got it working using a modified version of Bill Porter's example sketch that came with his library. but now i'd like to control the speed of the servos. i'm very new to this and wondered if anyone can help me and explain how to use the VarSpeedServo library in layman's terms.

Here's what i have so far, but i get a lot of errors:
Code: [Select]
#include <VarSpeedServo.h>

#include <PS2X_lib.h>  //for v1.6


PS2X ps2x; // create PS2 Controller Class

//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you conect the controller,
//or call config_gamepad(pins) again after connecting the controller.
int error = 0;
byte type = 0;
byte vibrate = 0;
int LX;
int LY;
VarSpeedServo myservo;  // create servo object to control a servo
VarSpeedServo myservo2;

void setup(){
Serial.begin(57600);

//CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************
 
error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error

{
  myservo.attach(5,0,180);  // attaches the servo on pin 9 to the servo object
  myservo2.attach(6,0,180);
   
}

if(error == 0){
   Serial.println("Found Controller, configured successful");
   Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
  Serial.println("holding L1 or R1 will print out the analog stick values.");
  Serial.println("Go to www.billporter.info for updates and to report bugs.");
}
   
  else if(error == 1)
   Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");
   
  else if(error == 2)
   Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");
   
  else if(error == 3)
   Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
   
   //Serial.print(ps2x.Analog(1), HEX);
   
   type = ps2x.readType();
     switch(type) {
       case 0:
        Serial.println("Unknown Controller type");
       break;
       case 1:
        Serial.println("DualShock Controller Found");
       break;
       case 2:
         Serial.println("GuitarHero Controller Found");
       break;
     }
 
}

void loop(){
   /* You must Read Gamepad to get new values
   Read GamePad and set vibration values
   ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255)
   if you don't enable the rumble, use ps2x.read_gamepad(); with no values
   
   you should call this at least once a second
   */
   
   
   
if(error == 1) //skip loop if no controller found
  return;
 
if(type == 2){ //Guitar Hero Controller
   
   ps2x.read_gamepad();          //read controller
   
   if(ps2x.ButtonPressed(GREEN_FRET))
     Serial.println("Green Fret Pressed");
   if(ps2x.ButtonPressed(RED_FRET))
     Serial.println("Red Fret Pressed");
   if(ps2x.ButtonPressed(YELLOW_FRET))
     Serial.println("Yellow Fret Pressed");
   if(ps2x.ButtonPressed(BLUE_FRET))
     Serial.println("Blue Fret Pressed");
   if(ps2x.ButtonPressed(ORANGE_FRET))
     Serial.println("Orange Fret Pressed");
     

    if(ps2x.ButtonPressed(STAR_POWER))
     Serial.println("Star Power Command");
   
    if(ps2x.Button(UP_STRUM))          //will be TRUE as long as button is pressed
     Serial.println("Up Strum");
    if(ps2x.Button(DOWN_STRUM))
     Serial.println("DOWN Strum");
 

    if(ps2x.Button(PSB_START))                   //will be TRUE as long as button is pressed
         Serial.println("Start is being held");
    if(ps2x.Button(PSB_SELECT))
         Serial.println("Select is being held");

   
    if(ps2x.Button(ORANGE_FRET)) // print stick value IF TRUE
    {
        Serial.print("Wammy Bar Position:");
        Serial.println(ps2x.Analog(WHAMMY_BAR), DEC);
    }
}

else { //DualShock Controller
 
    ps2x.read_gamepad(false, vibrate);          //read controller and set large motor to spin at 'vibrate' speed
   
     if(ps2x.Button(PSS_LY))
   
     LY = ps2x.Button(PSS_LY);
     {
     LY = map(ps2x.Analog(PSS_LY),  0, 255, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
     myservo.slowmove(LY,0);
     delay(15);                           // waits for the servo to get there
     }
     
     if(ps2x.Button(PSS_LX))
     LX = ps2x.Button(PSS_LX);          // reads the value of the potentiometer (value between 0 and 1023)
     {
     LX = map(ps2x.Analog(PSS_LX),  0, 255, 0, 180);    // scale it to use it with the servo (value between 0 and 180)
     myservo2.slowmove(LX,0);
     delay(15);
     }   
         
     
   
}


delay(50);
     
}
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: drewdavis on Oct 03, 2013, 03:20 am
Quote
i get a lot of errors

Sadly, no members of the Arduino forum that I know are trained in Telepathy so unless you post what the errors are we really can't be of much help  :D

Your code complied fine on my computer (I have the library's installed). My guess, would be that you installed one of your library's  wrong or you need to update them to make them compatible with the new version of Arduino IDE (assuming your running it).
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: deadmoonrising on Oct 03, 2013, 11:36 pm
my bad. here's the errors i get. ill try to reinstall the library.

Code: [Select]

ps2x_varspeed_test:16: error: 'Servo' does not name a type
ps2x_varspeed_test:17: error: 'Servo' does not name a type
ps2x_varspeed_test.ino: In function 'void setup()':
ps2x_varspeed_test:27: error: 'myservo' was not declared in this scope
ps2x_varspeed_test:28: error: 'myservo2' was not declared in this scope
ps2x_varspeed_test.ino: In function 'void loop()':
ps2x_varspeed_test:126: error: 'myservo' was not declared in this scope
ps2x_varspeed_test:134: error: 'myservo2' was not declared in this scope
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Zilch on Nov 28, 2013, 08:07 pm
Hi there, first of all - thanks for this great lib.
it is working nicely in my project.

i controll 3 servos to adjust 3 pots of an amp with an arduino nano.
the only issue i am having (same as with the original servo lib) is that attaching a servo causes it to go to middle position with full speed.
i really cant have that ;) the servos have to stay in the position they where when switched off.
otherwise the movement is too fast for the pots and could do some damage.

so is there a way to prevent that middle position when attaching a servo or at least do it in slow speed ?
i am really new to all this... so,
any help appreciated.

cheers


-------> EDIT:
kinda solved it, when i figured only writeMicroseconds can override the middle position after attach,
slowmove cant and write probably cant too...
so i can store the position of the servos after each move to eeprom and write it back in void setup before attaching the servos.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Nicolas1980 on Aug 28, 2014, 10:58 am
Sketches with the library compile under Arduino UNO, but won't as Arduino DUE...
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: 3dprinter on Aug 28, 2014, 09:34 pm

kinda solved it, when i figured only writeMicroseconds can override the middle position after attach,
slowmove cant and write probably cant too...
so i can store the position of the servos after each move to eeprom and write it back in void setup before attaching the servos.
That would have been my suggestion, too. Note that the eeprom is not infinitly rewritable ("The EEPROM has an endurance of at least 100,000 write/erase cycles" in the spec), so add in a some "filtering" so you only store when there has been a great enough move from previous stored value if you do this many times a second. (one million seconds is 11+ days)
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: aeddleston on Feb 13, 2015, 01:39 am
hi trying to use this code to move a servo with a remote control, an i want the speed to be slower, can you see any problems please,



#include <Servo.h>

#include <IRremote.h>
#include <VarSpeedServo.h>


unsigned long Value2 = 0xFFE01F; // where XXXXXXXX is on our your remote's values. We will call this Value 1
unsigned long Value1 = 0xFF609F; // where XXXXXXXX is another button on your remote

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
 
 VarSpeedServo myServo;

// the setup routine runs once when you press reset:
void setup() {             

Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver

  // initialize the digital pin as an output.

myServo.attach (10, 1, 179); // attack servo to digital pin 10 min 1 max 180
}
// the loop routine runs over and over again forever:
void loop() {

if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }

if(results.value == Value1) {
myServo.slowmove (180, 30);  //pos 180 speed 30
}

if(results.value == Value2) {
myServo.slowmove (1, 40);
}

}


  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"
In file included from servoIRmove.ino:4:
C:\Program Files\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:96: error: conflicting declaration '_timer1'
C:\Program Files\Arduino\libraries\Servo/Servo.h:83: error: '_timer1' has a previous declaration as 'timer16_Sequence_t _timer1'
C:\Program Files\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:96: error: conflicting declaration '_Nbr_16timers'
C:\Program Files\Arduino\libraries\Servo/Servo.h:83: error: '_Nbr_16timers' has a previous declaration as 'timer16_Sequence_t _Nbr_16timers'
C:\Program Files\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:96: error: conflicting declaration 'typedef enum timer16_Sequence_t timer16_Sequence_t'
C:\Program Files\Arduino\libraries\Servo/Servo.h:83: error: 'timer16_Sequence_t' has a previous declaration as 'typedef enum timer16_Sequence_t timer16_Sequence_t'
C:\Program Files\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:114: error: conflicting declaration 'typedef struct ServoPin_t ServoPin_t'
C:\Program Files\Arduino\libraries\Servo/Servo.h:101: error: 'ServoPin_t' has a previous declaration as 'typedef struct ServoPin_t ServoPin_t'
C:\Program Files\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:121: error: conflicting declaration 'typedef struct servo_t servo_t'
C:\Program Files\Arduino\libraries\Servo/Servo.h:106: error: 'servo_t' has a previous declaration as 'typedef struct servo_t servo_t'
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: proto-pic on Feb 24, 2015, 03:12 pm
DON'T include Servo.h - It causes this issue.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: frodo1986 on Apr 29, 2015, 05:56 am
Thank you for building this lib file.

When I compile the file, this massage occur:

D:\arduino-1.5.2\libraries\VarSpeedServoMaster\VarSpeedServo.cpp:71: fatal error: avr/interrupt.h: No such file or directory

But the interrupt.h is in the "D:\arduino-1.5.2\hardware\tools\avr\avr\include\avr" , is there any advise?
Thank you
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Sauarabh_garg on May 22, 2015, 01:20 pm
Hello Korman ,

Nice job first off all :) !

Can you tell me what will happen if we use false as third parameter in write function, and then without much delay will overwrite something else on the same servo pin of arduino, will the first one will complete before start of second or will skip that and start second ??

Thanking you in anticipation
 
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: piratebrine on May 24, 2015, 04:31 am
This is useful.   
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Isaac96 on May 24, 2015, 06:00 am
This is cool and versatile.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: XiLinX on Jul 05, 2015, 07:54 am
Is there a way that I can use <virtualwire.h> and <varspeedservo.h> libraries simultaneously as both use timer1

Currently I use <servotimer2.h> library but it has no speed control

Is there any <varspeedservo.h> library which use timer2

Thanks
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: JimboZA on Jul 05, 2015, 08:55 am
Just so I don't end up with an out-of-date version, is that one attached to the opening post, still current? Or did I miss a newer one attached somewhere in the 4 pages of posts? Or maybe there's an update on github or somewhere?
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Drivervince on Sep 03, 2015, 01:15 pm
 Hi all,
New person to the Arduino and software here.

I noticed the command has a function to let the servo finish to the end, before continueing.
I cannot find what the feedback is to the 'Finished servo'.

will the function continue reading the remainder of the loop or will the next item interfere?

Having some trouble understanding the inner functional working.
annybody can shine a light on this?


as background, after one run, i need to wait a moment, before the next run.
so i need the servo feedback, as the speed of the servo may vary (and thus the time it takes).

regards,
Vincent
 :smiley-mr-green:
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: zoomkat on Sep 04, 2015, 06:26 am
Quote
so i need the servo feedback,
What servo are you using that provides feedback?
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Drivervince on Sep 04, 2015, 02:08 pm
not from the servo.

 :smiley-confuse:
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: alexandre_cootep on Sep 20, 2015, 04:06 am
Hi, I'm trying to run this code with the VarSpeedServo.h:

Code: [Select]

#include <VarSpeedServo.h>

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

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

void loop() {
  myservo.write(180, 30, true);        // move to 180 degrees, use a speed of 30, wait until move is complete
  myservo.write(0, 30, true);        // move to 0 degrees, use a speed of 30, wait until move is complete
}




===>but is giving the following error:

Arduino: 1.6.5 (Windows 7), Placa:"Arduino/Genuino Uno"

sketch_sep19g.ino: In function 'void loop()':
sketch_sep19g:10: error: no matching function for call to 'VarSpeedServo::write(int, int, bool)'
sketch_sep19g.ino:10:30: note: candidate is:
In file included from sketch_sep19g.ino:1:0:
C:\Users\usuario\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\usuario\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:130:8: note:   candidate expects 1 argument, 3 provided
sketch_sep19g:11: error: no matching function for call to 'VarSpeedServo::write(int, int, bool)'
sketch_sep19g.ino:11:28: note: candidate is:
In file included from sketch_sep19g.ino:1:0:
C:\Users\usuario\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\usuario\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:130:8: note:   candidate expects 1 argument, 3 provided
Multiple libraries were found for "VarSpeedServo.h"

 Used: C:\Users\usuario\Documents\Arduino\libraries\VarSpeedServo

 Not used: C:\Program Files (x86)\Arduino\libraries\VarSpeedServo

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


====>someone could help me, please!

 
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: TrogX on Oct 24, 2015, 04:54 am
Hello, all.
I'm very happy to have found a servo library that has variable speed. Thank you for posting it, Korman. A funny thing is happening though. The code that would work with Servo.h, where I call functions in sequence, isn't working here. The slow speed is fantastic, but I'm having difficulty sweeping the servos between positions on a loop like I was with the original library. It stops at the first position in the loop, without going further. Any suggestions?
Code: [Select]
#include <VarSpeedServo.h>







VarSpeedServo RR;
VarSpeedServo RL;
VarSpeedServo MR;
VarSpeedServo ML;
VarSpeedServo FR;
VarSpeedServo FL;

//int pos =90;
int fanPin = 1;


void setup(){
  pinMode(fanPin, OUTPUT);
  digitalWrite(fanPin, HIGH);
  RR.attach(5);
  RL.attach(9);
  MR.attach(4);
  ML.attach(10);
  FR.attach(3);
  FL.attach(11);
  RR.slowmove(90,255);
  RL.slowmove(90,255);
  MR.slowmove(90,255);
  ML.slowmove(90,255);
  RR.slowmove(90,255);
  RL.slowmove(90,255);
   }

void loop(){
  RR.slowmove(90,255);
  RL.slowmove(90,255);
  MR.slowmove(90,255);
  ML.slowmove(90,255);
  RR.slowmove(90,255);
  RL.slowmove(90,255);
  delay(150);
  yawRight();
  delay(150);
 // yawLeft();
 
  }

 
 
 void yawRight(){
 
  FR.slowmove (65, 15);
  FL.slowmove (65, 15);
  MR.slowmove (65, 15);
  ML.slowmove (65, 15);
  RR.slowmove (65, 15);
  RL.slowmove (65, 15);
 
 
 }
 void yawLeft(){
  FR.slowmove (115, 15);
  FL.slowmove (115, 15);
  MR.slowmove (115, 15);
  ML.slowmove (115, 15);
  RR.slowmove (115, 15);
  RL.slowmove (115, 15);
  }
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: c0rsa1r on Nov 10, 2015, 09:35 am
Found on GitHub a working SAM (Due) working version of this awesome lib, tested and it work like a charm.

https://github.com/thorikawa/VarSpeedServoSam
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: rrohling on Jan 14, 2016, 11:57 pm
C:\Users\robert\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:56:23: fatal error: WProgram.h: No such file or directory

 #include <WProgram.h>

                       ^

compilation terminated.

Error compiling.

     I keep getting this error message. Any help?
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: rrohling on Jan 15, 2016, 12:25 am
C:\Users\robert\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:56:23: fatal error: WProgram.h: No such file or directory

 #include <WProgram.h>

                       ^

compilation terminated.

Error compiling.

     I keep getting this error message. Can any help? Here's my code.

#include <VarSpeedServo.h>
VarSpeedServo servo;

#define servoControl 6

void setup() {
  servo.attach(servoControl);
}

void loop() {
  servo.slowmove(85, 50);
  delay(1000);
  servo.slowmove(0, 50);
  delay(1000);
}
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: tinkerkid on Jan 15, 2016, 01:24 pm
Quote
C:\Users\robert\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:56:23: fatal error: WProgram.h: No such file or directory
You will need to change WProgram.h to Arduino.h in the .h and .cpp files.
You may need something like notepad ++ or CodeBlocks if you don't have either

https://notepad-plus-plus.org/

good luck!
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: brett100 on Jan 23, 2016, 06:48 pm
Hey everyone...let me first explain I'm very...very new! to all this arduino programming but I have found this page and it's exactly what I need!!....but...I've downloaded it and tried to do a very easy sketch to control a servo from
0 to 90 degrees..
Delay a second
90 to 180 degrees
Delay a second..and then to just continue this sequence.

Every time I try it it comes up with a fault!!

Is the any chance one of you professionals could show me a complete sketch on here as I'm at the end of my patience and am gonna smash this laptop up soon!!

It would be sooooo much appreciated!!

Thanks..
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: callmebob on Apr 09, 2016, 08:51 pm
Programming newbie trying to get VarSpeedServo.h to work with no luck. I'm using IDE 1.6.8

Please enlighten me as to the (hopefully) silly step I'm missing!


I downloaded the zip file attached to the second message here, unzipped it and installed it with the other libraries, and am able to include it from the 'include library' menu.

If I open and compile the standard Sweep sketch, that compiles fine. When using the VarSpeedServo.h library instead of Servo.h I get errors.

I've tried the suggestions I found here: tried changing the WProgram.h to Arduino.h in the .cpp file (it does not exist in my .h file) with no change.

I've tried compiling for different boards with no change.


All I'm doing is deleting the line #include <Servo.h> and inserting #include <VarSpeedServo.h>.

#include <VarSpeedServo.h> gets inserted at the top of the sketch automatically from the Include Library menu -- so I cut it from the top and paste it into the line where #include <Servo.h> was. (Leaving it at the top doesn't make any difference though).


An interesting note: the library manager says 'VarSpeedServo Built In Version unknown INSTALLED' and no other info.

Code: [Select]



/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <VarSpeedServo.h>

Servo 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

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

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





And the error messages...


Code: [Select]
Build options changed, rebuilding all
Sweep:14: error: 'Servo' does not name a type

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

 ^

C:\Users\bob\AppData\Local\Temp\arduino_modified_sketch_373480\Sweep.ino: In function 'void setup()':

Sweep:20: error: 'myservo' was not declared in this scope

   myservo.attach(9);  // attaches the servo on pin 9 to the servo object

   ^

C:\Users\bob\AppData\Local\Temp\arduino_modified_sketch_373480\Sweep.ino: In function 'void loop()':

Sweep:26: error: 'myservo' was not declared in this scope

     myservo.write(pos);              // tell servo to go to position in variable 'pos'

     ^

Sweep:30: error: 'myservo' was not declared in this scope

     myservo.write(pos);              // tell servo to go to position in variable 'pos'

     ^

exit status 1
'Servo' does not name a type

Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: cjones7 on May 08, 2016, 03:23 pm
callmebob, did you get it working?

If not, need to change "Servo myServo" to "VarSpeedServo myServo;"
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: c0rsa1r on May 10, 2016, 08:18 am
callmebob, did you get it working?

If not, need to change "Servo myServo" to "VarSpeedServo myServo;"
That's correct.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Goldenshuttle on May 31, 2016, 12:47 pm
I am getting this error message:
how to solve it ?
i removed Varispeedservo library and reinstalled it. I also restarted to computer..I changed the arduino board...all did not work..please help...

Arduino: 1.6.9 (Windows 7), Board: "Arduino Nano, ATmega328"

WARNING: Category '' in library EEPROM is not valid. Setting to 'Uncategorized'
WARNING: Category '' in library SPI is not valid. Setting to 'Uncategorized'
WARNING: Category '' in library SoftwareSerial is not valid. Setting to 'Uncategorized'
WARNING: Category '' in library Wire is not valid. Setting to 'Uncategorized'
 

Sketch_1:112: error: no matching function for call to 'VarSpeedServo::write(long int&, int, bool)'

 
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Rusconichess on Jun 08, 2016, 09:09 am
Hi Guys

I've a problem

I had a Servo SM-S2309S with them I wanted that, he turn from 0 to 90 to 180 deegres and back. It works, but the Servo didnt reach 180 deegres, so I buyed a Motor with 360 deegrees. But now it doesnt works with the old code and only turns endless and the turn back. What's wrong?
please help the sketch is here

#include <VarSpeedServo.h>
VarSpeedServo servo;
#include <LiquidCrystal.h> // include libary
LiquidCrystal lcd(12,11,5,4,3,2); // connected Pin's with the Lcd
int const Poti= A0;
int potVal = 0;
int analogservo;

int servoSpeeds = 20;
int doublespeed = 40;
int servoneun = 90; // the maximum servo angle
int servosechzig = 160;
int servoposition = 0;



void setup() {
 int const Poti = A0;
pinMode(analogservo,OUTPUT);
  servo.attach(9);       

  servo.slowmove(servoposition,servoSpeeds) ;

}

void loop() {
 
if(servo.read() == servoposition)

 
  {
    servo.slowmove(servoneun,servoSpeeds) ;
    lcd.clear();

lcd.print ("0");
lcd.print(" Grad");
delay(4000);

  }       


  else if(servo.read() == servoposition + 90)

  {
    servo.slowmove(servosechzig,servoSpeeds) ;
    lcd.clear();
    delay(4000);

lcd.print ("160");
lcd.print(" Grad");
delay(4000); 
  }
  else if(servo.read() == servoposition + 160)
  {servo.slowmove(servoneun,doublespeed) ;
  lcd.clear();

lcd.print ("90");
lcd.print(" Grad");
delay(4000);
 
 

  servo.slowmove(servoposition,doublespeed);
 lcd.clear();

lcd.print ("0");
lcd.print(" Grad");
delay(4000);
  }
  else{
   
  }
 
       

 
}
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: SgtDroid on Jun 18, 2016, 07:54 pm
What is the Limit to the Number of Servos i can control ?? The documentation says 8, can this be increased ??

I currently need to control 20+ servos, Using an arduino MEGA 2560 R3. (For a Humanoid)
What is my best option if i need speed control for all the servos?

I am willing to modify some code to control more servos if it is possible,
Unless someone has already done it :), Please link.

If such a Servo library is not available which can control more number of servos with SPEED control, i will try to make one and share :) .
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: msl on Sep 14, 2016, 09:53 pm
Can you give more specific documentation...?
I don't understand this sentence at all:

        myServo.slowmove (newpos, speed);
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: tarff on Oct 08, 2016, 09:48 am
Hi. I'm fairly new to Arduino's and very new to servo motors. I am trying to get the speed setting to work.

This is the code I have:

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 <= 90; 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 = 90; 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
  }
}


It uploads but then the servo just clicks and doesn't move. I know something is terrible wrong with the code but cannot work it out. Also, I would like the motor to pause when it hits 90 degrees and 0 degree but I'm not sure what the code is for that either.

Any help would be very much appreciated.

Cheers.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: outsider on Oct 08, 2016, 01:27 pm
How are you powering your servo? Not from the Arduino 5V pin, I hope. Have you tried the "Sweep" example from the Servo library?
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: tarff on Oct 09, 2016, 06:39 am
Thanks for your reply. The sweep example works but when I try and add the
Code: [Select]
myservo.slowmove the servo stops working.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: outsider on Oct 09, 2016, 08:47 am
Please post your most recent code.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: tarff on Oct 09, 2016, 09:25 am
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
  }
}
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: pradeepkumar669 on Oct 13, 2016, 08:33 pm
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)
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: MrGlasspoole on Dec 25, 2016, 07:39 pm
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.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: wildbill on Dec 26, 2016, 11:27 am
On attach, the servo moves to it's current position. So do a write before you attach.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: dineshlama on Mar 25, 2017, 03:55 am
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);
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: slipstick on Mar 25, 2017, 09:20 pm
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
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Paulroy2011 on Apr 24, 2017, 06:03 pm
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
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: vinceherman on Apr 24, 2017, 07:19 pm
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.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Ghosti46 on Jun 06, 2017, 12:36 pm
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......
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Bob_McNair on Apr 12, 2018, 07:55 pm
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
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: vinceherman on Apr 12, 2018, 08:30 pm
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 (https://forum.arduino.cc/index.php?topic=223286.0)?

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.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: T_J on Apr 21, 2018, 09:25 am
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!
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: slipstick on Apr 21, 2018, 11:03 am
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:
Code: [Select]

// 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
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: James-IV on Sep 08, 2018, 06:08 pm
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.
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: Killer800 on Oct 25, 2018, 06:08 pm
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 (https://www.servocity.com/d980tw-servo) 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,
Title: Re: VarSpeedServo - a modified Servo library with speed control
Post by: omartos on Oct 26, 2018, 09:00 pm
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