Go Down

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

Korman

May 18, 2011, 08:43 pm Last Edit: May 18, 2011, 09:52 pm by Korman Reason: 1
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

Msquare

Thank you. Saved me reinventing that particular wheel. Well, I already did it, but this is more elegant. To Be Tested   ]:)

robtillaart

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
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Korman

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

Friekje

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

Go Up