pidtuner / pidtuner.github.io

Free PID Controller gains tuning tool
GNU General Public License v3.0
243 stars 29 forks source link

How to tune a Soft-PWM tuned heater behind an SSR #13

Open Apehaenger opened 1 year ago

Apehaenger commented 1 year ago

Quite thanks for the cool pidtuner.com website as well as this project.

I'm trying to find good PID constant for a PID controller who's output goes into an software-PWM which in turn drives a SSR who's switching a heater. So in real the PID output value controls the on/off pulse of the SSR.

In my specific case I use a PWM Window of 5000ms which mean the PID will output values from 0 to 5000.

Now I tried to find good PID values with the help of this cool tuner here, but I get useless results.

First of, I tried to feed PID Tuner's input with the state of the SSR, so 0=off, 1=on (with a quite fast data input rate of approx. 500ms so that I get a good resolution). PID Tuner find a good Model but the estimated PID constants are below 0.0...

After reading the very detailed and good PDF, which clearly states that PID Tuners input hast to be exactly PID Controllers output, I fed PID Tuner input with the expected PID controller output (PWM input). In practice this is a couple of 5000 (max PWM windows size) over a period of some seconds and than a loooot 0 for the settle time phase (this is how I understood how to do the "step test").

The resulting calculated PID Model looked nearly perfect and the calculated pid values also looked better (i.e. Kp 190, Ki 5, Kd 1200).

But after checking these values in practice, I wasn't very happy with the result.

For testing purposes, I simply divided the PID Tuner input values by 2 and PID Tuner calculated me approx. 1/2 of the PID constants.

This is not realistic, which shows me that I either input the wrong values into PID Tuner or that I do have to input other data in my special case where I drive an PWM behind a PID.

Anybody who can point me my mistake?

BTW: Posted here because PID Tuners Forum didn't let me register :-(

pidtuner commented 1 year ago

that PID Tuners input hast to be exactly PID Controllers output

This is correct

But after checking these values in practice, I wasn't very happy with the result

Without knowing what is your PID implementation and without looking at your data, it is hard to know what is the root cause, it might be that your PID is non standard with non standard gains, or contains some filter or what not.

It could also be your PWM is introducing some nonlinearities, or the period of the PWM is not the best choice. Still, the pidtuner gives you a start point at which you can start tuning further, either manually or playing with the pidtuner slider.

BTW: Posted here because PID Tuners Forum didn't let me register

The forum has a whitelist of allowed email domains (gmail, etc.) because I was receiving a lot of spam registrations from dummy domains.

Apehaenger commented 1 year ago

Hi pidtuner!

Quite thanks for answering!!

For sure I need to give you some more details.

