Home / Electronics / PIDs and Tuning – A complete Guide

PIDs and Tuning – A complete Guide

What are they
PIDs are a way of controlling your ward. They are a series of values as seen under the PID tab of your flight controller firm where. This is an example from Clean flight:
By manipulating the different values you can get your quad to perform in different ways. PID (proportional-integral-derivative) is a closed-loop control system that try to get the actual result closer to the desired result by adjusting the input.

PID-quadcopter

Proportional Gain coefficient – the quadcopter will fly fairly stable without dialling in the other parameters too hard but this one is essential. This coefficient determines which is more important, human control or the values measured by the gyroscopes. The higher the value of the P, the more the quad reacts to the gyro and the more force gyro correction. If it is too low, the quadcopter will appear sluggish and will be harder to keep steady. However, if it is too high the multirotor starts to oscillate with a high frequency.
Integral Gain coefficient – this coefficient can increase the precision of the angular position. For example when the quadcopter is disturbed and its angle changes 20 degrees, in theory it remembers how much the angle has changed and will return to its previous position. In practice it isn’t always this accurate, nevertheless it is vital for flying. Without this term, the opposition does not last as long. I gain is especially useful with irregular wind, and ground effect (turbulence from motors). Sometimes referred to as Vortex ring oscillation this is when you descend into your own prop wash. Often this is visible as tell tail oscillations in descents and can be easily fixed by upping the I. However, when the I value gets too high your quadcopter might begin to have slow reaction and a decrease effect of the Proportional gain as consequence, it will also start to oscillate like having high P gain, but with a lower frequency.
Derivative Gain coefficient – this coefficient allows the quadcopter to reach more quickly the desired attitude. Some people call it the accelerator parameter because it amplifies the user’s input. It also decreases control action fast when the error is decreasing fast. In practice it will increase the reaction speed and in some cases an increase the effect of the P gain. A good way telling if a D gain is too low the quad will kick back after a flip so keep increasing it until it no longer does this.

quadcopter-overall-pid-process

The different PID controllers
Each PID controller is perfectly capable (despite what FGA says). What determines which one you use is mostly by personal preference on how you want to fly. For example, I use lux float because I find it a little more free and less robotic than PID 1, it is very hard to objectively say the difference between each PID but FGA has a go here:

PID screen cleanflight

‘I give myself the credit for starting all this PID controller whoohaarr since I got sick of PID 0’s annoying habits and tried PID 1, which convinced my friend Flits to try PID 1, who then put out an insane FPV acro video which Boris.B then saw and I convinced him to try it and then after that the whole mini quad world went nuts….. anyway ….
Quick answer, I have no favourites….
PID 0
Horrible, terrible, useless and every other bad word I can utter right now. Roll/pitch rate and yaw rate are coupled to the PID’s which makes you want to slit your wrist every time you try to tune.
PID 1
Very locked in but has a robotic feel about it. No coupling, no use of TPA. Much improved yaw.
PID 2
Crazy good fun for acro type flying and snappy yaw but not as locked in and has I gain issues. Also not so good in wind because of this. No coupling and no use of TPA. Extremely snappy yaw. Can have a high freq oscillation that are hard to remove.
PID 3
Feels and tunes like PID 0 so people will be familiar with it. Much better feel than PID 0 and no coupling. Suffers from oscillations when really pushed.
PID 4
Don’t bother
PID 5
Kind of like PID 3 but improved. Really nice feeling yaw and near the top of my fav list BUT>>>>….. Roll/pitch rates are coupled to the PID’s……. WHY WOULD YOU DO THAT TO ME WHY WHY WHY WHY WHY WHY WHY!!!!!!!!!!!!!!!!! AGGRO!
FGA goes on to gives the best expalnation of everything you need to know about PIDs and and RATES here:

I’ve been promising to write this down for a while so here goes. I may or may not know what I’m talking about and may be spewing out assertions and I take no responsibilities if your quad implodes into a blackhole and ends up on Pluto which may or may not actually be an official planet so take what you read here with a grain of salt (and be sure to add pepper…it improves the taste). It’s also worth noting that I am also currently watching Scott Pilgrim vs. The World on the computer so if something doesn’t make sense then you may need to reference the movie in question for the answer…

I could go on about all the maths and equations but all that jargon is confusing plus I just plain don’t understand it myself. I’ll leave that to the experts. Instead I’ll try to keep it simple and explain it the way I know and understand it.

Lets talk High School. A PID controller has three different High school types:
Mr. P is the High school sports jock. He loves to move around and take orders without question. With Mr. P’s gains set down low it’s like you’ve given him sleeping pills and he will be slow to react to your commands on the field. He will also go past where you wanted to and slowly come back like a sleepy person tends to do. As you raise the gains the sleeping pills wear off and he starts to act like a true athlete filled with sports drinks and he does exactly what you want with little delay. Too high gains and you give him too much sugar and he starts to shake from the sugar overdose. You don’t want him sleepy and slow to react but you also don’t want him so hyped up that he shakes all the time. The trick is keeping him fit, active and responsive without putting him over the edge.

