quad copter stability problem

when i try to tuning my quad copter it becomes crazy
i tied two axles and free the other 1 axis is on and the other off
i don’t use rf remote i control it with my pc
any help
here is the code

////////***********Sensor Configuration****************////

#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
MPU6050 mpu;
#define OUTPUT_READABLE_YAWPITCHROLL
// MPU control/status vars
bool dmpReady = false;  // set true if DMP init was successful
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer
Quaternion q;           // [w, x, y, z]         quaternion container
VectorInt16 aa;         // [x, y, z]            accel sensor measurements
VectorInt16 aaReal;     // [x, y, z]            gravity-free accel sensor measurements
VectorInt16 aaWorld;    // [x, y, z]            world-frame accel sensor measurements
VectorFloat gravity;    // [x, y, z]            gravity vector
float euler[3];         // [psi, theta, phi]    Euler angle container
float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector
volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high
void dmpDataReady() {
    mpuInterrupt = true;
}

////**************************END Sensor Configuration*************************/////

///***************************My Configuration***************************///////////

int Angle[2]={0,0};
int v_x=130 ;
float Kp=0.001 ;
unsigned long dt=0;
int Error=0, Des_angle=0,lastError=0;
float I=0,Kd=0,Ki=0;
float D=0;
unsigned long Now ,lastTime;
int a , b;
char button;
int dd=0;
long instI=0;
//////with glue  Pin 9
/////the other pin 10


void setup() {
   
 
  /**************************Sensor Setup*********************************///
  
  
  #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
        TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif
    Serial.begin(9600);
    while (!Serial); // wait for Leonardo enumeration, others continue immediately
    Serial.println(F("Initializing QuadCopter Devices..."));
    mpu.initialize();
    Serial.println(F("Testing devices connections..."));
    Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
    Serial.println(F("Initializing DMP..."));
    devStatus = mpu.dmpInitialize();
    mpu.setXGyroOffset(220);
    mpu.setYGyroOffset(76);
    mpu.setZGyroOffset(-85);
    mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
    if (devStatus == 0) {
        Serial.println(F("Enabling DMP..."));
        mpu.setDMPEnabled(true);
        Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
        attachInterrupt(0, dmpDataReady, RISING);
        mpuIntStatus = mpu.getIntStatus();
        Serial.println(F("DMP ready! Waiting for first interrupt..."));
        dmpReady = true;
        packetSize = mpu.dmpGetFIFOPacketSize();
    } else {
        Serial.print(F("DMP Initialization failed (code "));
        Serial.print(devStatus);
        Serial.println(F(")"));
    }
    
  ///////**************************End Sensor Setup****************************/////////

  ///*********************************************My Setup*****************************//////////
  
  
  ///initiate motors pins
  DDRB|=1<<1;
  DDRB|=1<<2;
  
  
     //initiate Timer2

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 250.000 kHz
// Mode: Phase correct PWM top=0xFF
// OC2A output: Inverted PWM
// OC2B output: Inverted PWM
TCCR1A=0xF1;
TCCR1B=0x03;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=v_x;
OCR1BH=0x00;
OCR1BL=v_x;
  
  
  
    
}



void loop() 
{
   
  
  Now = millis();
  if (dt<20)
 dt=45; 
  Angle[0]= ( ypr[1] * 180/M_PI) -6;
  Angle[1]= ypr[2] * 180/M_PI;  
  a=OCR1AL;
  b=OCR1BL;  
  
 ///*************************************Sensor Loop**********************//////// 
  
  if (!dmpReady) return;
    while (!mpuInterrupt && fifoCount < packetSize) {
    }
    mpuInterrupt = false;
    mpuIntStatus = mpu.getIntStatus();
    fifoCount = mpu.getFIFOCount();
    if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
        mpu.resetFIFO();
        } else if (mpuIntStatus & 0x02) {
        while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
        mpu.getFIFOBytes(fifoBuffer, packetSize);
        fifoCount -= packetSize;
        #ifdef OUTPUT_READABLE_YAWPITCHROLL
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetGravity(&gravity, &q);
            mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
            Serial.print("XY-Angle\t\t\t");
            Serial.print(Angle[1]);
            Serial.print("\t\t");
            Serial.print(Error);
            Serial.print("\t\t");
            Serial.print(a);
            Serial.print("\t\t");
            Serial.print(b);
            Serial.print("\t\t");
            Serial.print(v_x);
            Serial.print("\t\t");
            Serial.print(Kp*10);
            Serial.print("\t\t");
            Serial.print(Kd*10);
            Serial.print("\t\t");
            Serial.println(Ki*1000);
        #endif
    }
   
   ///************************************* End Sensor Loop**********************////////
   
   
    //*********************************************My Loop**************************************//
  if ( millis() >=10000 )
 {
  
  ///PID Logarithm
  
  Error= Des_angle - Angle[1] ;   // stable desired angle = 0
  
  D=(Error-lastError);
  D/=dt;
  lastError=Error;
  instI=Error * dt;
  I=I+instI  ;
  
 if ( Error == 0 )
      I=0;
 else
 {
  if (abs(I)<180)
    I=0;
 else if ((I>20250)&&(I>0))
    I=20250;
    else if ((I<-20250)&&(I<0))
    I=-20250;
 }
    
    if (v_x<=118)
   {
     OCR1AL= v_x - (Kp * Error) -(D * Kd) - (I*Ki);
     OCR1BL= v_x + (Kp * Error) +( D * Kd) + (I*Ki) ;
   }
   else
   {
     OCR1AL= v_x ;
     OCR1BL= v_x  ;
   }
    
    /*
    OCR1AL= v_x - (prop_x * Error) - (D*Pd) - (I*Pint) ;
     OCR1BL= v_x + (prop_x * Error) +( D*Pd) + (I*Pint) ;
     */
    
    ///Pc interface
  
  if(Serial.available())
    {
      button = Serial.read ();
      Serial.println(button);
      
      //increase speed
      if (button == 'w')
      {
       if (v_x==130)
      {
        v_x=123 ;
      }
      else
      {
       v_x-=1;
      } 
      }
      
      //decrease speed
      if (button == 's')
      {
       if (v_x==130)
      {
        v_x=130 ;
      }
      else if (v_x==123)
      {
       v_x=123;
      }
      else
      {
       v_x+=1 ;
      }
       
     }
       
       ///increase   prop_x
       
       if(button=='p')
       Kp+=0.001;
      
      //decrease prop_x
      
      if(button=='m')
       Kp-=0.001;
       
       if(button=='e')
       v_x=130;
      
      if(button=='o')
       Kd+=0.001;
      
      //decrease prop_x
      
      if(button=='n')
       Kd-=0.001;
      
      if(button=='i')
       Ki+=0.00001;
      
      //decrease prop_x
      
      if(button=='b')
       Ki-=0.00001;
      
    }
  
  button = 0 ;
 }
lastTime = millis ();
dt= lastTime-Now ; 
}

hello I'm Antonino Lagati end I'm working on a MPU6050 sarkfun and use a code similar to yours but does not compile error .................... MPU6050 mpu; how did you manage to make it run? thanks

how did you manage to make it run?

By downloading and installing the proper library, obviously.

Have you tried the angle calculation using this http://hobbylogs.me.pn/?p=47 library.