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!