Quad-Copter with PID Controller

Hello,
I have been building a custom arduino quad-copter that uses an MPU-6050 for the gyro/accel and a nrf24l01+ as a transceiver. To control the motors I am using PID, but have had some confusion about the subject. From my understanding, I thought PID only brings back the quad-copter to the desired angle, but doesn’t keep it there. For example, if the quad-copter’s center of mass isn’t perfectly centered, then some of the motors will always have to work slightly harder than the others to keep it a desired angle, but doesn’t PID just get the drone to the desired angle and then stop applying any extra power once its there?

Do I need to apply some sort of offset to the motors, or am I wrong about PID entirely. I have posted the code I have used on the drone below.

Thanks for the help.

stabilization_I2cdevMPU_.ino (17 KB)

I am no expert on PID really, and it seems you understand probably better than I, but PID is a method of providing stable and consistent control output where there are varying, unknown and unpredictable loads in play.

Think controling the speed of a fan as a (probably poor) example:
Without PID control: if you placed your finger on the fan blades while it were spinning (i.e. applying a load to the motor) then the fan would of course slow down and make no attempt to get back to the speed it was prior to the load being applied.
With PID control: if you placed your finger on the fan blades to slow them down, the output would be automatically adjusted to increase the power to the motor in an attempt to correct the discrepancy between the actual speed and the desired speed (commonly referred to as the set point).

Apologies if that's teaching granny to suck eggs, but hope it helps.

I thought PID only brings back the quad-copter to the desired angle, but doesn't keep it there

These two statements seem to be contradictory.

If the target angle is say 90 degrees to the horizontal, ie level, then the effect of the PID should be to adjust the inputs to achieve that angle. Once the angle is achieved then the effect of the PID will be to maintain the same angle as any disturbance from it will be corrected.

I admire your ambition, but it seems like you aren’t quite ready to undertake writing a flight controller for a quadcopter.

The flight controller acts to make the quadcopter do what the human is asking.

In stabilised or level mode, the operator is telling the quadcopter to attain and maintain a desired angle of orientation, pitch and roll axes both.

In rate or acrobatic mode, the operator is telling the quadcopter to attain and maintain a desired rate of rotation about the three axes pitch, yaw and roll.

The PID loops use feedback from the sensors to adjust the motor speeds to accomplish the desired behaviour. To keep it orientated at the desired angles, or to keep its rates of changes about the three axes constant.

Start with something simpler, like PID Pong to get a better idea about feedback control servomechanics.

Fly some toys. Look at any of the available open source flight controller softwares for quadcopters. You are seriously attempting to re-invent a well developed wheel.

alto777