Mr. I is that scared unpopular kid at school that doesn’t like to try new things and just wants to stay where he is without taking risks. He wants to hold onto things and doesn’t like to move. If you set his gains down low he won’t hold on very well and things will move without your commands. The higher the gains and the higher he holds on to stop things moving. If you set his gains too high he too will start to shake just like when you are really straining to hold a heavy object still. The trick is too set him high enough that he holds things still when no command is given and from outside forces but not any higher. I will explain why shortly.

Mr. D is the science nerd with glasses who is super smart and likes to sit down and think about things through and not act straight away. He likes to take your commands and think about them. Why do you want to move, how fast and when do you want to stop? Too low gains and there is little to no thinking going. Too high and there is too much thinking going on. Far too high gains and Mr. D will have a mental break down resulting in shaking. Mr. D needs to be set so there is enough thinking to stop excessive corrections to get to the desired point but not any higher. I will explain that next also.

Relationship between the PID’s.
You’ve heard me say before that P needs to be as high as you can get it but I and D need to be as low as you can get them. This is because their level of gain effects the others relative to each other. Mr. P is always going to set so he is the strongest over the other two. With just the P gain set and with out any D gain the quad will always over shoot the intended stopping position when you centre the stick quickly because it had no warning you were going to stop. Since it overshot it then tries to go back but will overshoot again because there was no warning when that point was reached. This is the oscillations you get when you quickly centre the stick after a quick roll. Remember that Mr. P is a sports jock. He’s quick, but dumb. He didn’t know you had to slow down as you approached the stopping point and as a result overshot. This is where Mr. D comes in with his big nerdy brain. With Mr.D turned up high enough, as Mr. P approaches the stopping point, Mr. D tells him the stopping point is coming up and suggests he slows down so he doesn’t overshoot. Since Mr. D is strong enough thanks to your settings, Mr. P will listen to him. How much he listens to him depends on how much D you have set. The issue here is if you have Mr. D turned up too high and powerful compared to Mr. P’s gains he will over think things and constantly annoy Mr. P which will slow Mr. P’s response time down just like that annoying person talking to you when you are trying concentrate. With your D up too high it can make the response feel slower and mushier. In a perfect world you want Mr. D up high enough that he tells dumb old Mr. P slow down just in time to stop right on the stopping point but still allow Mr. P to follow orders from you with a quick reaction. If you have Mr. D only telling Mr.P the right amount of info then you will get Mr. P working more efficiently and you can then turn up Mr. P’s gains a little more to get an even faster response.

It’s important to have your I gains high enough so that the quad doesn’t move around or get blown around by the wind or other forces that are outside and not anything to do with your control input but Mr. I can cause issues if he is set too high as well. Just like Mr. D, the higher you set Mr. I, the more power he has over Mr. P. With I gains set too high it is like trying to steer a car smoothly when someone else is trying to hold it still. If Mr. I is holding the steering wheel tight and then Mr. P tries to move it then after some fighting (because mr. P is set higher and stronger) Mr. P will eventually win but the steering wheel will slip suddenly and you will get the jerky movement around centre stick even though you expo is set fairly high. So you want Mr. I set high enough that he stops all uncommanded movements but not high enough that he fights Mr. P trying to act out your commands.

For roll and pitch I like to set up my initial PID’s based on other PID’s or an educated guess and adjust so its flying ok and the P gains feel reasonable. I then do 360 deg flips and rolls to look for oscillations as I stop and increase/decrease D until they appear/disappear. I then adjust P gains to get a better response and look for signs that the quad overshoots slightly and slowly comes back once after rolls and flips. That is a sign P gains are a little too low still and Mr. P’s sleeping pills haven’t fully worn off as he is not comprehending either what myself or Mr. D is trying to tell him. Then I fly hands off or fly smooth and watch for signs of the quad wandering (a windy day can help). I also watch for the movements becoming smoother/jerkier. If there is no uncommanded movements I lower the I gains or raise if there is. Yaw P is similar in that I feel for a crisp response and watch for a slight overshoot and slow re-centering afterwards and lower/raise to suit. Note that high yaw gains can cause oscillations as well. Yaw I gains are set just like the other I gains. Yaw D is not generally needed as the response is not going to be crisp as roll or pitch so dumb old Mr. P can do it on his own. D in yaw on most of the PID controllers don’t work as a D gain anyway. Then I set rotation rate and expo to suit my taste/flying style.

Of course all of the above is subject to the electronics used and an understanding needs to be had about the limitations of the hardware used on the frame. Certain esc’s are faster reacting than others and some have better braking than others. Some motors will spin up and slow down faster than others and some props have more inertia and therefore more yaw ability and speed change/thrust than others. Sometimes you might just be asking more than the setup can provide and it is nothing to do with the tuning. The bottleneck and the slowest part of the loop is always going to be the motors.

 

