I'm testing Arduino's PID Library as a black box. I've mocked Arduino's functions (analogRead, millis, delay) and coded a small engine to simulate the vertical movement of a quadcopter. For simplicity I'm considering only 1 dimension, no wind, and no lateral movement A simulated altitude sensor is feeding the input of the PID controller, and the output controls the thrust of the engine. The quadcopter has a 2:1 thrust-to-weight ratio.
I'm trying to tune the Kp, Ki and Kd gains using any of the manual methods described in wikipedia .
Both the manual and the Ziegler-Nichols method require to set Ki and Kd to zero at first, and set Kp to a value where the output starts to oscillate.
The problem here is that when doing that, no matter what value I give to the proportional gain, the oscillation always becomes unstable, like this (not my image):
In the manual method, the wiki says:
increase the Kp until the output of the loop oscillates
What I understand from that sentence is that I should start with a really low value of Kp, then increase untill it oscillates (and I guess it would be an unstable oscillation). To begin with, I don't know how the non-oscillating case would be. But in my simulation it always oscillates (in an unstable way) no matter how low the gain is.
So I switched to Ziegler-Nichols, where according to the wiki :
The "P" (proportional) gain, Kp is then increased (from zero) until it reaches the ultimate gain Ku, at which the output of the control loop oscillates with a constant amplitude.
Here it is more clear that i should aim for a constant amplitude oscillation. But then again it doesn't matter what value I try, the oscillation is always unstable. Which makes sense to me, because its thanks to Kd that the PID controller "sees" the future, and with only the proportional term it only reacts when crossing the setpoint.
For the simulation, I started having the quadcopter take off from an altitude of 0 meters, but as the amplitude of the oscillation increases with time, it ends up ballooning and crashing in the floor. I tried to compensate for this by rising the setpoint higher so that there is more space to the ground, and launching it from this altitude, hoping the thing stabilized even with a really large amplitude, but the result is the same. I've also tested with really small setpoints (2-3 meters), and this produces lower initial amplitudes and a shorter period, but in the end it goes to the floor.
How should approach this? And BTW, is the PID an appropiate controller for quadcopters? What do the pros use in real life drones?