-
Notifications
You must be signed in to change notification settings - Fork 52
PID tuning
PID tuning can be quite complicated. We have few PID factors to consider and our expectations to the process. First you should know a bit about PID algorithm - there is plenty of papers and YT videos on the topic. You could also read few short documentation from the PID library author.
Then you can prepare yourself a quick test environment, as described here and start experiment. This is just an approximation of your target environment so don't expect to find proper values here and moved them to production.
I would recognize three types of variables here:
This are depending on your environment, and physical components, like how big your kiln is and how long heat distribution inside takes. This will make response PID value delayed in time, and the algorithm will "see" results of it's working also with delay making it prone to overshoot the temperature. So the closer the thermocouple is, to heating element, the faster response is going to be. But then, on the other hand, you are unable to control temperature in entire kiln and you have to consider longer dwell time to distribute heat evenly.
Also there is a question of your heating element, does it produce heat proportional to time (and this is also almost never the case) or only in really narrow time window.
Keep in mind that (usually) we control only the heating process, we don't have any impact on cooling one. So if you prepare program, you need to do it with yours environment physical parameters in mind. So if you need to have cooling step in the program, you have to make it long enough to actually allow naturally to cool down of your kiln chamber, otherwise (if the next step is to heat it up again) it may never reach desire temperature.
Since, by default, controller is not waiting to reach desire temperature, it tries - but if the heating element is to weak or program too demanding, may never reach it. So this is also something to keep in mind when designing program. Usually it's better to go slow and then eventually speed things up.
There is an additional parameter (not being a part of PID algorithm) "PID_Temp_Threshold" that is design to force reaching designed temperature. When set temperature (SV) - PID_Temp_Threshold is bigger then current temperature (PV) controller will wait. It will go in to dwell mode with current settings (this is not the same as program dwell). But this may slow program running quite a lot and with wrong settings may hang process in dwell mode indefinitely (if heater is unable to reach desire temperature). But if you require going close to program temperature, and time is less important - this may be for you.
You probably know how your heating should look like. And you know if you want to reach desire temperature as fast as possible (and probably agree to large overshoot) or you want to never go above desire temperature. Are you able to tolerate temperature fluctuation, or this should go precisely as planned in program. This are really important vectors to consider when preparing PID values.
Large, temperature overshoot - may brake your work:
Finally we have PID itself. It's easy to steer it, in the way where it simply won't work. Here is and example of poorly chosen parameters:
Red line (measured temperatures) does not raise as expected.
In PID algorithm we have three values to steer it Kp, Ki, Kd (and that's why it's PID). We can also change (for currently used PID library) to Proportional on Measurement (PoM) or Proportional on Error (PoE) behaviour. There is also build in PID Window divider (this was not my intention to steer PID itself with it - but it happens to help here also) value in PIDKiln.h - this will speeds up/inflate PID responsiveness a lot.
This is, by no any means, explanation of PID, but easy way to imagine how it may work:
- Kp - this is proportional part of PID algorithm where error (SV-PV) is multiplied by Kp. This value is calculated without "memory" of the past - so is will only try to minimize current error and will not be able to stabilize temperature (assuming there is some inertia of heating vs probing). When Kp is too small, it may never be able to reach desire temperature.
- Ki - this is most important parameter for us, it will calculate value based on current and past error. So it will grow exponentially. It controls how fast we can acquire desire temperature and usually how much we will overshoot it.
- Kd - this part of PID is responsible for preventing any fluctuations (or measurement errors) and enables faster temperature stabilization.
Here are few examples with comments and put all measurements together on a single graph.
Test naming convention is: PoM or PoE _ divider _ Kp,Ki,Kd
This is an example of tuning where we don't wont to go above desire temperature. We can see that PID is unable to follow program, but if we would extend expected program time - it could be perfect fit. Notice, there is 10 times "divider" here and Kp=20 Ki=0,2 Kd=0,1.
This is the test with the same parameters as above (20;0,2;0,1) but without divider value. You can see here, that PID is to slow to reach desire temperature. Just when it could reach 45C, program started to lower temperature down and test environment never reached it.