I'm building a quad-copter using an accelerometer and gyro. The form looks like this one:
My pitch is controlled by the front and back motors. My roll is controlled by the left and right motors.
I used PID and servo libraries.
Here's my pitch stability code:
double Kp=3.15, Ki=4.3, Kd=0.6;
int throttle = 1000;
PID PitchPID(&PitchInput, &PitchOutput, &PitchSetpoint, Kp, Ki, Kd, DIRECT);
PitchPID.SetMode(AUTOMATIC);
backESC.attach(3);
frontESC.attach(5);
// arme the motors
backESC.writeMicroseconds(2000);
frontESC.writeMicroseconds(2000);
delay(5000);
backESC.writeMicroseconds(700);
frontESC.writeMicroseconds(700);
delay(2000);
void loop{
// i have the angle and pitch
int xAngle = GetX();
int Pitch = GetPitch();
PitchInput = (Pitch) ;
PitchSetpoint = 0;
PitchPID.SetOutputLimits(-150,150);
PitchPID.Compute();
backPower = PitchOutput;
frontPower = (PitchOutput*-1);
frontESC.writeMicroseconds(backPower + throttle);
backESC.writeMicroseconds(frontPower + throttle);
}
As you can see, I don't yet have a real algorithm to stabilize the quad. I would be grateful for some help. I have already tried some samples. It didn't go well. Even help without using my PID library would be appreciated.