Totally boring PID info, don't read...

FinalGlideAus

terrorizing squirrels
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. :)
 
Last edited:

Robbie

Senior Member
I love the way people have put more effort in to the comments the reading the article....tbh my pids are fine and that amount of text looks scary....
 

narcolepticltd

I unbuild stuff regularly
I love the way people have put more effort in to the comments the reading the article....tbh my pids are fine and that amount of text looks scary....

I'd say the majority of us who've commented so far have read through the entire article regardless of our current PID situation. While your tune may be working out, there's a vast number of posters here that are brand new and have no clue. This is a good start to point them towards.

It's long winded because it is presented in a non-technical format... not to mention FGA has been promising this for a long time, and finally had the chance to get it out of his brain. This is more a 'stream of consciousness' post that can be cleaned up and refined later.
 

narcolepticltd

I unbuild stuff regularly
Initial notes for FGA:

First of all...

January-20-2012-18-57-42-sfdga004.JPG

Secondly, Scott Pilgrim vs the World is awesome and should be merged into cleanflight.

If you do get around to prettying this up with bold flavored text and sections, it might be helpful to mention that a lot of the info presented outside of P I and D descriptions are specific to cleanflight and note the current version (cause a year from now everything will be different, and it will confuzzle those who see this as a sticky).
 

FPVology

Member
I am only half way through, but just wanted to mention I think this is brilliant.
So far I think this is an excellent write-up and think it can/will help A LOT of people.

Great post FGA.
 

nilsen

Senior Member
Thanks FGA,

Seems tuners anonomous has to reconvene after some re-tuning.

The most interesting thing there for me as the "super expo", I didn't realise Pitch/roll rates on PID 3 actually changes the PID values.

Thanks a lot.
 

jipp

Senior Member
fun read. i go for a weekend to the lake and look what i come back too! i should go to the lake more offten. was a lot of fun flying the quad at the lake. and to my surprise i did not even lose it over water the one time i was brave enough to take a large circle over it ( ok ill be honest, i did not plan on going over the water sorta just happened.. how could i tell my little sister i suck as a pilot and am still learning and i could not do something as simple as that yet.. yeah.. i did tell her after words and she called me a idiot.. sigh can not win i tell ya sometimes. ).. laughs. thanks for taking the time to post it. i have no plans using clean flight at this point. but i still read this piece over twice just so i have a better understanding of pids.. as i assume pids are part of every FC/software package. and they should all work together in the same way just use different vocabulary.

chris.
 

SlowPass

Member
I noticed in the new cleanflight configurator it is possible to setup in-flight adjustments to Pitch and Roll separately now. Is it easier to tune them separately or should Pitch and Roll be tuned together at the same time and then adjusted separately if needed?

I'm guessing they could be slightly different because of how a quad balances or how cameras are mounted, correct?
 

FinalGlideAus

terrorizing squirrels
Good to hear Dominic has fixed that up now. I don't use it and haven't followed its progress but now it's fixed I may do. Most H quads are not symmetrical in motor layout or weight distribution so the pids will be different for roll and pitch.