Hi folks,
I am new to electronics and robots. I am new to this forum as well.
I have bought al5d with botboarduino and finaly got it working after 15 days.
I have created a program in arduino which works but after 3 loops robot fall down(I mean stops) and restart itself automatically…
I don’t know what is happening. Please help me with this.
Below is my code : -
[code]#include <Servo.h>
Servo Base;
Servo Shldr;
Servo Elbow;
Servo Wrist;
Servo Gripper;
Servo WristR;
#define BasePin 2
#define ShldrPin 3
#define ElbowPin 4
#define WristPin 11
#define GripperPin 12
#define WristRPin 10
void setup()
{
Base.attach(BasePin);
Shldr.attach(ShldrPin);
Elbow.attach(ElbowPin);
Wrist.attach(WristPin);
Gripper.attach(GripperPin);
WristR.attach(WristRPin);
Serial.begin(9600);
WarmUp();
}
void loop()
{
//picking
MoveServo(Base,Base.read(),45);
MoveServo(Elbow,Elbow.read(),45);
MoveServo(Shldr,Shldr.read(),60);
MoveServo(Elbow,Elbow.read(),85);
MoveServo(Wrist,Wrist.read(),157);
MoveServo(Gripper,Gripper.read(),90);
MoveServo(Wrist,Wrist.read(),90);
MoveServo(Shldr,Shldr.read(),90);
//dropping
MoveServo(Base,Base.read(),135);
MoveServo(Elbow,Elbow.read(),45);
MoveServo(Shldr,Shldr.read(),60);
MoveServo(Elbow,Elbow.read(),85);
MoveServo(Wrist,Wrist.read(),157);
MoveServo(Gripper,Gripper.read(),0);
MoveServo(Wrist,Wrist.read(),90);
MoveServo(Shldr,Shldr.read(),90);
}
void WarmUp()
{
MoveServo(Shldr,90,90);
MoveServo(Elbow,90,90);
MoveServo(Base,90,90);
MoveServo(Wrist,180,180);
MoveServo(Gripper,0,0);
}
void MoveServo(Servo &servo, int startpos, int endpos)
{
if(startpos > endpos)
{
for(int pos = startpos; pos>=endpos; pos-=1)
{
servo.write(pos);
delay(15);
}
}
else if(startpos < endpos)
{
for(int pos = startpos; pos<=endpos; pos+=1)
{
servo.write(pos);
delay(15);
}
}
servo.write(endpos);
}
[/code]