Due-based quadrocopter pid tuning

Hello. I've built a completely own quadrocopter and written my own software for it by following multiple guides on the internet. More info about the quadrocopter including the hardware and software can be found on this github project: https://github.com/Quarduino/quarduino

I'm now having problems with tuning the PID controllers. I've followed videos on youtube and other tutorials about how to tune PIDs for a quadrocopter but I'm not getting the same results. I started with tweaking the p-value but could not get the quadrocopter to be as stable as it's supposed to be and I've tried values raning from 0,0001 to 20 where the lowest value didn't stabilize at all and the highest made it tip over immediately. Because of this, I started tuning the d-value and it got a bit better but it's getting worse after a couple of seconds of flight.

Here is a video with the best settings I could get, P=0,5 and D=0,5: https://mediacru.sh/D-ew_2RycgZO. When changing the i-value which is supposed to prevent the quadrocopter from leaning at a constant angle, it leaned even more. I suspect this is because the gyro may "think" it's always at an angle due to vibration.

Does anyone know anything more I could try to do? Or could this be caused by too mutch vibration?

What is your sensor? Only gyros? Or do you have an IMU? Are your motors pretty well balanced? How do you manade the D calculation? Is it filtered?

I'm using a Sparkfun 6DOF IMU with an ADXL345 accelerometer and a ITG3200 gyro (this one and this library). I'm not sure if the motors are well balanced, at least they didn't vibrate when I tested them one at a time. The PID-calculation is done using this library: http://playground.arduino.cc/Code/PIDLibrary.

I don't see any filtering on the derivative action of this PID. On a system such as a multicopter, that can be a problem since the vibrations can induce high frequency noise in the attitude estimation... So either you filter the derivative input or you have to stay with a relatively low Kd to avoid oscillations.

Also, the attitude estimation is critical since, with a wrong estimation, you can't expect a good behavior... But I think the lib should do it fine enough.

Anyway, your copter's behavior is in the good direction. It can stabilize actively for a few seconds before it starts to oscillate. A better tuning should do the work.

Set Ki and Kd to 0 and start with a low Kp. Increase it until it starts reacting too fast and oscillate or flip over. Then set the Kp to half of that and start increasing the Ki to reduce its leaning. Then increase the Kd (not too much) to avoid oscillations. If after setting the Kp, you still have oscillations, try to add a low Kd...

The problem I have is that I don't really know when I should stop increasing Kp and dividing it by 2. I went from Kp 0 to about 1,3 with small steps in between and that's when it felt like it was oscillating too much. Then I set Kp to around 0,65 but somehow it still felt too much: https://gfycat.com/IlliteratePitifulGoa. I began increasing Ki from 0 just to see if it would help anything which is didn't since from what I know, it only helps to reduce constant leaning rather than this kind of oscillation. What do you think if it looks like in the video above? Maybe Kp is still too high and I should start over with smaller steps between each test?

I haven't try a manual tuning for a quadcopter yet, so I'm pretty much guessing with you :/

I think you should reduce the Kp indeed. Normally, with a too low value the copter would not oscillate, that should be a good start. Increasy slightly the Kd should reduce the oscillations but since you don't filter the derivative of the angle, I think this will only increase them.