Help Programming Quadruped

Hi, Im new to the forums! But i have owned my Arduino Uno for about 4months now.
I started building a quadruped robot. I
I am using eight micro 9gram Servos. Powered with a 6V 1600mAh Ni-NH battery pack.

My goal for controlling the bot is for now to just get it walking smoothly and efficiently.
Here is what i have right now. It does what I want, but is really not smooth at all and it doesnt allow the robot to walk effectively either.

#include <Servo.h>
Servo servo1A;
Servo servo1B;
Servo servo2A;
Servo servo2B;
Servo servo3A;
Servo servo3B;
Servo servo4A;
Servo servo4B;

int servoTR1 = 0; //Top Right Inner Joint
int servoTR2 = 1; //Top Right Outer Joint
int servoTL1 = 3; //Top Left Inner Joint
int servoTL2 = 5; //Top Left Outer Joint
int servoBL1 = 6; //Bottom Left Inner Joint
int servoBL2 = 9; //Bottom Left Outer Joint
int servoBR1 = 10; //Bottom Right Inner Joint
int servoBR2 =11; //Bottom Right Outer Joint

int i;
int j;


void setup()
{ //Assigning the servos so the correct leg.
  servo1A.attach(servoTR1); 
  servo1B.attach(servoTR2);
  servo2A.attach(servoTL1);
  servo2B.attach(servoTL2);
  servo3A.attach(servoBL1);
  servo3B.attach(servoBL2);
  servo4A.attach(servoBR1);
  servo4B.attach(servoBR2);

}


void loop()
{ 
  for (int i=0; i<=90; i=i+90) //Making the outer joint flex up 90 degrees
  {
    servo1B.write(i);
    delay(300);                //Waiting for just enough time
    for (int j=180; j>=30; j=j-30) //For the inner joint to move forward
  {
    servo1A.write(j);
  }
  }
  for (int j=180; j>30; j=j-30) // and come back just when the 90 degree wait is over
  {                              //I do this motion to all the legs. First the top right then
    servo1A.write(j);             //the leg diagnol to it. and so on..
  }
  for (int i=0; i<=90; i=i+90)
  {
    servo3B.write(i);
    delay(300);
    for (int j=0; j<=30; j=j+30)
  {
    servo3A.write(j);
  }
  }
  for (int j=0; j<30; j=j+30)
  {
    servo3A.write(j);
  }
  for (int i=0; i<=90; i=i+90)
  {
    servo2B.write(i);
    delay(300);
    for (int j=0; j<=30; j=j+30)
  {
    servo2A.write(j);
  }
  }
  for (int j=0; j<30; j=j+30)
  {
    servo2A.write(j);
  }
  for (int i=0; i<=90; i=i+90)
  {
    servo4B.write(i);
    delay(300);
    for (int j=180; j>=30; j=j-30)
  {
    servo4A.write(j);
  }
  }
  for (int j=180; j>30; j=j-30)
  {
    servo4A.write(j);
  }                              //and it keeps on repeating.
}

Please help me out with this one. I feel like im controling the servos the "hard".
Thanks!

When the forum moderator shows up, he always says, "go back to your message and
wrap the code part in `` and then press the modify key".

The correct insertion procedure is to use the '#' key on the forum message editor.

There

I don't know how to help you, but if I was design a 4 legs robot and trying to code it, I will have to figure out : How a 4 leg creature walk ... and trying to simulate the same type of walk. :roll_eyes:

That look like a cool project. I wonder a 6 legs design will be cooler... like a spider - bug !

I wonder a 6 legs design will be cooler

Hexapods are pretty common these days, have a look at these

http://www.lynxmotion.com/c-3-hexapods.aspx

I think they may be easier to drive because you can always have three legs on the ground.

@extentionex
You have to compartmentalise the code, as it is it's too hard to figure out. Write and debug small functions that move a leg in various specific ways and take a leg # as a parameter, then your code will look more readable. eg

loop () {
   liftLeg(1);
   moveLeg(1, BACK);
   lowerLeg(1);

   liftLeg(2);
   moveLeg(2, FORWARD);
   lowerLeg(2);

   liftLeg(3);
   moveLeg(3, BACK);
   lowerLeg(3);

   liftLeg(3);
   moveLeg(4, FORWARD);
   lowerLeg(3);


}

Then remove this and place it in a function call moveForward() or whatever.

On other word try to write and debug small pieces of code at a time then combine them into human-readable sequences. As it is with a 1000 for loops it's just too hard to decipher and therefore debug.

So put the bot on a pedestal with legs off the ground, get one leg working as you think it should and work from there.

Also check out these forums

There are guys there more into robots then the average member here.


Rob

Thanks Graynomad for the links. I will check it out.

BTW check this cool & mean "bug" http://www.lynxmotion.com/p-855-a-pod-combo-kit-for-bot-boardssc-32bap28-and-ps2-controller.aspx... the price is : $1337.00 ... :fearful: Man ! expensive !

Also check out these forums

http://www.lynxmotion.net/
Society of Robots - Robot Forum - Index

There are guys there more into robots then the average member here.

Cool forums. Thanks for the link.

That ant bot is pretty neat, have you seen the videos, very smooth and realistic movement.


Rob

That ant bot is pretty neat, have you seen the videos, very smooth and realistic movement.

Not Yet. It will be cool.

Hello! I am developing a similar bot with the same 8 Servo config.I am trying to figure out a way to make it walk from past couple of days.But, nothing worked . kindly help.