So I've been building a twelve servo biped for quite some time, and run into more than a handful of problems. I posted a very similar question, in fact same, asking for help, and I got some, but couldn't focus on the robot and set it aside for upwards of two months. I've come back and hit the same roadblock I had before...
My original question at For-Loop Questions and a Complex Biped - #6 by SilentDemon555 - Programming Questions - Arduino Forum
Okay, I don't know how much help i'll get, but here's hoping...
I have a sketch, and it involves a nested for loop command. Now the trouble is, this is running on my biped, and i cant seem to get it to run right.
Basically this is how it is set up...
For(Leg = 1 ----> Leg = 2){
For(Start Leg Location ------> End Leg Location){
CODE
}
I cant really explain it, i need the first leg to move, then the second AND as the second one is moving bring the first leg back to Start...
I need to be able to modify values of the legs "on-the-fly, and have the legs move, in the words of PeterH, in an asynchronous fashion.
I got some basic ideas, with no idea what to change or where to change it... I'm so lost and have no idea where to start converting this "synchronous movement" into "asynchronous movement"
Once again here's the main part of the FOR-LOOP in the code...
for(leg = 1; leg <= 2; leg++){ // switches the value for leg, Leg = 1, then Leg = 2, Then Leg = 1, etc....
for(x = xmin; x <= xmax; x = x + xstep){ // runs through all values from min to max based on inverse kinematic equations
y = yCenter + sqrt(sq(CirRadius)-sq(x-xCenter)); // calculates the Y variable, also used in IK2
fracdone = (x - xmin) / (xmax-xmin); // the fracdone equation, used in Shift
CheckHypotenuse(); // I dont know why i did this, an oversight perhaps? I just dont really want to modify things yet (it all sorta works)
if(CheckHypotenuse()==0){ // if the angle is too far to reach, stop movement
return;
}
ik2(); // calculates X and Y into Thetas
normalize(); // Corrects for servo error, and puts servos in correct quadrant
if(leg == 1){ // if First Leg, do only this...
servo3pulse = D2Pminus(a1500pulse, theta1);
servo4pulse = D2Pplus(a1500pulse, theta2);
servo5pulse = D2Pminus(a1500pulse, theta3);
shift(leg);
buildmove(3, servo3pulse); //Servo 3 = servo3pulse = theta1
buildmove(4, servo4pulse); //Servo 4 = servo4pulse = theta2
buildmove(5, servo5pulse);
finishmove(500);
delay(500);
}
else{ //If Second Leg, do only this...
servo19pulse = D2Pplus(a1500pulse, theta1);
servo20pulse = D2Pminus(a1500pulse, theta2);
servo21pulse = D2Pplus(a1500pulse, theta3);
shift(leg);
buildmove(19, servo19pulse); //Servo 3 = servo3pulse = theta1
buildmove(20, servo20pulse); //Servo 4 = servo4pulse = theta2
buildmove(21, servo21pulse);
finishmove(500);
delay(500);
}
} //Next x
FirstStep = 1; //Tells the program the initial step has taken place
} //Next leg