PID Autotune  - Page 1
Forum section: electronics / projects

author: cmk
author_rank: Newbie
timestamp: August 13, 2015, 02:51:23 am
content: Hi Guys! I'm doing my final project, it's temperature measurement and control on PIC16f877, for the measurement i use PT100 sensor, i manage go implement on/off, fuzzy, and PID control, but now i'm thinking about putting some code for Auto-tuning the PID, searching the net for the algorithms or some examples i wasted a lot of time and did not find anything straightforward, if anybody of you has any idea or experience in this subject please share i would be very thankful!regards

author: retrolefty
author_rank: Super Contributor
timestamp: August 13, 2015, 03:09:39 am
content: Quote from: cmk on August 13, 2015, 02:51:23 am'Fuzzy' and auto-tune are pretty much proprietary in the industry it's aimed at.

author: hendorog
author_rank: Super Contributor
timestamp: August 13, 2015, 03:35:17 am
content: 3d printer firmware contains autotune routines for the extruder temperature PID control, and is open source and generally targets Arduino. You can probably find something useful in there. It works pretty well.Here is a one:https://github.com/MarlinFirmware/Marlin

author: hendorog
author_rank: Super Contributor
timestamp: August 13, 2015, 04:57:06 am
content: Some more details here - including how the PID parameters used relate to the ones from commercial controllers:http://reprap.org/wiki/PID_Tuning

author: Kleinstein
author_rank: Super Contributor
timestamp: August 13, 2015, 07:41:24 am
content: There are different types of autotune:The simple form that most commercial controllers support is to more or less automate the classical tuninig methods or variations of them. So one needs a tuning phase to adjust the controller. The controller here does some tests to get the system properties and calculates suitable PID parameters from that. After that the PID controller runs on fixed parameters.Modern controllers may have more than just the classic 3 PID parameters: there is allways a 4 th paramter (though sometimes fixed) to controll the high frequency rollof of the I and D part - pure PID just can't exist in real world. If fast reaction to setpoint changes is needed there is often some form of setpoint feed forward with maybe 1 or 2 more parameters to adapt.The more difficult thing is contineous autotune. Here initial parameters are often determined similar to the method above just with less required accuracy. Later the controller adjusts its pararameters during normal operation. Here much is proprietry or patented technology, some of this can be found in advanced controll theoriy articles, but often only the general princlple not much details, or in a very mathematical and theretical form. I know of three different methods, but little details:1) Add a small test signal to the output and use this to measure the system. Here a low bandwidth alows very small amplitudes close to normal noise. In the extreme case this could be quantisation steps of the output. Here it's a balance between extra noise and how fast the system can adapt.2) Use the reaction to changes in setponts during normal operation to learn about the system. This requires enough and preferrable fast changes in setpoint.3) Run the PID controller with slightly varying parameters and compare noise and other measures of quality of regulation as a function of settings. Here the assumption is that the system is not changing fast.

author: cmk
author_rank: Newbie
timestamp: August 13, 2015, 11:40:23 pm
content: Quote from: hendorog on August 13, 2015, 03:35:17 amthank you, i finally have some clue to start working from!!

author: f5r5e5d
author_rank: Frequent Contributor
timestamp: August 13, 2015, 11:52:36 pm
content: sometimes its worth buying or borrowing the bookhttp://www.amazon.com/PID-Controllers-Theory-Design-Tuning/dp/1556175167

author: IanB
author_rank: Super Contributor
timestamp: August 13, 2015, 11:53:23 pm
content: Tuning of PID controllers depends on the control objectives. For example servo controllers will often be tuned differently from regulatory controllers. Some controllers may emphasize close tracking of the set point, while others may try to minimize large swings in the manipulated variable. Auto tuning algorithms must therefore be given control objectives to meet. There is no single best tuning.

author: hendorog
author_rank: Super Contributor
timestamp: August 14, 2015, 12:11:39 am
content: QuoteYou are welcomeThis is the relevant file.https://github.com/MarlinFirmware/Marlin/blob/Release/Marlin/temperature.cppQuoteI think its the D part which is a problem with a noisy input. I think the code implements some averaging which effectively low pass filter's the temperature. That will reduce the input noise appearing in the control signal on the output.

