colinl / node-red-contrib-pid

A node-red PID loop controller node intended for the control of real world processes
Apache License 2.0
26 stars 18 forks source link

Integral always locked #21

Closed Vartkat closed 11 months ago

Vartkat commented 1 year ago

I surely need some help as I tried a lot fo value combinaisons during the last 15 days.

Here is the story, a large 9000 sq feet warehouse with a roof begining at 21 feet and at the top about 40 feet. Two temperature censors one at human level the other one in the rafters. Two 12 feet huge Big Ass Fans (that's the brand).

Fans are there to push heat from the rafters to human level. I'm trying to keep a difference of 2 degrees between rafters and the ground.

image

After many tryouts I came to max out the fans speed at 40%. Means when the PID is at 1, the fans runs at 40%, that's the best value I managed to get.

Setpoint is 2 (of course I'm feedinf the PID with the difference value) Prop band is -1.65 (positive values were not working) Integral time is 720 sec (12 min) Derivative time is 120 (2 min) and Max interval is 900 (15 min) Smoothing is at 60.

Censors are giving values every 10 sec, but I limited the PID output rate at 1 value evry 2 min cause it was doing too many on/off.

image

As you can see, it's not bad but not a nice smooth curve as what we're suppose to get from a PID (as far as I understood). Is that the best I will get or is there any way to : 1- not have a PID locked ( as I understood this is not good, even if it seems to work) 2- achieve to get a smooth curve with no off but a variation of speeds to maintain the temp difference at 2 degrees.

Thanks for your help

Vart

colinl commented 1 year ago

Hi @Vartkat. It is clear from the graph that the loop is not working correctly. The fan speed should not be leaping about like that.

I limited the PID output rate at 1 value evry 2 min cause it was doing too many on/off.

The solution to that is to tune the loop correctly, not to do things like that. Did you see my guide to loop tuning linked from the node's readme? http://blog.clanlaw.org.uk/pid-loop-tuning.html

Firstly, to make sure I understand, does increasing the fan speed increase the temperature difference or decrease it? I cannot make sense of the graph. Can you show one with just the fan percent and temperature diff please. With them lined up, obviously.

Vartkat commented 1 year ago

Thanks for the quick answer.

Yes I saw the your guide but couldn't understand it, surely beacuse I have not access to Node Red Dashboard as I am using NR in Home Assistant. But I read quite a few tutorials and watch 4 or 5 videos explaining things I must confess I didn't completly understood.

As heat always naturally goes up rafters are always hoter than ground if we do nothing. Fans are supposed to push heat toward the ground and decrease the difference. But things are not so obvious, if we blow too much air hot air goes down and goes back up, if we blow air too fast physics says we're warming air as moving particules are getting hotter (I'm not sure this in relevant in this case cause the temp increase of moving air must be very small). Whatever, even if people on the ground says that moving air give them cool breeze sensation it's not cool, the air they receive is hotter by a few degrees.

image

This is on 12 h, up graph reads the raw difference, lower graph fan speed BUT sometime the fan is off, that's the red part on the middle bar. As the difference is not really readble I asked Grafana to give me means of the difference.

image

This one show mean on 5min

image

And this one mean on 15 min.

colinl commented 1 year ago

OK, so increasing the fan speed should reduce the difference. By default the PID node assumes that it is a heating type process, where increasing the pid node output will increase the process value. In your case it is the other way round, so the first thing to is to invert the sense of the output. In addition you said you wanted to limit the fan to 40%, so you want the fan output to be 40% when the pid output is 0 and 0% when the output is 1. You can do that easily with a Range node set to map the input range 0 to 1 to the target range 0.4 to 0. Next we need to get a feel for the speed and gain of the process. To do that, set the derivative time to 0 and the integral time 9999 (which means they will do very little), and set the proportional band to 0. That will put the loop into on/off control, so if the temperature difference is less that 2 the fans should be off, and if greater than 2 the fans should be on (at 40%). The result should be that the difference should oscillate about 2, with the fans going on and off as the difference goes up and down around 2 degrees. Let that run for a couple of cycles and post the chart showing the temperature difference and fan power.

Vartkat commented 1 year ago

Thanks. Inverting the PID output should be a key point. As the value was already around 0.5 I've set Setpoint to 0.5 (to not wait for hours) all others values as you said.

Raw output (temp values every 10 sec is not really readable) :

image

Note that fan speed rate is set to 1 every 30sec (more often does so many on/off that I fear it will break the fans).

To make it more readable I've asked to mean temp difference on 5min wich give this graph :

image

If I follow your tutorial, I should look to duration between the time the curve crosses 0.5 and the next peak, but in this case the next down peak (as we inverted the logic ). Is that right ?

If so I get various durations and overshoots, here is what I can measure : image

colinl commented 1 year ago

Have you got grafana interpolating fan speed? It should show as a square wave as it should only ever be 40% or off.

Since the temperature changes over just a few minutes you need to set the pid to run at the 10 second rate. Leave the integral and derivative as they are for the moment, and set the proportional band to (plus) 1 and see what happens then.

Vartkat commented 1 year ago

Done...

image
colinl commented 1 year ago

Why have you posted that? The problem with the graph is that grafana is interpolating the values. If you configure the chart to show staircase mode then that will stop that. You will then be able to see the actual data points.

Vartkat commented 1 year ago

Sorry, here is the graph for the time I posted the values without interpolation...

image
Vartkat commented 1 year ago

Since I changed the values, i.e. since 20min the fan doesn't stop even if the temperature difference is under 0.5...

image
colinl commented 1 year ago

Don't smooth the temperatures out, show us the real values. Set the integral time to 5 minutes. Also please plot the values you are feeding into the pid

Vartkat commented 1 year ago

Real values...

image

Note that sensors are DHT22 which has a precision of 0.2 so we are within this precision

colinl commented 1 year ago

Is the green line the actual values that are being fed into the pid node? Set that to staircase mode too please. Is the red line the value directly as it comes out of the pid node? Those are the two values I would like to see. Something there doesn't make sense. Have you set the integral time to 5 minutes now?

Vartkat commented 1 year ago
image

Second blue bar is Prop ban =1 second is Integral =5 min (300). Note that the PID node still says locked and fan never stops... The vlaues fed to the PID node are the one you can read on the right scale.

colinl commented 1 year ago

I need to see the value coming out of the pid node too. But if the fan is on then the difference should come down, but it is going up.

Vartkat commented 1 year ago

That's the point, if fans are blowing too long temperature difference is going back up. I've implemented the pid value in the graph, for now as you can expect, as fan is at its max pid value is 0. Let's wait a few to see if it changes anything (and to see the value on the graph)....

colinl commented 1 year ago

Please Export the flow around the pid node, including the sensors and the fan control, so I can see exactly what the code is doing. Set the proportional band to 10, then if the output still sits at zero there is something wrong somewhere. I am on the road for a few days so my feedback posts may be reduced.

Vartkat commented 1 year ago

Hi, and thank you again to look into my case. I've let the room settle. During the night, from 9pm to 10 am, when the external temp goes under 50°F (10°C), the difference stay stable around 1°F. Above 50°F the difference begins to raise (the external temp influence the the internal on, more when there's no heating but that's not our subject).

I've managed to get what we were looking at :

image

This si during two hours. I didn't show the pid output as it is exactly the inverted graph as the fan speed. Setpoint is set at 2 as the difference was already around 2. Also I've setup the node feeding the PID to send values every second instead of every 10 sec even if the sensors are giving values every 10 sec.

colinl commented 1 year ago

Is that with the prop band set to 10.0? And the integral set to 5 minutes (300 second).

Vartkat commented 1 year ago

Is that with the prop band set to 10.0?

No prop band to 0, as you adviced at the begining to find the on/off rythm.

colinl commented 1 year ago

Set it to 10 as I said earlier.

colinl commented 1 year ago

And integral to 300

Vartkat commented 1 year ago

After one hour it's begining to settle around 2...

image

Setpoint =2 Prop band =10 Integral time =300 Derivative =0 Max sample =900 Smoothing =0 and for the first time the PID node is not locked.

colinl commented 1 year ago

Bring the prop band down to 5 and it will come in quicker. If you bring it down too much it will start bouncing about.

Vartkat commented 1 year ago

Here is what I get after 5 hours with the numbers I gave. I'm now reducing the prop to 5.

image

But you have to know that if we look into a day without fans we get this :

image

which means the difference somehow follows the external temp (green is rafters, yellow main, orange is external temp and blue the difference. I don't know if this is relevant.

Also note that the fans are going till their max (i.e. 40%) perhaps I should give it more freedom to go up ?

Vartkat commented 1 year ago

I was wondering... Can the disable function be seen as a pause in the PID calculation, I mean when it's re-eneabled does it keeps the values it had or does it start from the begining in its journey to find the right value ?

colinl commented 1 year ago

Also note that the fans are going till their max (i.e. 40%) perhaps I should give it more freedom to go up ?

If it needs more then give it more.

Can the disable function be seen as a pause in the PID calculation, I mean when it's re-eneabled does it keeps the values it had or does it start from the begining in its journey to find the right value

Currently, when disabled, it does hold the integral offset that had built up while it was operating. So it should not have to start from scratch again. I do have a plan to add 'bumpless transfer' which means that it will hold the output at the existing value and then start from there again when put back into normal mode. Not sure when I will get round to implementing that though.

Vartkat commented 1 year ago

And here is what I get :

image

Setpoint =2, Propo band =4, Integral Time = 300, Derivative time =0, Max sample =900, derivative smoothing =0.

Seems not bad to me even if I don't get the exact smooth curves I see in the tuning guide.

Should I try to lower the prop band to 3 ? or even less ? Should I set any derivative time ? (If I well understand this should make a delayed reaction when approching the setpoint and a delayed stop when under the setpoint, is that right ?) And what about changing the integral time for more, hoping to get a less noisy result on the fan speed curve ?

As I'm using DHT22 which precisin is 0.2, the noise of the green curve could be due to this precision and so the curve could be considered a line within + or -0.2 (correct me if I'm wrong)

colinl commented 1 year ago

I am surprised you managed to get the control that good. A system like yours, with circulating air currents, is always going to be noisy, but as you suggest the poor resolution of the sensor makes it even worse. You can't use derivative because of the noisy signal, but I doubt if it would help much anyway. If you shrink the pb more then the noise on the fan control will increase so the speed will move about more, which may be undesirable. I would leave the integral where it is, it should be about right. Do you need better control than you are now getting?

Vartkat commented 1 year ago

If the master is happy with what the student did, I'm also happy ;-)

You are right, we don't want the fan to go faster cause it won't be confortable for the people in the room, I've been told 20% is like "a nice little breeze". So being around 20% is exactly what we should approach and it is (for the day we look).

If you shrink the pb more then the noise on the fan control will increase so the speed will move about more, which may be undesirable.

I wasn't thinking of shrinking the prob band but increasing the integral to be less noisy. But as the best is the enemy of good I'l stop with these values.

As the integral is 5 min, I asked graphana to mean and smooth the curves on 5 min (which I know you don't like) but it gives something nearer to your guide and really nice.

image

For other readers, the key point here is to invert the output, map values 0 to 1, to 100 to 0 (and not 0 to 100), then begin with a prop band at 10 and an integral of 10 min, see what it does and step by step reduce prop band then integral till you get satisfied.

Thank you very much for your valued help, I wouldn't have succeeded without you.

I'll update you with the result during hotter days.

P.S. For those curious about speed of hot air going up you can read https://physics.stackexchange.com/questions/178480/the-speed-of-air-rising-through-a-heated-tube

colinl commented 1 year ago

I asked graphana to mean and smooth the curves on 5 min (which I know you don't like)

Smoothing for display is no problem, but when trying to analyse a process to understand it better you need all the information that is available.

the key point here is to invert the output, map values 0 to 1, to 100 to 0

That is specific to your process. It is not generally the case.

begin with a prop band at 10 and an integral of 10 min, see what it does and step by step reduce prop band then integral till you get satisfied.

Again that is specific to your process, other processes need different settings.