Thank you all for the help. I really do need to learn the millis() function but had little time to work on this project.
I ended up just running through 8 arrays filled with servo positions on a loop.
It doesn't perfectly mimic the gait of a frog for the simple reason that we cant balance due to servo/sensor limitations.
//Pete's Revision, the gait is mirrored.
#include<Servo.h>
Servo // min , max , center? Orientation
LS, // 830 2230 1800 = vert. + = back
LE, // 850 2050 1000 = straight. + = forward
RS, // 850 2200 1100 = vert. + = forward
RE, // 1100 2350 2100 = straight + = back
LH, // 1000 1750
RH, // 1150 1850 + = forward
RK, // 1500 2000 1500 = str + = back
LK; // 1500 2100 2100 = straight + = forward
int integral_span = 20;
double time = 45;
// values for calibration:
double ls = 90, le = 90, rs = 90, re = 90, rh = 90, lh = 90, rk = 90, lk = 90;
int a = 1, b=1;
double
LEa[]={140, 135, 160, 160, 110, 105, 104, 103, 102, 101, 100, 101, 102, 103, 104, 104, 105, 106, 107, 108, 110},
LSa[]={167, 174, 174, 138, 143, 145, 146, 148, 150, 152, 153, 155, 157, 158, 159, 160, 162, 163, 164, 165, 166},
RSa[]={48, 47, 45, 43, 42, 41, 40, 38, 37, 36, 35, 34, 33, 32, 25, 62, 55, 57, 54, 52, 50},
REa[]={103, 102, 102, 101, 101, 100, 100, 100, 100, 100, 101, 101, 100, 95, 85, -10, 45, 70, 90, 107, 104},
LHa[]={77, 78, 80, 81, 83, 84, 85, 87, 88, 89, 90, 91, 92, 94, 95, 97, 99, 100, 102, 74, 75},
LKa[]={75, 78, 80, 83, 86, 89, 92, 94, 97, 100, 101, 104, 107, 110, 114, 117, 121, 129, 132, 69, 72},
RHa[]={64, 63, 61, 58, 55, 52, 50, 48, 46, 80, 78, 77, 75, 74, 72, 71, 70, 69, 68, 67, 66},
RKa[]={120, 116, 113, 110, 106, 99, 93, 90, 89, 148, 148, 145, 142, 140, 137, 134, 132, 131, 129, 126, 123};
void setup()
{
pinMode(13, OUTPUT);
// links pins to servos
LS.attach(2); // Left Shoulder
LE.attach(3); // Left Elbow
RS.attach(4); // Right Shoulder
RE.attach(5); // Right Elbow
LH.attach(6); // Left Hip
LK.attach(7); // Left Knee
RH.attach(8); // Right Hip
RK.attach(9); // Right Knee
//set-up first frame of gait
RE.write(re);
LE.write(le);
RK.write(rk);
LK.write(lk);
RS.write(rs);
LS.write(ls);
RH.write(rh);
LH.write(lh);
}
void loop ()
{
digitalWrite(13,HIGH);
while (a <= integral_span)
{
re=REa[a]+35;
le=LEa[a]-35;
rs=RSa[a]+25;
ls=LSa[a]-42;
rk=RKa[a]+30;
lk=LKa[a]-10;
rh=RHa[a]+15;
lh=LHa[a]+11;
RE.write(re);
LE.write(le);
RK.write(rk);
LK.write(lk);
RS.write(rs);
LS.write(ls);
RH.write(rh);
LH.write(lh);
delay(time);
a++;
}
a=1;
}