author: ywara
author_rank: Contributor
timestamp: August 14, 2015, 01:36:08 am
content: PID autotune in low-cost COTS parts generally use the relay method. Most autotune algorithms are quite bad. Generally they are far too aggressive for typical algorithms.

author: cmk
author_rank: Newbie
timestamp: August 14, 2015, 03:07:14 am
content: Quote from: ywara on August 14, 2015, 01:36:08 amI use double output on my project, one is Relay and the other is Triac, i understand very well that autotune won't do any magic, but at least it will get you somewhere, so you can try to fine-tune by trial and error, if it does not work you can always do it by some of the proven methods....

author: cmk
author_rank: Newbie
timestamp: August 14, 2015, 03:21:53 am
content: Quote from: hendorog on August 14, 2015, 12:11:39 amyes i've seen the file, it was easy to find, now am looking in the equation, and trying to figure out how is this going to work, as far as i can understand in 3d printers there are 2 variables controlled via PID method, one is the speed of cooling fans an the other is the power delivered to the heater (i might be wrong here).Am not very worried about for the D part, if it causes a lot of trouble i will dump it and stick only with PI method for controlling.thank you again, this was very helpful.

author: hendorog
author_rank: Super Contributor
timestamp: August 14, 2015, 03:41:06 am
content: QuoteYep, there are two PID controlled outputs in 3d printers, one is the heated bed (the flat printing platform) and the other is the extruder heater which squirts out the plastic itself.The fan is normally a separate thing and is just there to quickly solidify the printed plastic so that a new layer can be immediately placed on top - good for printing a slim tall tower for example.The platform is heated to stop warping - as the layers build up the higher layers shrink and it causes the part to warp. Heating the platform helps to reduce that effect.

author: Smokey
author_rank: Super Contributor
timestamp: August 14, 2015, 04:44:12 am
content: Two great books areComputer controlled systems by astromAndControl system design guide by ellis

author: retrolefty
author_rank: Super Contributor
timestamp: August 14, 2015, 01:30:50 pm
content: Quote from: ywara on August 14, 2015, 01:36:08 amThis is very true. However there are always exceptions, especially with temperture control on with very slow process times (large vessels, etc) where the auto-tune will have a much better chance at finding a workable D product.

author: Kleinstein
author_rank: Super Contributor
timestamp: August 14, 2015, 06:21:57 pm
content: How good autotune usually works, depends on how good the system is represented by the model used in the autotune algorithm. Usually a model of the sytem is assumed, the model parameters are determined from measurements and than PID paramters are calculated based on the model parameters. This may not be explicites, but most tuning rules are developed with a certain model of the system. The important part often missing is checking if the system is well represented by the model - if not a different set of tuning rules (formulars) should be used.In large slow thermal systems one often has nearly PT1 behaviour and thus relatively easy tuning. These systems also need a good tuning and profit from a rather aggressive tuning. With smaller faster systems there often is comparative more deadtime (e.g. from extra delay, e.g. from mounting the sensors, or inside heaters). These systems are more difficult to regulate and may need a different model and thus different tuning rules.

author: Smokey
author_rank: Super Contributor
timestamp: August 14, 2015, 07:04:24 pm
content: Quote from: retrolefty on August 14, 2015, 01:30:50 pmLike has been mentioned up thread, derivative is tricky. Basic 101 textbook PID derivative calculation is inherently a noise amplifier and most likely will make your system unstable. It's better to skip the D and just go PI unless you have an algorithm that specifically addresses the problems with basic D.

author: Korken
author_rank: Regular Contributor
timestamp: August 14, 2015, 08:44:25 pm
content: If you are going to go for auto tuning then you might just as well go for a simple linear model identification and a Model Predictive Controller (PID autotuning usually only moves the poles to desirable locations but the effect of zeros are ignored, impacting performance).They are somewhat computationally complex but do "tuning" intrinsically since it is based on the model and the control is found solving an optimization problem.A control/prediction horizon of 2 usually suffices for temperature control unless you have a very advanced model for the losses.Using linear models I once implemented one on an AVR with 3 step prediction and float emulation, was enough for 5 Hz.Oh, and the MPC is much more intuative to use as it represents the problem in the time domain and not the frequency domain, so the notion of poles and zeroes does not apply.