Author Topic: SimpleServo library  (Read 10734 times)

bjh

  • Newbie
  • *
  • Posts: 31
SimpleServo library
« on: February 17, 2013, 10:43:04 pm »
The SoftwareServo library doesn't seem to work with my servos, after some creative investigation, I set about writing my own.  First, big thanks to Eje_G for the bit-bang reference code, which showed me the path to making my actual project workable with the Digispark!  Also, if SoftwareServo works for you, great, it's probably closer to what you want.


I've reached the point that I think SimpleServo might be usable by anyone else, so I spruced it up a bit, banged out a README, and am posting it.  I consider it v0.1: feature set, implementation and documentation are all incomplete and I've done little testing.  When it's ready, I'll put it up on the wiki.



At the moment SimpleServo doesn't even implement servo.write(), instead you have to specify how many milliseconds to send signal to the servo using servo.writeMillis(); I have ideas for alleviating this and a few other limitations, but for now I hope it might help other folks get their servos doing the happy dance.  From (indeed most of) the README:



"Hey, ya hear that?  Me neither… It's simple… Maybe *too* simple…"


This is a simplistic library to bundle up and generalize bit-banging servo PWM.  It has some good points and trade-offs and is primarily being developed for the Digispark.


First the good:
  - It can control any number of servos
  - It's all software, no fancy hardware required
  - It produces a relatively clean signal
  - It allows (or will) tuning pulse parameters to suit the widely varied tastes of different servos
  - A single instance can be used with multiple similar servos


Now some limitations:
  - It can only control one servo at a time
  - The program can't do anything else while the servo is being controlled
  - It doesn't (yet) complete the standard servo library API
  - The caller must specify how long to signal the servo (for now)
  - Documentation is incomplete (at the moment)


Though it might not be a good fit for some projects, it can be very useful, particularly with servos that get confused by imprecise timing that can arise from trying to generate multiple different signals simultaneously.


Also, when typical servos stop receiving a control signal, they stay where they are; while they won't actively hold their position, most require some force to backdrive.  So if that's enough for your project, you can move each servo in turn, and sample inputs, set LEDs and such in between. 


bjh

  • Newbie
  • *
  • Posts: 31
Re: SimpleServo library
« Reply #1 on: February 20, 2013, 10:54:06 pm »
Announcing SimpleServo v0.8!  Feature-complete, but minimally tested and incomplete documentation (i.e. there are comments in the header and code.)


Good ol' servo.write() now works, and you can control as many servos as you want in turn.  Set parameters to tune signaling so you get the most out of the servos your project is using.


Did I mention it is (so far) minimally tested?  Posting early to give folks a chance to try it out, let me know if you have any issues.


Enjoy!
--bjh

MrPaul

  • Newbie
  • *
  • Posts: 1
Re: SimpleServo library
« Reply #2 on: February 23, 2013, 06:30:46 am »
The program works with my servo. Thanks bjh!!!  ;D ;D ;D

bjh

  • Newbie
  • *
  • Posts: 31
Re: SimpleServo library
« Reply #3 on: February 28, 2013, 11:41:13 pm »
Fixed a couple bugs, but mostly I'd like editorial feedback on the documentation I've put together, please send me my dumb mistakes :-)  (don't stop this from telling me any way I need to fix the rest of it too!)
« Last Edit: March 01, 2013, 10:02:31 am by bjh »

amorris

  • Newbie
  • *
  • Posts: 1
Re: SimpleServo library
« Reply #4 on: August 17, 2013, 07:58:00 pm »
Has anyone tried using this library to control continuous rotation servos?  Ultimately I'd like to control a pair of servos that will drive a small bot.  My test code (which worked beautifully using Arduino Uno and #include Servo.h) results in each servo turning a short amount, then stopping, rather than each of them running continuously for two seconds.  I realize that this library cannot control two servos at the same time, but perhaps there's a way to simulate it by driving one then the other, back and forth very quickly or something like that?  Any suggestions?  Here's my test code:


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


SimpleServo servoLeft;          // Define left servo
SimpleServo servoRight;         // Define right servo


void setup() {
  servoLeft.attach(0);  // Set left servo to digital pin 10
  servoRight.attach(1);  // Set right servo to digital pin 9
}
void loop() {            // Loop through motion tests
  forward();             // Example: move forward
  delay(2000);           // Wait 2000 milliseconds (2 seconds)
  reverse();
  delay(2000);
  turnRight();
  delay(2000);
  turnLeft();
  delay(2000);
  stopRobot();
  delay(2000);
}


// Motion routines for forward, reverse, turns, and stop
void forward() {
  servoLeft.write(0);
  servoRight.write(180);
}


void reverse() {
  servoLeft.write(180);
  servoRight.write(0);
}


void turnRight() {
  servoLeft.write(180);
  servoRight.write(180);
}

void turnLeft() {
  servoLeft.write(0);
  servoRight.write(0);
}


void stopRobot() {
  servoLeft.write(90);
  servoRight.write(90);
}

GeekDoc

  • Newbie
  • *
  • Posts: 1
Re: SimpleServo library
« Reply #5 on: September 11, 2013, 08:42:39 am »
I just found this post after trying the SoftwareServo library (which didn't work for me at all), and it works perfectly!  Thanks very much for doing this work and sharing it with the community.