### PID Explained

PID is not difficult. It is very time consuming to get it right. It is a straightforward mathematical calculation. The dynamic reactionin the real world makes it hard.

If you have an electronic thermostat at home it is PID controlled. So is your oven. I have worked on hundreds of PID equipped machinesthat use PID to control a moving mass driven by a motor and screw, a 6,000,000btu burner (12 of them. Some gas bill!) and lots more.

You use PID every day when you drive your car. When you are driving along at 60 mph you have about 10% throttle. Try stopping the car andstarting off with 10% throttle. You will eventually get to 60 mph. It will takea long time.

You don’t drive that way. Instead, you push the throttle down. Driver A in a Honda Civic uses 50%. Driver B in a Ford Mustang uses 95%.How much I push the throttle is “P”.

In our case not the real RC throttle, but the reaction to a difference between where we are and we should be. If we are not touching theroll stick and we are level there is no difference. If the wind changes theroll then the sensor reads the difference. How much you want to react isdetermined by “P”.

Both drivers lift off the throttle at exactly 60 mph. The Civic overshoots by 5 mph. The Mustang overshoots by 20 mph. That would be an “I”of zero and a large "P". In real life you start backing out of the throttle as you approach 60mph. The Civic driver starts to ease out of the throttle at 50 and gently rollsup to 60 mph. The Mustang driver starts to ease out at 55 and still overshootsa little. How much I lift off the throttle as I approach 60 mph is “I”. If “I”is too big you overshoot. If ”I” is too small it may never get there. “I” ispart of the equation from the start, but “P” has the largest influence. As youget closer to where you want to be “I” exerts a stronger influence to smoothlybring that difference to zero. “P” justlooks at the amount of error, “I” looks at the accumulation of errors over time and brings you smoothly to zero error.The tuning information on the wiki says “I” should be zero. I disagree.

The Civic has a responsive throttle and responds to engine braking very well and rolls along at exactly 60 mph. The Mustang has verylittle engine braking and a very responsive throttle and rolls along somewherebetween 58 and 62 mph. To adjust long term variance in speed is “D”. Onlynecessary when you have a static condition. That almost never happens withflying vehicles. It is possible to have a very small negative number to helpcertain conditions, but that is long after “P” and “I” have been sorted out.

If you are flying a camera and want a smooth reaction with no wobbles or overshoot you will end up with different values than the guy thatis only interested in acrobatics and wants the fastest reaction and is willingto put up with a little overshoot to get what he wants.

One of the problems in coming to grips with PID is the fact that the numbers are dimensionless. We know what 5 lbs, 23 feet, and 94 psilook like because there is a dimension attached. PID isn’t related to anything.It is just a number that reflects the mass of the system and how quickly thesystem can react to changes. The numbers could be 0 or 100. There is no way to knowwhere to start with PID.

Fortunately for you the team here has established baseline PID numbers. Let’s assume that you and your buddy build identical quadcopters.You have received the finest parts that are available. Your buddy shops thebargain bin. They are going to fly slightly different from each other. The samePID numbers might be close. Might be different. Even if you managed to adjustthe PID, when you mount a camera the center of mass and weight change and so dothe PID numbers. Different prop, different motor . . .

If you have too large a number for “P” then it over reacts and you get a rapidly oscillating out of control vehicle. If “P” is too smallthen it is too slow to react and by then the situation has changed and you geta drunk vehicle. It’s important to slightly reach these conditions tounderstand where the middle is.  If you are starting from scratch start with "I" zero and work on "P". When you introduce "I", everytime you adjust “P” you affect “I”. When you are getting close to a number thatworks you are going to have to look at the numbers as well as the reaction. Thenumbers will tell you more about the reactions than your eyes will. On thissmall of a vehicle a very small change goes a long ways. The Aeroquad PIDTuning methodology should work well, but I still think adjusting “I” isnecessary. One set of PID numbers only works in a narrow range of fixed conditions. The Arducopter team has already figured out that a cascading PID is necessary. And multiple PID conditions.

So you tuned it perfectly on that nice summer day at the beach. Now in the winter at 6,000 ft you expect the same tuning to work? (PS:  Tuning outdoors with the wind makes life 10times harder.) Because we are tuning with multiple axis the job is moredifficult. As your axis angle increases you start to slide down hill and youraltitude has to compensate.

Keep track of every number you change and the reaction. When you get lost it helps you to get back on track. Change only 1 number at a timeand by small values. So what you are looking for is middle ground that will getyou running and make you happy. You can spend a ton of hours tuning the systemif you don’t have PID experience. Have patience. If you have no patience, usethe baseline number and go on with life.

#### Replies

• Great analogy I have been tuning mini quads and hexcopters for a while now and I'm still finding it hard to get right. Anyone with any base PIDs for a tarot 680pro with Sunnysky 380kv motors running on PixHawk if really appreciate your input. I have it flying fairly well but I'm still getting troubles yaw one way losing altitude and gaining in opposite yaw. Getting a lot of drift when I roll and release controls and needing to use opposite roll to counter. I have looked at the settings after auto tune and it seems to be as high as it goes and won't allow any further increases. Pitch and yaw are the only PIDs with more room to increase, is there somewhere to increase power for motors with more poles. Anyway thanks for the rundown Dean and any further help would be appreciated.
• Fantastic! I had previously heard PID explained in terms of the temperature of running water (wikipedia I think).

However I was driving in traffic and thought I was getting closer to understanding the whole concept as I noticed my mental calculations of throttle vs total speed vs distance to next vehicle.

Some people with a lead foot, rather than smoothly applying and reducing gas to adjust speed. This would be a to high a P... resulting in the oscillations that typically cause car sickness.

This write-up really helped me understand the mental algorithms I was doing in my head. Something in the way you said it, made it click into place. I'm much more well prepared to fix the tuning my 450.

Thanks and well done.

• Great!!! This is just what i needed! Thanks alot! :)

• thanks !! this helps !!

Can you elaborate on cascading PID .

at what frequency should i change my motor speed .

Is 100 hz fine for PID ?
• The Arducopter PID loop is not a classic PID loop. See http://www.diydrones.com/profiles/blogs/announcing-arducopter-the?i...

Peter
• Really great write-up. This kind of explanation really helps crest some of the newbie learning curves. Thanks.
• Oh yes, much appreciated. Thank you for your effort putting into layman's terms.
• Surprised no-one has answered yet!

That was an awesome write-up! Absolutly great... Call it "PID for Dummies" ;)

Thanks for writing all that
This reply was deleted.