Pages: [1]   Go Down
Author Topic: Help Programming Quadruped  (Read 2638 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
#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!
« Last Edit: March 27, 2012, 10:18:46 am by extentionex » Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There
Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-roll

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

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8494
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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

Code:
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

http://www.lynxmotion.net/
http://www.societyofrobots.com/robotforum/

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

______
Rob
« Last Edit: April 28, 2012, 07:23:01 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ...  smiley-eek-blue  Man ! expensive !

Quote
Also check out these forums

http://www.lynxmotion.net/
http://www.societyofrobots.com/robotforum/

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


Cool forums. Thanks for the link.

Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8494
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Not Yet. It will be cool.
Logged

Pages: [1]   Go Up
Jump to: