Hello everyone. I have been trying to create my own controller and quad copter and i hit a roadblock. The problem is that when i try to fly the quadcopter, it feels like its going to take off as your increase the throttle but once it gets to a point where its actually going to start taking off, it just goes berserk. it never takes off and it just starts going haywire. If i hold it with my hand from the buttom and try to do some basic tests, it seems to work. if you tilt towards a motor, that motor increases power and if you tilt quickly, the motor reacts with faster speed.
Im not sure if im missing a step or something. i looked into a million equations and tried quite a lot of them, its not working.
here is what i have right now, the Code takes input from the controller and changes throttle speed. The Angles comes from the chip MPU 6050 using Jeff's library. as far is i know, the Library filters the Acc and Gyro and uses both to give you the Angles but im not sure.
No code for movement yet since it cant even take off vertically. Im Using arduino nano for the quad and uno for the controller. Right now, the leveling code is inside the Quad itself.
Frame:Amazon.com: 90mm 3K Carbon Fiber Quadcopter Frame for Racing Quadcopter Micro FPV Drone: Toys & Games
the MPU chip:Amazon.com: MPU-6050 Accelerometer Gyro Sensor 6DOF Six-Axis IMU for Arduino Quadcopter Drone RC, 3-5V I2C Compass 40P Female to Male Dupont Cable, 40P Male Pin Header: Home Audio & Theater
The ESC :Amazon.com: Spedix IS35 4-in-1 35A 5S ESC (20x20mm): Toys & Games
Motors:
Code: [Select]
Code:
//
float Porpotional_gain=3;
float Integral_gain=1.3;
float Derivative_gain=0.2;
PidTime=millis(); // we Read the Current time.
TimeError=(PidTime-LastPidTime)/1000;
CurrentReading_Yaw=ypr[0] * 180/M_PI;; // we read current Angles.
CurrentReading_Roll=ypr[2] * 180/M_PI;
CurrentReading_Pitch=ypr[1]* 180/M_PI ;
Desired_Roll=Initial_Roll; //the initial Angle of the MPU when its flat on the ground
Desired_Pitch=Initial_Pitch;
Error_Pitch=Desired_Pitch-CurrentReading_Pitch;
Error_Roll=Desired_Roll-CurrentReading_Roll;
int_errorGain_Pitch+=(Error_Pitch*TimeError);
int_errorGain_Roll+=Error_Pitch*TimeError;
Integral_Pitch=Integral_gain*int_errorGain_Pitch;
Integral_Roll=Integral_gain*int_errorGain_Roll;
Derivative_Roll=Derivative_gain*(( Error_Roll - Prev_Error_Roll)/TimeError);
Derivative_Pitch=Derivative_gain*(( Error_Pitch - Prev_Error_Pitch)/TimeError);
Input_Pitch=(Porpotional_gain*Error_Pitch)+Integral_Pitch;
Input_Roll=(Porpotional_gain*Error_Roll)+Integral_Roll;
Motor_1_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)-Input_Pitch;
Motor_3_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)+Input_Pitch;
Motor_2_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)-Input_Roll;
Motor_4_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor) +Input_Roll;
Prev_Error_Pitch=Error_Pitch; // update values that we need to carry for the next loop call.
Prev_Error_Roll=Error_Roll;
LastPidTime=PidTime;
//The MinMicroSeconds is that smallest value the motor can take which is 1000 milis.
//MotorPower is Potentiometer reading from the controller and its scaled by 3.
Please, i just want to know if im missing something or is this just a "keep adjusting PID " type of problem. i tried tuning the PID multiple times and there is noticeable difference in the attempts to fly but never succeeded.
there is very little that happens outside of this loop in terms of balancing the Quad. What else does this need to get stable flight?
Im not sure if im missing a step or something. i looked into a million equations and tried quite a lot of them, its not working.
here is what i have right now, the Code takes input from the controller and changes throttle speed. The Angles comes from the chip MPU 6050 using Jeff's library. as far is i know, the Library filters the Acc and Gyro and uses both to give you the Angles but im not sure.
No code for movement yet since it cant even take off vertically. Im Using arduino nano for the quad and uno for the controller. Right now, the leveling code is inside the Quad itself.
Frame:Amazon.com: 90mm 3K Carbon Fiber Quadcopter Frame for Racing Quadcopter Micro FPV Drone: Toys & Games
the MPU chip:Amazon.com: MPU-6050 Accelerometer Gyro Sensor 6DOF Six-Axis IMU for Arduino Quadcopter Drone RC, 3-5V I2C Compass 40P Female to Male Dupont Cable, 40P Male Pin Header: Home Audio & Theater
The ESC :Amazon.com: Spedix IS35 4-in-1 35A 5S ESC (20x20mm): Toys & Games
Motors:
Code: [Select]
Code:
//
float Porpotional_gain=3;
float Integral_gain=1.3;
float Derivative_gain=0.2;
PidTime=millis(); // we Read the Current time.
TimeError=(PidTime-LastPidTime)/1000;
CurrentReading_Yaw=ypr[0] * 180/M_PI;; // we read current Angles.
CurrentReading_Roll=ypr[2] * 180/M_PI;
CurrentReading_Pitch=ypr[1]* 180/M_PI ;
Desired_Roll=Initial_Roll; //the initial Angle of the MPU when its flat on the ground
Desired_Pitch=Initial_Pitch;
Error_Pitch=Desired_Pitch-CurrentReading_Pitch;
Error_Roll=Desired_Roll-CurrentReading_Roll;
int_errorGain_Pitch+=(Error_Pitch*TimeError);
int_errorGain_Roll+=Error_Pitch*TimeError;
Integral_Pitch=Integral_gain*int_errorGain_Pitch;
Integral_Roll=Integral_gain*int_errorGain_Roll;
Derivative_Roll=Derivative_gain*(( Error_Roll - Prev_Error_Roll)/TimeError);
Derivative_Pitch=Derivative_gain*(( Error_Pitch - Prev_Error_Pitch)/TimeError);
Input_Pitch=(Porpotional_gain*Error_Pitch)+Integral_Pitch;
Input_Roll=(Porpotional_gain*Error_Roll)+Integral_Roll;
Motor_1_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)-Input_Pitch;
Motor_3_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)+Input_Pitch;
Motor_2_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)-Input_Roll;
Motor_4_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor) +Input_Roll;
Prev_Error_Pitch=Error_Pitch; // update values that we need to carry for the next loop call.
Prev_Error_Roll=Error_Roll;
LastPidTime=PidTime;
//The MinMicroSeconds is that smallest value the motor can take which is 1000 milis.
//MotorPower is Potentiometer reading from the controller and its scaled by 3.
Please, i just want to know if im missing something or is this just a "keep adjusting PID " type of problem. i tried tuning the PID multiple times and there is noticeable difference in the attempts to fly but never succeeded.
there is very little that happens outside of this loop in terms of balancing the Quad. What else does this need to get stable flight?