I try to use your PID Tuner for my Another-HotPlate-Firmware project (The PID stuff is in dev branch, Hotplate.cpp. The implementation is mainly Arduino -> PID Controller -> Soft-PWM -> SSR -> PC Hotplate

I use r-downing's AutoPID, but with changed/fixed derivate calculation https://github.com/Apehaenger/AutoPID/compare/r-downing:AutoPID:master...master (here's a issue conversation about the calculation https://github.com/r-downing/AutoPID/issues/4), but surely I can also switch to Brett's much praised PID implementation if you're in doubt of r-downing's calculations.

During initial tests I decided somewhen for a 5000ms PWM Window (as well as max. PID output), and a 250ms PID sample time. I'm fully unsure if it was a good decision, but due to the high system (PTC & K-Thermocouple) delay, I thought I need a relative huge PWM window. Well it's not hammered in stone, if you've better recommendation I would highly appreciate to hear them ;-)

It's fully clear to me that PID Tuner "only" gives a first estimation, but due to the fact that your PID Tuner already calculates nearly perfect models (also for the Hotplate) I have the hope on finding a way to best fit PID calculation/modeling.

Lastly, here's my latest

PID Tuner data import:

73.09, 0.00, 24.36
73.62, 0.00, 24.41
74.13, 0.00, 24.34
74.65, 0.00, 24.46
75.17, 0.00, 24.51
75.69, 0.00, 24.55
76.19, 0.00, 24.66
76.73, 0.00, 24.61
77.23, 0.00, 24.58
77.73, 0.00, 24.53
78.28, 5000.00, 24.53
78.78, 5000.00, 24.61
79.28, 5000.00, 24.71
79.86, 5000.00, 24.76
80.36, 5000.00, 24.91
80.94, 5000.00, 24.85
81.44, 5000.00, 24.87
82.02, 5000.00, 25.01
82.52, 5000.00, 25.24
83.02, 5000.00, 25.63
83.63, 5000.00, 25.95
84.13, 5000.00, 26.73
84.69, 5000.00, 27.24
85.19, 5000.00, 27.96
85.76, 5000.00, 29.29
86.29, 5000.00, 30.27
86.79, 5000.00, 31.93
87.36, 5000.00, 33.19
87.86, 5000.00, 35.22
88.44, 5000.00, 36.68
88.94, 5000.00, 38.21
89.51, 5000.00, 40.70
90.05, 5000.00, 42.32
90.55, 5000.00, 44.99
91.12, 5000.00, 46.80
91.66, 5000.00, 49.57
92.20, 5000.00, 51.48
92.70, 5000.00, 53.48
93.27, 5000.00, 56.46
93.81, 5000.00, 58.47
94.31, 5000.00, 61.54
94.88, 5000.00, 63.65
95.38, 5000.00, 66.83
95.96, 5000.00, 68.94
96.46, 5000.00, 71.00
97.04, 5000.00, 74.06
97.54, 5000.00, 76.22
98.04, 5000.00, 79.27
98.63, 5000.00, 81.27
99.13, 5000.00, 84.38
99.70, 5000.00, 86.37
100.20, 5000.00, 88.41
100.78, 5000.00, 91.30
101.31, 5000.00, 93.36
101.81, 5000.00, 96.18
102.39, 5000.00, 98.00
102.89, 0.00, 100.84
103.47, 0.00, 102.63
103.97, 0.00, 104.44
104.54, 0.00, 107.10
105.04, 0.00, 108.93
105.62, 0.00, 111.55
106.15, 0.00, 113.12
106.69, 0.00, 115.56
107.22, 0.00, 117.22
107.72, 0.00, 118.77
108.28, 0.00, 121.03
108.82, 0.00, 122.53
109.32, 0.00, 124.52
109.88, 0.00, 125.83
110.38, 0.00, 127.55
110.96, 0.00, 128.81
111.46, 0.00, 129.92
111.96, 0.00, 131.67
112.56, 0.00, 132.66
113.06, 0.00, 134.16
113.64, 0.00, 135.10
114.14, 0.00, 135.93
114.71, 0.00, 137.03
115.23, 0.00, 137.67
115.73, 0.00, 138.46
116.29, 0.00, 139.02
116.79, 0.00, 139.84
117.37, 0.00, 140.26
117.87, 0.00, 140.71
118.45, 0.00, 141.31
118.98, 0.00, 141.66
119.48, 0.00, 142.16
120.04, 0.00, 142.46
120.54, 0.00, 142.90
121.11, 0.00, 142.97
121.65, 0.00, 143.37
122.19, 0.00, 143.42
122.73, 0.00, 143.53
123.23, 0.00, 143.57
123.82, 0.00, 143.55
124.32, 0.00, 143.69
124.89, 0.00, 143.84
125.39, 0.00, 143.84
125.97, 0.00, 143.90
126.47, 0.00, 143.75
127.04, 0.00, 143.75
127.57, 0.00, 143.75
128.07, 0.00, 143.72
128.65, 0.00, 143.73
129.15, 0.00, 143.50
129.74, 0.00, 143.46
130.24, 0.00, 143.43
130.82, 0.00, 143.29
131.32, 0.00, 143.18
131.82, 0.00, 143.00
132.41, 0.00, 142.86
132.91, 0.00, 142.52
133.48, 0.00, 142.42
133.98, 0.00, 142.12
134.54, 0.00, 142.07
135.04, 0.00, 142.01
135.62, 0.00, 141.76
136.16, 0.00, 141.54
136.69, 0.00, 141.26
137.23, 0.00, 141.06
137.73, 0.00, 140.90
138.30, 0.00, 140.66
138.80, 0.00, 140.51
139.30, 0.00, 140.17
139.91, 0.00, 140.06
140.41, 0.00, 139.86
141.00, 0.00, 139.68
141.50, 0.00, 139.28
142.07, 0.00, 138.99
142.57, 0.00, 138.94
143.07, 0.00, 138.46
143.66, 0.00, 138.25
144.16, 0.00, 138.02
144.74, 0.00, 137.75
145.24, 0.00, 137.47
145.81, 0.00, 137.30
146.31, 0.00, 137.14
146.81, 0.00, 136.81
147.42, 0.00, 136.56
147.92, 0.00, 136.40
148.49, 0.00, 136.17
148.99, 0.00, 135.91
149.55, 0.00, 135.71
150.05, 0.00, 135.56
150.64, 0.00, 135.42
151.18, 0.00, 135.18
151.72, 0.00, 135.09
152.26, 0.00, 134.93
152.76, 0.00, 134.67
153.33, 0.00, 134.51
153.83, 0.00, 134.33
154.40, 0.00, 134.08
154.95, 0.00, 133.87
155.45, 0.00, 133.61
156.02, 0.00, 133.30
156.52, 0.00, 132.97
157.08, 0.00, 132.71
157.62, 0.00, 132.48
158.12, 0.00, 132.08
158.68, 0.00, 131.95
159.18, 0.00, 131.66
159.75, 0.00, 131.51
160.25, 0.00, 131.09
160.82, 0.00, 130.98
161.32, 0.00, 130.90
161.82, 0.00, 130.46
162.43, 0.00, 130.33
162.93, 0.00, 129.83
163.50, 0.00, 129.67
164.00, 0.00, 129.61
164.58, 0.00, 129.38
165.08, 0.00, 129.23
165.66, 0.00, 128.96
166.20, 0.00, 128.79
166.70, 0.00, 128.38
167.27, 0.00, 128.29
167.77, 0.00, 128.15
168.33, 0.00, 127.73
168.85, 0.00, 127.65
169.35, 0.00, 127.40
169.91, 0.00, 127.21
170.41, 0.00, 126.99
170.99, 0.00, 126.78
171.49, 0.00, 126.59
171.99, 0.00, 126.32
172.57, 0.00, 125.94
173.07, 0.00, 125.66
173.65, 0.00, 125.51
174.15, 0.00, 125.29
174.71, 0.00, 125.06
175.25, 0.00, 124.90
175.75, 0.00, 124.71
176.31, 0.00, 124.50
176.81, 0.00, 124.16
177.39, 0.00, 124.01
177.89, 0.00, 123.83
178.47, 0.00, 123.60
179.00, 0.00, 123.43
179.50, 0.00, 123.27
180.07, 0.00, 123.00
180.57, 0.00, 122.79
181.13, 0.00, 122.68
181.66, 0.00, 122.48
182.16, 0.00, 122.31
182.74, 0.00, 121.96
183.24, 0.00, 121.77
183.80, 0.00, 121.59
184.30, 0.00, 121.47
184.80, 0.00, 121.36
185.38, 0.00, 121.14
185.88, 0.00, 120.93
186.46, 0.00, 120.73
186.96, 0.00, 120.47
187.52, 0.00, 120.09
188.06, 0.00, 119.87
188.56, 0.00, 119.52
189.12, 0.00, 119.39
189.66, 0.00, 118.99
190.19, 0.00, 118.95
190.69, 0.00, 118.83
191.19, 0.00, 118.58
191.79, 0.00, 118.41
192.29, 0.00, 118.04
192.85, 0.00, 117.88
193.35, 0.00, 117.79
193.85, 0.00, 117.42
194.44, 0.00, 117.19
194.94, 0.00, 116.89
195.49, 0.00, 116.69
195.99, 0.00, 116.47
196.49, 0.00, 116.22
197.06, 0.00, 115.96
197.56, 0.00, 115.70
198.12, 0.00, 115.62
198.65, 0.00, 115.53
199.15, 0.00, 115.43
199.70, 0.00, 115.27
200.20, 0.00, 115.00
200.78, 0.00, 114.83
201.28, 0.00, 114.66
201.78, 0.00, 114.48
202.37, 0.00, 114.31
202.87, 0.00, 113.86
203.45, 0.00, 113.76
203.95, 0.00, 113.63
204.50, 0.00, 113.58
205.04, 0.00, 113.36
205.54, 0.00, 113.23
206.09, 0.00, 113.06
206.63, 0.00, 112.87
207.16, 0.00, 112.78
207.69, 0.00, 112.60
208.19, 0.00, 112.26
208.75, 0.00, 112.25
209.25, 0.00, 112.13
209.82, 0.00, 111.90
210.33, 0.00, 111.75
210.83, 0.00, 111.60
211.39, 0.00, 111.47
211.89, 0.00, 111.48
212.39, 0.00, 111.40
212.98, 0.00, 111.25
213.48, 0.00, 110.97
214.04, 0.00, 110.68
214.54, 0.00, 110.72
215.04, 0.00, 110.68
215.62, 0.00, 110.62
216.12, 0.00, 110.33
216.68, 0.00, 110.21
217.18, 0.00, 110.08
217.68, 0.00, 109.79
218.27, 0.00, 109.63
218.77, 0.00, 109.52
219.34, 0.00, 109.42
219.84, 0.00, 109.35
220.42, 0.00, 109.13
220.92, 0.00, 108.91
221.42, 0.00, 108.53
221.92, 0.00, 108.47
222.47, 0.00, 108.21
222.97, 0.00, 107.94
223.54, 0.00, 107.91
224.04, 0.00, 107.69
224.62, 0.00, 107.53
225.12, 0.00, 107.43
225.68, 0.00, 107.31
226.22, 0.00, 107.15
226.72, 0.00, 106.91
227.29, 0.00, 106.77
227.79, 0.00, 106.61
228.38, 0.00, 106.51
228.88, 0.00, 106.42
229.47, 0.00, 106.11
230.00, 0.00, 105.97
230.50, 0.00, 105.77
231.07, 0.00, 105.64
231.57, 0.00, 105.32
232.13, 0.00, 105.25
232.67, 0.00, 105.12
233.22, 0.00, 104.81
233.72, 0.00, 104.74
234.22, 0.00, 104.61
234.72, 0.00, 104.52
235.26, 0.00, 104.43
235.76, 0.00, 104.25
236.33, 0.00, 104.21
236.83, 0.00, 103.96
237.41, 0.00, 103.82
237.91, 0.00, 103.62
238.49, 0.00, 103.39
239.03, 0.00, 103.30
239.53, 0.00, 103.19
240.09, 0.00, 103.08
240.63, 0.00, 102.82
241.18, 0.00, 102.66
241.72, 0.00, 102.43
242.26, 0.00, 102.33
242.76, 0.00, 102.30
243.26, 0.00, 102.18
243.84, 0.00, 102.12
244.34, 0.00, 101.73
244.90, 0.00, 101.74
245.42, 0.00, 101.65
245.92, 0.00, 101.29
246.47, 0.00, 101.23
246.97, 0.00, 101.05
247.53, 0.00, 100.76
248.03, 0.00, 100.61
248.63, 0.00, 100.37
249.17, 0.00, 100.23

pidtuner commented 1 year ago

By looking at your data I can tell your process is quite nonlinear, given the fact that it actuates only in one direction. This is common in temperature control loops where you can only heat up but not cool down.

Also this kind of control loop is of integral nature, so you should select an integral model (not first order, nor second order), so either choose integrator or integrator with lag (if your process does have lag).

I assume that with "nearly perfect models" that you took all data for identification and obtained the following model: image

Which gives the following initial gains:

image

I understand the temptation to choose the whole data to fit a model in the pidtuner, but this is a common mistake, one must understand the nature of the process before trying to control it. I do not have full knowledge of your process, but knowing that is a temperature control loop, I would use just the first step data to obtain an integrator with lag model:

image

Which gives these gains:

image

Then I would start tuning further from there, moving the slider to the left if the control is too aggressive or to the right if I think the process can handle it..

Apehaenger commented 1 year ago

Quite thanks for your detailed answer an explanation.

In special the description/recommendation about the preferred models for my temperature control process is very helpful for me, as well as evaluating only the first step.

I'll do some tests the next days.

Is there anything I can optimize when generating the PID Tuner input, which would lead to better findings? Like multiple steps (i.e. for easier comparison, or some kind of manual average calculation) At the moment i.e., I generate the PID Tuner input data by setting the max. PID Output till a setpoint of 100°C is reached and then wait (collect data) till the temperature settles to that setpoint. If only the first step is interested (from my last sample), which is (when I interpret it right), only the heating period and not the settle-to-setpoint period, I probably only need to wait till "max temperature minus i.e. 10°C settle" time is reached.

Would a second step be useful for better findings? i.e. when using the average of two steps? Or is it a dump question of an unlucky PID unillumined? ;-)

During our conversation I got also in doubt if my huge PID window selection has been clever. Will test that also with much smaller windows.

Will keep you informed about my findings ;-)