hi forum
i build quadruped arduino robot from hexapod robot from this link and succeed to modified the code as my needs since my servo position isn't the same relative to the servo bracket as the original project. my quadruped robot legs order is : leg 1 and 2 on the right side of the robot and leg 3 and 4 on the left side, leg 1 and 3 are front leg. all the legs forward movement run as my expectation but they step(run) at the same time. how do i modified my code in for loop to make leg 1 and 4 to step forward and when those legs step down leg 2 and 3 step forward. thank you
this is the code
#include <Servo.h>
Servo s18;
Servo s17;
Servo s16;
Servo sc1; // create servo object to control a servo
Servo sf1;
Servo st1;
Servo sc2;
Servo sf2;
Servo st2;
Servo sc3;
Servo sf3;
Servo st3;
Servo sc4;
Servo sf4;
Servo st4;
int i0H1 = 0;
int i1L1 = 0;
int i2L1 = 0;
int i3L1 = 0;
int i4L1 = 0;
int i5L1 = 0;
int i6L1 = 0;
int i1L2 = 0;
int i2L2 = 0;
int i3L2 = 0;
int i4L2 = 0;
int i5L2 = 0;
int i6L2 = 0;
boolean l1status = LOW;
boolean l2status = LOW;
boolean aStatus = LOW;
boolean attStatus = LOW;
int k = 0;
int a = 0;
int aa = 0;
int period = 1000;
unsigned long time_now = 0;
boolean c = true;
float distance;
long duration;
int dataIn;
int m = 0;
int h = 0;
int t = 0;
int att = 0;
int speedV = 50;
void setup() {
Serial.begin(15200);
sc1.attach(37); //
sf1.attach(38);
st1.attach(39);
sc2.attach(40);
sf2.attach(41);
st2.attach(42);
sc3.attach(33);
sf3.attach(32);
st3.attach(31);
sc4.attach(30);
sf4.attach(29);
st4.attach(28);
sc1.write(70);
sf1.write(90);
st1.write(90);//tibia 1
sc2.write(70);
sf2.write(90);
st2.write(100); // tibia 2
sc3.write(100);
sf3.write(100);
st3.write(90);// tibia 3
sc4.write(100);
sf4.write(100);
st4.write(90);// tibia 4
delay(3000);
delay(4000);
}
void loop() {
Serial.begin(9600);
moveLeg3();
moveLeg2();
moveLeg1();
moveLeg4();
delay(speedV);
}
void moveLeg1() {
//rise the tibia
if (i1L1 <= 10) {
st1.write(90 - i1L1 * 2);
sf1.write(90 - i1L1 * 3);
i1L1++;
}
// rotate coax
if (i2L1 <= 30) {
sc1.write(70 + i2L1);
i2L1++;
}
// step down the tibia
if (i2L1 > 20 & i3L1 <= 10) {
st1.write(70 + i3L1 * 2);
sf1.write(60 + i3L1 * 3);
i3L1++;
}
// totate coax back
if (i2L1 >= 30) {
sc1.write(100 - i4L1);
i4L1++;
l1status = HIGH;
}
if (i4L1 >= 30) {
i1L1 = 0;
i2L1 = 0;
i3L1 = 0;
i4L1 = 0;
i5L1 = 0;
}
}
void moveLeg2() {
// lift tibia
if (i1L1 <= 10) {
st2.write(90 - i1L1 * 2);
sf2.write(90 - i1L1 * 3);
i1L1++;
}
//move coax
if (i2L1 <= 30) {
sc2.write(70 + i2L1);
i2L1++;
}
// step down tibia
if (i2L1 > 20 & i3L1 <= 10) {
st2.write(70 + i3L1 * 2);
sf2.write(60 + i3L1 * 3);
i3L1++;
}
// rotate back the coax
if (i2L1 >= 30) {
sc2.write(100 - i4L1);
i4L1++;
}
if (i4L1 >= 30) {
i1L1 = 0;
i2L1 = 0;
i3L1 = 0;
i4L1 = 0;
i5L1 = 0;
}
}
void moveLeg3() {
if (i1L2 <= 10) {
st3.write(90 + i1L2 * 2);
sf3.write(100 + i1L2 * 3);
i1L2++;
}
if (i2L2 <= 30) {
sc3.write(100 - i2L2);
i2L2++;
}
if (i2L2 > 20 & i3L2 <= 10) {
st3.write(110 - i3L2 * 2);
sf3.write(120 - i3L2 * 3);
i3L2++;
}
if (i2L2 >= 30) {
sc3.write(70 + i4L2);
i4L2++;
l1status = LOW ;
}
if (i4L2 >= 30) {
i1L2 = 0;
i2L2 = 0;
i3L2 = 0;
i4L2 = 0;
i5L2 = 0;
}
}
void moveLeg4() {
if (i1L2 <= 10) {
st4.write(90 + i1L2 * 2);
sf4.write(100 + i1L2 * 3);
i1L2++;
}
if (i2L2 <= 30) {
sc4.write(100 - i2L2);
i2L2++;
}
if (i2L2 > 20 & i3L2 <= 10) {
st4.write(110 - i3L2 * 2);
sf4.write(120 - i3L2 * 3);
i3L2++;
}
if (i2L2 >= 30) {
sc4.write(70 + i4L2);
i4L2++;
}
if (i4L2 >= 30) {
i1L2 = 0;
i2L2 = 0;
i3L2 = 0;
i4L2 = 0;
i5L2 = 0;
}
}
void initialPosition() {
a = 0;
aa = 0;
m = 0;
l1status = LOW;
l2status = LOW;
// Leg 1
st1.write(90);// tbia 1
sf1.write(90);
sc1.write(70);
st2.write(90);// tibia 2
sf2.write(90);
sc2.write(70);
st3.write(90);//tibia 3
sf3.write(100);
sc3.write(100);
st4.write(90);//tibia 4
sf4.write(100);
sc4.write(100);
i1L1 = 0;
i2L1 = 0;
i3L1 = 0;
i4L1 = 0;
i5L1 = 0;
i6L1 = 0;
i1L2 = 0;
i2L2 = 0;
i3L2 = 0;
i4L2 = 0;
i5L2 = 0;
i6L2 = 0;
}