Micro quadcopter help

Hello Everyone,

I’ve been building a micro quadcopter. The main body is about 4.5cm long, and 4.5cm wide. The body is made from the PCB. It uses an ATmega 328 running at 16mhz, I am using a 3.7V/ 400mAh LiPO. I know the ATmega is running out of spec, but I only use it above ~3.8V. I have all the motors working, and even have PID working. I am able to tilt the quadcopter using my hands and feel it trying to correct its angle.
I initially had a problem with the hardware, the power management was lacking, causing me to solder in through-hole decoupling capacitors at key points on the board.
Here are some pictures:

The problem is that I’m not able to get it off the ground stabilized. Right when it turns on it leans to one side and flips. I am sure that the propellers are on the correct way, and the all the hardware works. I just want to know what you guys think?

Orange propellers face forward

I have also attached the main code (DMPsensortest.ino)

Extra pictures:

Video of motors running

Schematic:

DMPsensortest.ino (15.1 KB)

It's hard to tell what is going wrong. I don't see anything obviously wrong in the sketch. It is a little hard to read. Thre is no reason to use 'double' since on the Arduino that is the same as 'float' and casting your values to 'double' every time you use them is even more confusing.

It would be clearer to use PitchSetpoint and RollSetpoint in place of "Setpoint" and "Setpoint1". Similarly for Input, Output and PID.

When you use the IMU to get Pitch, Roll, and Yaw values are they nice and steady? Do the values change as you expect?

Since the library gives you YPR values in Radians I would just use them rather then translating everything into degrees.

With the PID outputs ranging from -255 to +255 it will be easy to exceed the PWM limits of 0 to 255. Maybe +/-10 would be more appropriate?

I am able to get nice and smooth values from the IMU. I'm using the built in DMP so all processing takes place in the IMU.

For the following part of the code:

    throttleFR = STARTSPEED + Output + Output1;
    throttleBR = STARTSPEED + Output - Output1;
    throttleFL = STARTSPEED - Output + Output1;
    throttleBL = STARTSPEED - Output - Output1;

The STARTSPEED is 75, the Output is the Y-Axis PID output, and Output1 is the X-Axis PID output. I am now mapping the PID outputs from -90 to 90. This way 75(STARTSPEED) + 90(Output max) + 90(Output1 max) = 255. This totally removes the jerkiness. Before, I was mapping Output and Output1 to -255 to 255.

But now I am experiencing a lot of fluctuations, I will try adjusting the PID constants,

It is quite a difficult stuff. Try multiwii for arduino, it may work with your board after some changes.

http://www.multiwii.com/connecting-elements

Yes it is very difficult stuff. Especially with a quad that's only 4.5cm wide(main body). Currently with any P value I keep experiencing oscillations.

anshulsanam: Currently with any P value I keep experiencing oscillations.

I'm no PUID expert but I think that means the gain is too high. Have you tried kP less than 1? Reduce the value by half and repeat until it is stable. If you are at 1.0 try 0.5! Keep kI and kD at 0.0 for now.