Right, since I’ve babbled on here for all of the above I may as well add on the below explanations:

RC Rate
Controls the speed of the rotation on roll and pitch. Think of it like dual rates in your Tx. It does not effect yaw.

Yaw Rate
Same as RCrate but just for yaw.

RC Expo
Works the same as expo in your Tx and effects Roll and Pitch. It does not effect yaw. Note that a separate Yaw Expo should be included from CleanFlight 1.9.0 onwards.

Roll/pitch Rate
Recently been split to separate Roll and Pitch. How this works depends on which PID controller you use. In Pid 1 and 2 (MW Rewrite and Luxfloat) it is simply a multiplier of RC Rate. In the others (MW2.2, MW2.3, MW Hybrid and Harakiri) it increases the RC Rate but also relaxes the PID’s as you move the control away from the centre. By doing this, Mr. I is not fighting Mr. P so much and Mr. P is being feed a small amount of short term sleeping pills which gives a smooth roll. Increasing this value gives you more and more of a loose, smooth but faster feel as you move away from centre stick so gives a similar feel to expo and hence why it has been dubbed “super expo”. Because it changes the PID’s by doing so it can have side effects and some people don’t like it. You can get the same feeling in PID 1 and 2 by increasing the RC Expo more.

Throttle Mid
The point where you want to centre your Throttle Expo on. This can help to settle down an over powered quad that is hard to hold in a hover.

Throttle Expo
How much expo you want to add to the throttle mid point.

TPA (Throttle PID Attenuation)
The more powerful the setup, the faster the response and the lower the PID’s need to be. That is why when you go from a 3S setup to a 4S setup the quad usually oscillates because you need to reduce the PID’s accordingly. This is also the case as you increase the throttle. Most of the PID tuning happens around hover throttle but as you increase throttle you also increase power and the response due to the extra thrust from the motors. What works at hover throttle may be too high at full throttle. TPA lowers the PID’s as you increase the throttle to help keep the ideal PID’s along the entire throttle range.

TPA Breakpoint
The point at which TPA begins to kick in. Default is 1500 (half throttle)

gyro_lpf (Low Pass Filter)
This filters out the noise (vibrations) in the system. Default is set to 42 which means all vibrations above 42Hz are ignored. In theory you want as much info from the sensors and as quick as possible but there are side effects to that. You can set it as high as 256 (Hz) but then you are likely to let a lot of noise (read: vibrations) into the system which the PID loop will pick up and tell the motors to correct. The motors then get accelerated and decelerated rapidly which works them much harder, heats them up more and draws more current out of them. The other side effect is they work in a similar way to a step down switching regulator that is lowering the voltage and you end up with less thrust and a slower top speed. So basically you want the gyro to give you as much info as possible but not enough that you are also getting the useless info as well, very similar to a boss in a conference room only allowing the people he trusts to talk at once rather the whole room which will only end up confusing him with too much information. The Gyro_lpf can only be set to the following values: 5,10,20,42,98,188,256Hz. If set to any other value it will revert back to the default 42Hz value. For a standard mini 42 is about as high as you can go without running into too many side effects. Sometimes 98 works but it really depends on the noise in the system. Remember that the higher you go, the better it may be but the more fiddly it may to hold a good tune. It’s kind of like a race car engine compared to a road car engine. One has more power and better response but one is more reliable. An amazing flying quad is no good if it turns to mud each time a prop is chipped.

Looptime
This is the speed at which the PID loop is done and is set in Milliseconds (2000ms for example). Of it is obvious that the faster the PID loop calculations happen the better the quad will handle but there are many variables to consider. The main one is the rest of PID loop can handle the increased speed. Motors and esc’s are part of the PID loop so they must be taken into account. Before OneShot they were the limiting factor so going below 2000 loop time was pointless. With Oneshot now able to go as low as 250 looptime things have changed. Of course some will argue if the Gyro_pf is still set to 42 there is no point but I’ll leave that for them to bitch about. Another thing to consider is that loop time is another type of Low Pass Filter. The lower the loop time the quicker the calculations are being done and the more noise will enter the system. Where am I going with this you may ask? No where really, just something to consider when doing these things. We are all try ing to get things happening faster for better response but as always there is never a gain somewhere without a loss somewhere else.

Right, that’s enough babbling so I’ll leave it there. As I said before, take it for what it’s worth. I’m not university educated in this area and can’t argue the numbers with the experts but I think I’ve proven what I can achieve with the numerous videos I’ve posted over the last year or so. I’ve always said, PID tuning is half maths and half art, neither of which I’m any good at.

 

 

credit: Help from Oscarliang and FinalGlideAus as well as an incredible community!

 

 

Check Also

AKK X1 25/200/600mw Video Transmitter – Review

Click here to purchase this video transmitter A great, good value Video Transmitter!!! As you …

Leave a Reply

Your email address will not be published. Required fields are marked *