[if this belongs in programming questions instead -- let me know and i'll move it over]
So as a preface, i'm pretty new to arduino programming and have been trying to solve this problem for a bit. I have two servos set up on an arm with a version of the basic 'sweep' sketch that includes some easing (that i found online). Adding in the 2nd servo as such.. ( my new line for the 2nd servo was: myservo2.write(calangle); )
...has this look by default:
http://dl.dropbox.com/u/1378390/servo1.mov
#include <Servo.h>
Servo myservo;
Servo myservo2;
float timeAngle;
float timeAngleadjust;
float moveAngle;
int oldposition;
float servocon;
float sfactor;
// servo_smoothmove by witpim. 2007
void smoothmove(int cposition) {
int anglediff = abs(cposition-oldposition);
sfactor = servocon/anglediff;
for (timeAngle=0.000; timeAngle<=1;) {
timeAngle = timeAngle+sfactor;
timeAngleadjust = (1.0/2.0) - (1.0/2.0*cos(timeAngle*PI)); //coming from here http://this.is/torfi/robotblog/index.php?getInfo=1&projectID=34
moveAngle = (anglediff*timeAngleadjust);
int calangle;
if (oldposition > cposition) {
calangle = oldposition - (int)moveAngle;
}
if (oldposition < cposition) {
calangle = oldposition + (int)moveAngle ;
}
myservo.write(calangle);
myservo2.write(calangle);
}
oldposition = cposition;
}
void setup() {
Serial.begin(19200);
servocon = 0.01; // servo factor, the higher the faster
myservo.attach(9);
myservo2.attach(10); // attaches a servo connected to pin 2
}
void loop() {
smoothmove(40);
smoothmove(110);
}
Both arms move the same way, at the same time. So, I tried adding a copy of the smoothmove function and alternating the smoothmove calls in the loop like:
void loop() {
smoothmove(40);
smoothmove2(40);
smoothmove(110);
smoothmove2(110);
}
but that has this effect:
http://dl.dropbox.com/u/1378390/servo2.mov
The first servo moves and completes its action, then the 2nd, then back to the first etc. What i'm looking to do is "overlap" the actions so the 2nd servo begins moving about midway through the first's movement, like so:
http://dl.dropbox.com/u/1378390/servo3.mov
Any ideas on how to accomplish this?
Thanks-