Go Down

Topic: Source code to lift body of hexapod (Read 657 times) previous topic - next topic

likhithr_18

I am trying to make an hexapod with arduino mega board . I prefered tripod method of implementation .
I am trying to coordinate 3 legs at a time (ex: (1 ,3 ,5) &( 2,4,6)) .I am facing an issue of unable to lift six legs at a time .As a result i could not able to lift body of hexapod . I am using this source code to make it autonomous.
Code: [Select]

#include<Servo.h>
#define TIBIA 45
#define del   300
#define COXA_CCW 70
#define COXA_CW 105
#define AC_UP 92
#define AC_DOWN 125
int UP=AC_UP;
int angle;
int DOWN=AC_DOWN;
void tri1();
void walkfwd();
void walkbwd();
void turnleft();
void turnright();
void tibia();
Servo A[3],C[3],B[3],D[3],F[3],E[3];// AC and DF are connected together
//AC[0]=AC_tibia, AC[1]=AC_femur, AC[2]=AC_coxa;
void setup()
{
  // put your setup code here, to run once:
  digitalWrite(2, OUTPUT);
  digitalWrite(3, OUTPUT);
  digitalWrite(4, OUTPUT);
  digitalWrite(5, OUTPUT);
  digitalWrite(6, OUTPUT);
  digitalWrite(7, OUTPUT);
  digitalWrite(8, OUTPUT);
  digitalWrite(9, OUTPUT);
  digitalWrite(10, OUTPUT);
  digitalWrite(11, OUTPUT);
  digitalWrite(12, OUTPUT);
  digitalWrite(13, OUTPUT);
   
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);

  A[0].attach(2);
  A[1].attach(3);
  A[2].attach(4);
  C[0].attach(2);
  C[1].attach(3);
  C[2].attach(4);

  B[0].attach(5);
  B[1].attach(6);
  B[2].attach(7);

  D[0].attach(8);
  D[1].attach(9);
  D[2].attach(10);
  F[0].attach(8);
  F[1].attach(9);
  F[2].attach(10);

  E[0].attach(11);
  E[1].attach(12);
  E[2].attach(13);

 

}

void loop()
 {
  // put your main code here, to run repeatedly:
   for(int i=0;i<=2;i++)
   {
    walkfwd();
   }
  for (int j=0; j<=2; j++)
   { 
    walkbwd();
   }
  for (int k=0; k<=2; k++)
   { 
    turnleft(); 
   }
  for (int l=0; l<=2; l++)
   { 
    turnright(); 
   }
 }
 void walkfwd()
 {
  tibia();
  tri1();
  tri2();
  tri3();
  tri4();
  }
  void walkbwd()
  {
  tibia();
  b1();
  b2();
  b3();
  b4(); 
  }
  void turnleft()
  {
  tibia();
  l1();
  l2();
  l3();
  l4();
  }
  void turnright()
  {
   tibia();
   r1();
   r2();
   r3();
   r4();
  }
  void tibia()
  {
  A[0].write(TIBIA);
  C[0].write(TIBIA);
  B[0].write(TIBIA);
  D[0].write(TIBIA);
  F[0].write(TIBIA);
  E[0].write(TIBIA);
  delay(del);
  }
  void tril()
  {
   A[2].write(COXA_CW);
   C[2].write(COXA_CW);
   E[2].write(COXA_CCW);
   D[2].write(COXA_CW);
   F[2].write(COXA_CW);
   B[2].write(COXA_CCW);
   delay(del);
   };
   
   void tri2()
   {
    A[1].write(AC_DOWN);
    C[1].write(AC_DOWN);
    E[1].write(DOWN);
    D[1].write(UP);
    F[1].write(UP);
    B[1].write(UP);
    delay(del);
   };
   void tri3()
   {
   A[2].write(COXA_CCW);
   C[2].write(COXA_CCW);
   E[2].write(COXA_CW);
   D[2].write(COXA_CCW);
   F[2].write(COXA_CCW);
   B[2].write(COXA_CW);
   delay(del);
   };
   void tri4()
   {
    A[1].write(AC_UP);
    C[1].write(AC_UP);
    E[1].write(UP);
    D[1].write(DOWN);
    F[1].write(DOWN);
    B[1].write(DOWN);
    delay(del);
   }
   void b1()
   {
     A[2].write(COXA_CCW);
     C[2].write(COXA_CCW);
     E[2].write(COXA_CW);
     D[2].write(COXA_CCW);
     F[2].write(COXA_CCW);
     B[2].write(COXA_CW);
     delay(del);
    }
    void b2()
    {
    A[1].write(AC_DOWN);
    C[1].write(AC_DOWN);
    E[1].write(DOWN);
    D[1].write(UP);
    F[1].write(UP);
    B[1].write(UP);
    delay(del);
   }
  void b3()
  {
  A[2].write(COXA_CW);
  C[2].write(COXA_CW);
  E[2].write(COXA_CCW);
  D[2].write(COXA_CW);
  F[2].write(COXA_CW);
  B[2].write(COXA_CCW);
  delay(del);
  }
  void b4()
 {
  A[1].write(AC_UP);
  C[1].write(AC_UP);
  E[1].write(UP);
  D[1].write(DOWN);
  F[1].write(DOWN);
  B[1].write(DOWN);
  delay(del);
  };


 void l1()
 {
  A[2].write(COXA_CCW);
  C[2].write(COXA_CCW);
  E[2].write(COXA_CCW);

  D[2].write(COXA_CW);
  F[2].write(COXA_CW);
  B[2].write(COXA_CW);

  delay(del);
 }
