PID problems

mate115

Member
Hi everyone,

So i decided to build my own quadcopter half a year ago and i finished everything, the drone is built, the controler is working (i built my own with arduino) and motors spin as the should. So basicly everything is working. I decided to use PID for the stabilization and its working a bit wacky. I am using MPU6050 to calculate the angle, which is working fine. So the problem is that when i turn the P gain up, it oscillates like it should, but the oscillations grow bigger. I checked everything and its working as it should, the PID refresh frequency is 400Hz. In one loop it reads sensor data, calculates the angle, the error and PID. So in theory, it should be working. I understand it should be oscillating, but i dont get why the oscillations keep growing and get bigger over time! Of course, if i turn the P gain down, the grow slower, but there just isnt any P gain where they dont grow and get bigger over time. Even if i use the smaller P gain (if i use really small gain the output of the pid is too small to actually make any changes to the motor speed).

My hypothesis is that the motors i am using have so big delay that the PID is working as it should, and the signals to the motor drivers are being sent at the right time, but the motors actually produce thrust with such a delay that it overshoots more and more because it doesnt correct the angle at the right time but with delay. Could this be the problem?

With best regards, mate115
 
:rolleyes: ... Try increasing your "D value".
The reason the oscillations grow bigger is because the further away Proportional is from the set point the more aggressively it drives
the correction which, when too aggressive (P is too high) causes it to overshoot that set point. Upon realizing it's overshot the setpoint
it then again drives towards the set point only to overshoot it again, hence oscillations. As the set point is approached the Derivative will
reduce the Proportional's drive to minimize any over shoot. ;)
 
I actually tried doing that but it still overshoots. I tried increasing it from 0 to max (2) and i found there are spots where the oscillations grow faster, and spots of D gain where they grow slower, but i simply couldnt find any D gain where they would grow. Is there any way to calculate the D gain? I know theres this Ziegler-Nichols method, but i simply cant use it since i have oscillations all over the place. Any recommendations as to what i can do?
Thank you so much for your help!
 
And for the integral part, i didnt even try doing it yet, right now i am focusing on P and D, mostly on P. I was reading all these different tuning methods, but pretty much all of them require either oscillation period time, or they require rise time (meaning the time it takes for the P to correct the error). I am really new to regulations and PID especially, and i just want to know if its alright that when you are using P gain only, the oscillations grow bigger? I am so in the dark right now, and i want to know at least if i am on the right path.
 
And for the integral part, i didnt even try doing it yet, right now i am focusing on P and D, mostly on P

Your approach is exactly correct.
Think of "P" as the responsiveness to being off target.
Think of "D" as the shock absorber or dampener for "P".
Think of "I" as resistance against any outside forces.

After you've achieved a good balance with the Proportional and Derivative functions, THEN tune the Integral
to reduce any drifting that may occur without your input. This is always a much smaller value than the other two
and remember that the settings for any one particular axis (roll, pitch, yaw) will also have an effect on the settings
for any other axis. Tuning PIDs is somewhat of an art form ... lol .. so don't get discouraged if it takes some time to
get everything to your liking. :)
 
Ziegler-Nichols method

That mathematical modeling is fine for getting you into the ballpark, but you're already there.
The first thing I would suggest is to DRAMATICALLY INCREASE your processing loop time speed.

400 Hz is just not anywhere fast enough, you should try for something more like around 8KHz.
 
Last edited:
Back
Top