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

[Question] How to supply Values #14

Closed soloam closed 3 years ago

soloam commented 4 years ago

Hello, I'm using this node to control my AC, and for that I'm reading the temperatures with multiple xiomi temperature sensors that are zigbee. This devices only submit the temperature when the delta is 0.5º. This can take some time to make a report when heatig or cooling a room.

What is the best approach to have better results, submit the temperature periodically, like 30s, even if no changes is detected, or only when the sensor submits the change?

I'm getting a lot of Integral Locked, and I think that is related with a low Integral Time, I used your blog post to help calibrate the PID.

Thank You

kleini commented 4 years ago

I use a trigger node to resend the existing msg object received from the temperature sensor. Nodes only do something (mostly) if they get some input values. This is especially true for this PID node. So having an input every 5 minutes into this PID node makes the calculation of the output more accurate.

soloam commented 4 years ago

I have it sending every 30 seconds! Probably it's to often! Can it be this the reason for having constant integral lock? How can I reset this without having to redeploy the flows?

Thank you

kleini commented 4 years ago

What is your setpoint and process value? Integral lock happens only, if both are very different.

soloam commented 4 years ago

Process value: 27.17 Set Point: 27

I don't think they are that far apart!

The values that I'm testing in the setting are:

PB: 0.7 Int Time: 360 Derv Time: 90

soloam commented 4 years ago

I know that my PB is a bit low, but I tested out with the method of doubling the overshoot, and I got that

kleini commented 4 years ago

My use case is heating, so it should not be that much difference:

How can you measure temperatures with an accuracy of 1/100 degree? I only found temperature sensors, with an accuracy of 1/10 degree but the deviance is given as +/-1°. So they measure something but not room temperature as it actually is. Consecutive sensor values sometimes differ +/-0.5°.

soloam commented 4 years ago

I think that I might have my values wrong!? Where in my setting did you get that my sensors are 1/100 of accuracy? To get the proportional band value I had the system running with only the set point and measured the bigger diference from my set point to the top of the curve, and I got 0.35, I doubled it and got the 0.7, and that was my starting point.

My sensors are zigbee from xiaomi, and they report at every 0.5º delta (or 1 hour since last report)

Then to get the integral time I doubled the time that was from the set point to the top of the curve, that was 180s, so, 360s... To my derivative I divided 180s for 2, so the 90s.

kleini commented 4 years ago

You said, your process value is 27.17. That is accuracy 1/100. Regarding your proportional band: 0.7 means in your case with a set point of 27, that a process value of 27.7 will result in 1.0 output value. Is that, what you want? Btw. how do you control your cooling process? How is an output value of 0.5 applied to the cooling process?

colinl commented 4 years ago

Give the PID loop data as often as you can, even if it has not changed. To tune a loop it is absolutely essential to have a chart showing the process value and the output of the PID, so make a chart (if you have not got one already) and add the image here. Then we will get an idea of whether it is reasonably tuned or not and whether you are sampling the temperature often enough.

You said the sensors only give you a value when the change is 0.5 degrees and asked what the best way to get better results is, well the answer to that is to use sensors with better performance. I use DS18B20 which are very cheap, have a resolution of 1/16 C and can be polled every few seconds if necessary. However the first thing to do is to get the best possible with what you have so post the chart and we will see what is going on. You might have to scale the pid output to make it readable on the chart, it doesn't need to fill the chart, but we need to see the general trends. You can use a Range node to scale the input range 0 to 1 to an output range that fits on the chart ok.

How are you driving the AC from the PID output?

soloam commented 4 years ago

My process value is the average of several sensor scattered around the room, I do this to get a more uniform temperature, I don't want a sensor that is closest to the ceiling to report a higher temperature and influence the cooling.

Regarding the output 1 at 27.7, probably I can make more like, output 1 when is 28.

To make the cooling I process the outpout in a range 0:1 to 1:0 and it inverts the values

soloam commented 4 years ago

Yes I have all the date logged in graphana, when I get home I will pull the data and paste the charts here! What do you need the Kp Ki and Kd variables or only the output to the AC?

To get the PID to the AC, I process the values from the PID and move them by a 0:1 - 0:5 range and that output is the speed that I send to my ac unit. So in the case of cooling, I use a 0:1 - 1:0 range and then 0:1 - 0:5 range. If its heating I will only use 0:1 - 0:5 range.

Thank you

kleini commented 4 years ago

The output value needs to be used accurately to control the AC. A value of 0.0 means: no AC at all, 0.5 means half of full AC power and 1.0 means maximum AC power. What you mean with the speed of an AC unit? If it has a speed control between off and 1 to 5, output value of 0.0 means off, while output of 0.5 should be translated to speed value 2.5 and output of 1.0 should be translated to speed value 5.

colinl commented 4 years ago

Using grafana (with Influx or similar presumably) is great, as you can always go back and see how it performed. Make sure you keep a note of the tuning params too. By the way, they aren't Kp, Ki and Kd in this algorithm they are PB, TI, and TD (proportional band, integral time and derivative time). Yes I need to know those too please. They aren't just different names for the same parameters, they are different constants in the maths.

soloam commented 4 years ago

I round it to integer, so 0 will mean that the ac will go to sleep mode, in this state e keeps using only the fans for a few minutes (to help mix the air) and the stop. Value of 1 to 5 is the speed of the fans, so 0.5 output will be 2.5, that will be the speed 3.

soloam commented 4 years ago

Using grafana (with Influx or similar presumably) is great, as you can always go back and see how it performed. Make sure you keep a note of the tuning params too. By the way, they aren't Kp, Ki and Kd in this algorithm they are PB, TI, and TD (proportional band, integral time and derivative time). Yes I need to know those too please. They aren't just different names for the same parameters, they are different constants in the maths.

When I get home I'll pull the graph, since all is logged in influxdb I can go back in time and see what was the response of the PID to that settings.

soloam commented 4 years ago

The result of the PID working in the AC image

The Values of the PID image

colinl commented 4 years ago

I would take the derivative off, set it to zero, it won't do anything useful when you have such large steps in the apparent process values, all it does is add those spikes every time the process value steps, which aren't helpful. What does it look like on a much longer timescale? Obviously with that resolution and the fact that you only have a few discrete speed settings you are never going to get really good control.

soloam commented 4 years ago

Main main goal is to keep the temperature always at the lowest speed, to ensure power savings! Yes I only have 5 speeds in the ac. I do this because the temperature regulation of the auto in my ac is very bad, and is almost always at full speed, making the power footprint very big. I want to ensure that the system reduces the speed when it does not need it to keep the temperature.

colinl commented 4 years ago

I am sure it can be made to work reasonably well, Set the Derivative Time to zero and show me how it does then, if possible over a few hours. What have you got PB and TI set to currently?