void l2()
 {
  A[1].write(DOWN);
  C[1].write(DOWN);
  E[1].write(DOWN);
  D[1].write(UP);
  F[1].write(UP);
  B[1].write(UP);
  delay(del);
 };

 void l3()
 {
  A[2].write(COXA_CW);
  C[2].write(COXA_CW);
  E[2].write(COXA_CW);

  D[2].write(COXA_CCW);
  F[2].write(COXA_CCW);
  B[2].write(COXA_CCW);

  delay(del);
};
 void l4()
 {
  A[1].write(UP);
  C[1].write(UP);
  E[1].write(UP);
  D[1].write(DOWN);
  F[1].write(DOWN);
  B[1].write(DOWN);
  delay(del);
  };
 void r1()
 {
  A[2].write(COXA_CW);
  C[2].write(COXA_CW);
  E[2].write(COXA_CW);

  D[2].write(COXA_CCW);
  B[2].write(COXA_CCW);

  delay(del);
};
void r2() {
  A[1].write(DOWN);
  C[1]. write(DOWN);
  E[1].write(DOWN);

  D[1].write(UP);
  F[1].write(UP);
  B[1].write(UP);

  delay(del);
};

void r3() {
  A[2].write(COXA_CCW);
  C[2].write(COXA_CCW);
  E[2].write(COXA_CCW);
  D[2].write(COXA_CW);
  F[2].write(COXA_CW);
  B[2].write(COXA_CW);
  delay(del);
};
void r4() {
  A[1].write(UP);
  C[1].write(UP);
  E[1].write(UP);

  D[1].write(DOWN);
  F[1].write(DOWN);
  B[1].write(DOWN);

  delay(del);
};

Further I am not using any simulator for this . I would like to know suggestions so that it can help me to lift hexapod and make it autonomous

vinceherman

#1
Dec 22, 2017, 04:13 pm Last Edit: Dec 29, 2017, 02:08 pm by vinceherman
Hmmm...  another post from another new user asked very similar questions using very similar terminology.  Is this a classroom assignment? ;-)

A note on your code - hit CTRL-T. This auto formats the code, making it easier to read.  It also helps you identify mismatched curly brackets.

You ask about being able to make it lift.  Does that mean that you have it running but the servos were not strong enough to lift the weight of the body?

There are a number of factors that could be affecting this.
How much does the entire device weigh?
What model servo are you using?
What are you using for power supply for the servos?
How did you do the servo power wiring?
How long are the leg pieces?
What position do you have the feet in when trying to rise?

For the last one, get down on the floor and do a push-up.  First do it with your hands directly under your shoulders.  How easy is that?
Then do a push-up with your hands nearly as far apart as you can reach.  Can you do it?  I can't.  My shoulder muscles cannot generate enough torque when the lever is that long.

TomGeorge

Hi,
What servos are you using and how are you powering them.

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

PaulS

Quote
I am facing an issue of unable to lift six legs at a time
You want to pick all 6 legs up off the ground at the same time AND have the hexapod not fall on the floor on it's belly. Does that seem reasonable?
The art of getting good answers lies in asking good questions.

Go Up