View Full Version : Tune a PID for heavens sake.

So I read this (http://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method) and it mentions

The "P" (proportional) gain, Kp is then increased (from zero) until it reaches the ultimate gain Ku, at which the output of the control loop oscillates with a constant amplitude. Ku and the oscillation period Tu are used to set the P, I, and D gains depending on the type of controller used:

My question is at what "set point" do I begin to make it oscillate.

Iwant to control temperature and can span a wide range of temperatures so what temp do I use to get KU?

ElectricAye

02-08-2012, 10:23 PM

Will this help? The tuning process is usually a combo of trial-and-error and some rules of thumb.

http://www.omega.com/temperature/z/pdf/z115-117.pdf

localroger

02-08-2012, 10:25 PM

Check out the manual tuning subsection of the wikipedia article:

http://en.wikipedia.org/wiki/PID_controller

Executive summary: Start with all three coefficients at zero, run P up until it oscillates, drop P to about half that value, run I up to improve response time, if it gets unstable run D up to compensate but beware too much D causes overshoot. That's basically how it was done between discovery of the math and all these cheap newfangled computers capable of doing simulations and optimization.

JasonDorie

02-08-2012, 11:40 PM

If you're not sure what set point to use, typically when tuning them you start with a set point that is very close to your measured value, then you change the set point to something new (but reasonably realistic) and watch it respond. If it oscillates then you reduce the Kp param and do it again, then tune Kd, then Ki.

Temp controls are interesting in that they generally can't cool, or actively go down like they can heat, or actively go up, meaning that the response parameters may need to be different if your new set point is below the current measurement or above it. PIDs in general are a kind of fiddly black magic.

max72

02-09-2012, 09:20 AM

Another source of tuning tips is lakeshore:

http://www.lakeshore.com/Documents/LSTC_appendixF_l.pdf

Thanks everyone looks like I have some reading to do. :smile:

Running a simulation should be instructive. MATLAB (expensive) could be used, or Scilab (free).

mindrobots

02-09-2012, 05:34 PM

Octave is an open-source, free alternative to MATLAB that is very MATLAB compatible.

http://www.gnu.org/software/octave/

SONIC the Hedgehog

02-09-2012, 05:37 PM

Needed my 200th post, and I wanted to find something interesting and worthwhile to post, so what is trying to be oscillated? But also how would that help with temperature control/measurement?

mindrobots

02-09-2012, 05:42 PM

@Sonic: A classic form of feedback loop:

http://en.wikipedia.org/wiki/PID_controller

Read and learn.....very useful.

SONIC the Hedgehog

02-09-2012, 05:44 PM

Wow! I'm an honors student with straight As.....someone needs to slap a little sense into me

SONIC the Hedgehog

02-09-2012, 06:10 PM

So what's happening then is Bits is trying to use the propeller to control a PID so measure a variety of temperatures, and she would be trying to correctly tune the oscillations to accurately track the temperatures?

localroger

02-09-2012, 10:22 PM

Sonic, bits is trying to make the Prop control (most likely) a heater to maintain a constant temperature. In a PID loop, each sample cycle you start with an error, which is the difference between the actual temperature and your target. You use your error history to develop three terms, which you multiply by constants to generate this cycle's control output -- a term Proportional to the immediate error, one one based on the Integral which you can think of as the total area under the error curve (with area under the target being negative), and one based on the Derivative or the rate at which the error is changing. Once you get your terms you multiply each by a constant and bam, you get the output at which to set your heater for that sample cycle.

Implementing a PID loop is a lot easier than understanding all the highfalutin math that explains why they work so well; with the right constants they can track a moving target closely and recover quickly without overshoot when there is a sudden change. What Bits is asking is where do you start figuring out what those three multipliers are for the P, I, and D terms. It can be done theoretically if you know stuff like how fast your heater adds energy, how fast heat is lost through insulation, and if there are any delays or other factors. But for many years this "PID tuning" has also been done by seat of the pants estimation, which works even if you don't have a computer and don't understand Calculus.

SONIC the Hedgehog

02-09-2012, 10:49 PM

Yeah I read about the errors. Wikipedia said that after each cycle the PID will try to correct th error as much as it can. Ah I get it, thanks a bunch, and I might have to start my own project like that.

localroger

02-10-2012, 02:10 AM

I have a coworker who recently used a commercial PID control board and a few hundred bucks worth of OTS parts to build his father a power steering rig for his speedboat; his father's disabled and has little upper body strength, so L built him a rig where he can steer the boat by twiddling a potentiometer. His math not extending much beyond Algebra I he read the instructions and hand-tuned the PID controller. He sent me a video of his Dad tooling around Mobile Bay looking happy as a clam that he can still go fishing.

SONIC the Hedgehog

02-10-2012, 02:27 AM

That's very innovative! So with simple math routines can be calculated and then the proper results would be achieved? That sounds very simple.

$WMc%

02-10-2012, 02:31 AM

It takes a whole lot of understanding to figure out PID.

'

It will come to you.

'

Be patient.

SONIC the Hedgehog

02-10-2012, 02:34 AM

Thank you for your teachings Jedi master, I'm sure Bits will learn a lot.

Lawson

02-10-2012, 06:59 AM

How to tune P, I, and D in a PID loop? First start with things they effect directly, like disturbance rejection and system noise. But even that is getting ahead of myself, the zeroith thing to do is to put real meaningful units on every quantity in the servo loop. For a thermal system Kp will have units of [watts/degree] Kd will have units of [watts/ (degree/second) ] Ki will have units of [watts / (degree-second)] and so on. It just so happens that Kp has the units of thermal conductance and acts EXACTLY like you had a physical thermal bridge to a heat source at the set-point temperature. Similarly simplifying the units of Kd get you [Joule/degree] which has the units of heat capacity. Ki doesn't really have a physical equivalent, but engineering units still make it's effects easier to quantify.

Cranking Kp till the system oscillates is a good starting point, but you can likely further double Kp if you add enough Kd. (with mechanical positioning systems often Kp can be quadrupled or more this way) What's the cost of high Kp and Kd? System noise and idle power consumption. I.e. the derivative term acts as a high-pass filter so it has it's largest effect at high frequencies where the signal to noise ratio is often low. Note: to use a large Kp you NEED a similarly large Kd term otherwise the system will have a high frequency resonance where it's easy to disturb the system. (in the case of a thermal system, the physics provides a lot of Kd on it's own, so this term can often be dropped) What's the gain with high values of Kp? Rejection of external disturbance at middle frequencies and the ability to use larger values of Ki for enhanced DC and low frequency disturbance rejection. Indirectly, a large Kp also accelerates command response. (with just Kp and the system model it's also pretty easy to calculate how much an external heat source will effect the temperature of the system, aka disturbance rejection) Also, Ki gain does NOT like infeasible commands. If you give the thermal system a step temperature command, Ki WILL cause overshoot. If you instead use a smooth ramp command, Ki won't cause overshoot but will reduce tracking error during and after the ramp. After all this, you're pretty free to choose Kp, Ki, and Kd. It's common for useful stable values of these gains to cover several orders of magnitude and because of this, changes to gains smaller than 2x are rarely worth the trouble.

If command response is your goal it's better to use a system model to construct a FeedForward controller. (aka an open-loop controller run in parallel with the PID loop) Something as simple as multiplying the rate of command temperature change by the heat capacity of the thermal system can really speed up command response. A FeedForward controller does requires feasible commands, aka commands that stay within the physically limited capabilities of your system. I.e. no temperature steps, as these require many Joules of energy to be added instantly, something not physically practical.

Lawson

P.S. The accumulation and difference terms used by computers to approximate integration and differentiation are approximations. When operating near the sample frequency of the the servo loop, the error in these approximations becomes significant, and will show up in the dynamics of the system.