User Tools

Site Tools


Sidebar

Table of contents

pid_tuning_guide

PID Tuning Guide (written by silverxxx)

This text is taken from here

Ok , the pids look something like this in file pid.c (rate) and anglepid.c ( for level )

Quote:
// Kp ROLL PITCH YAW
float pidkp[PIDNUMBER] = { 17.0e-2 , 17.0e-2 , 10e-1 };
// Ki ROLL PITCH YAW
float pidki[PIDNUMBER] = { 15e-1 , 15e-1 , 50e-1 };
// Kd ROLL PITCH YAW
float pidkd[PIDNUMBER] = { 6.8e-1 , 6.8e-1 , 5.0e-1 };
// output limit
const float outlimit[PIDNUMBER] = { 0.8 , 0.8 , 0.4 };
// limit of integral term (abs)
const float integrallimit[PIDNUMBER] = { 0.8 , 0.8 , 0.4 };

in the brackets, the first number is roll, second pitch, and last is yaw.

Generally the roll and pitch are the same for square frames.

So you have kp , ki and kd which are the 3 terms of the pid.

Then there is outlimit, that sets the max pid output. In this case the output is at 0.8 , or 80% thrust max for pitch and roll, and 40% for yaw ( because more yaw makes it unstable)

The integrallimit is similar, but applies to the Ki Iterm only. It can be set the same as outlimit , or smaller.

About the numbers used: because this are float numbers, and there are radians somewhere in the program, the p, i , and d terms are very small, so they use the scientific notation, in order to not have to type many zeros.

So 17e-2 = 17 * 10 to the power(-2) = 0.17

and 15e-1 = 1.5

There are also large positive numbers in some places, for instance 1e6 is 1000000

Level mode tuning:

In level mode, the firmware uses both rate and angle pid, and as such, it's best to have the quad tuned in acro mode before fine-tuning level mode. The level mode pid settings are found in file “anglepid.c

Level mode is pretty easy to tune as it usually only needs P or PI (it will fly ok with P only). For quick tuning set P only, and set I to zero.

Acro mode tuning:

It's possible to have the quad fly with P and D only, and that is probably the fastest way to tune it since only 2 numbers are required. From PD to PID generally the P term can be reduced about 30%-50% and I term increased to a value where there are no side effects.

I'd start with D of 5e-1 and find a P that works well. If the quad flies, it's easy to increase D, as a d that's too high can generally either be heard, or induce very fast oscillations. If the quad is drifty (and hard to control) it needs more P, if it oscillates after a change of angle , it needs less.

A P that is too high will cause oscillations after a stick input. In this case, either decrease P or increase D.

The I term can have all sorts of effects, and it is also affected by P (and vice-versa) so it's best to either leave it last, or have a small one ( or zero) The I term can cause some overshoot, or it can cause drift if its zero and P and D are not high enough. It can also cause oscillations that get worse with time. In case of overshoot, lower I term or increase P term.

Note that a quad with P D ( i set zero) will only fly well if the motors produce similar thrusts, and the quad is built straight. The CG has to be in the middle, as well.

The D term usually creates the “locked in” feel. The higher the D term, the more “locked in” the quad will feel, and also will cope better with wind and other issues. A higher D will also allow a higher P to be used, hence increasing control response. Too high D will cause very fast oscillations, and it may also cause “jumpyness”, the quad seemingly jumping up/down. The jumpiness is caused by vibrations (mainly from the motors), as the D term is vibration sensitive.

A unusual method to check how good the quad is tuned is to hit it while hovering with an object (ruler / pencil) slighty, on one of the corners. If it oscillates afterwards, either/both P or I are too big or D is too small.

PID Tuning - another perspective (Ian444):

This is how I tune, it may be wrong, as there are many tuning methods, but this might help or give you some ideas, and note this is just my opinion, its written for acro mode tuning:

You need D to balance P. P is the primary correction force, D is the one that stops it overshooting the mark. To check this, hover the quad in front of you and facing away from you, and flick the roll stick left and right. See if the quad bounces as it settles on the new position. If it does, increase the D at least 10% and try again. If it doesn't, decrease the D until you just start to see a little bit of bounce. A little bit of bounce (or bounceback) is around where you want to be. Too much D can wreck a tune so if there is no bounceback you need to decrease it until you find the edge of bounce. Once P and D are in the correct ratio I simply scale them up and down together to make changes, I usually use 10% for a small change and 20% for a larger change.

Let's assume you now have P and D in the correct proportion, but maybe not the correct overall amount. How do you know if the P/D ratio is too much or too little? If there is not enough P/D the quad feels a bit doughey or unresponsive, or like the rates are too low, and it can also get upset with wind gusts while hovering, because there is not enough P authority to keep the correct attitude, or go to a new commanded attitude. Too much P is a bit harder to detect but often shows up when you try to land, and you touch the ground, and suddenly the motors increase in rpm on touching down (it keeps wanting to bounce off the ground). A little bit of that behaviour is normal, but excessive amounts are due to too much P/D. Also you can tell by feel (does the quad always track straight and go where you expect it to?), but with a new quad that is difficult because you might not know what it is supposed to “feel” like. So in that case try to get it flying with nice enough manners while you get used to it. If you are not sure, use the trial and error method, increase P/D by say 15%, and then decrease P/D by 15%, and see what the results are. That will quickly lead you in the correct direction.

The I term is adjusted by lowering it until you see the quad having difficulty holding a set attitude both in hover or while travelling forwards on a set course, it will start to drift around. Then bump I up just enough so the quad will hold its attitude (say in 10% increments). If you start tuning with too much I, it will foil your tuning attempts. Any value of P, I or D that is too high for the quad will make tuning very difficult. It is always best to start low and work up, and do not increase any of the values any more than is needed.

It is difficult to know where to start with the I term. Usually it ends up being 1/3 to 1/2 of the P term once tuned (on my quads). Also I find it doesn't need to vary much when P and D are changing, it is almost an independent setting from P and D. Start as low as you are comfortable with. Before you fly a newly-built quad, it is almost impossible to know where to start, unless you have built a similar one before, or someone gives you some starting values. In the case where there is nothing to start with, you have to put some numbers in there and just see what happens.

Some more comments by silverxxx regarding where to start with I from this post: https://www.rcgroups.com/forums/showpost.php?p=36368724&postcount=6881

“I sometimes start at zero to see how balanced the quad is. Otherwise if I can't balance the quad or I just don't feel like havig drifts, I just put 1 in there, that stops the drifts.
However, low I seems good in gentle flights, but will be bad as soon as heavy maneuvering starts. Generally the quad tends to want to come back after a rate change with I too low.”

Also, you don't have to tune a quad and that's it (in one go). If you keep notes, you can keep tweaking it when you are in the mood to try some changes. Some quads I almost gave up on turned out to be great flyers in the end, given a bit of time and persistence, but not all at the same time, (or on the same day), sometimes it's weeks later until I get it flying right. Others quads, they are tolerant of many tuning values and fly well right from the start.

Something else to add is that in general, higher kv motors need less PID because in effect they add gain to the PID's compared to the same size motor with lower kv rating. A similar thing can happen by changing prop pitch/diameter or number of cells, again the tuning is affected because for the same change in motor speed command from the FC, a different thrust change occurs compared to before the props or number of cells was changed. Unfortunately the FC does not know anything about the motors/props/batteries fitted, so it has to be tuned for whatever combination of parts are being used. Sometimes hardware changes do not require a retune, but usually they do.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
pid_tuning_guide.txt · Last modified: 2016/12/07 21:48 by ian446