# Silverware Wiki

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.