Relay PID headaches
 

Relay PID headaches  

  RSS

floriske
(@floriske)
Active Member
Joined: 4 months ago
Posts: 7
20/05/2019 2:41 pm  

I'm currently in the progress of converting a fridge into a mycodo controlled meat curing chamber. But PID controlled relays are giving me some 'headaches'.

I have 3 relays:
- fridge (used for both cooling and de-humidifying)
- ceramic bulb (heater)
- humidifier

My basic PID knowledge comes from
another hobby of mine: flying RC helicopters.

With my helicopters the PID output adjustment (servo throw) is continuous and proportional which makes it rather simple to understand.

The PID period based relay control in Mycodo works rather different with 2 major differences: PID output is changed every PID period instead of continously and the output in case of a relay isn't proportional but either 0% or 100%.

The only way to proportionally regulate a relay would be to have it pulsating on/off but that's something that both the fridge and the ceramic bulb don't like.

I found your PID advise in another topic in which you talk about not setting Kp higher than P resulting in twice the PID period.

If I where to convert that advise to my temperature control situation with the default 30s PID period it would result in:

Max temp. in the summer: 30°C
Avg desired temp: 15° (+/-0,5° max)
Max. error: 15°

PID period * 2 = 60
P=Kp * e
60=Kp * 15
Kp=4

Based on this I can calculate the error at which time P will be equal to the PID period.

P=Kp * e
30=4 * e
e= 7,5°

Which would mean that the temperature would have to drop or raise 7,5°C in the current and following PID period or else the relay will start pulsating because P will become lower than the PID period. Which the fridge and heater won't like.

If I where to raise Kp in such way that the relays won't start pulsating this would most likely result in overshoot because the relay will remain 100% on until the desired temperature is just about reached.

I need to figure out a different approach for this situation which is giving me some headaches. So I hope you can help me out.

My thoughts so far:

I think I need to test run the fridge and heater to see how much °C they cool/heat over a period of time. As well as how much overshoot occurs when turning them off (and over which period this overshoot occurs).

Next I think I need to expand the PID period and raise Kp to achieve a situation where the relays won't pulsate and the overshoot is minimal.

If the differences between fridge and heater are too big maybe even use 2 PID controllers.

Or am I over thinking this and would 2 conditional controllers do the trick? Something like: fridge on above 15,5°C and heater on below 14,5°C

Hope you can give me some good advise on this.


Quote
routout
(@routout)
Active Member
Joined: 7 months ago
Posts: 5
24/05/2019 8:26 am  

I played with same problems last year when I tested Mycodo for the same use as you now. Thats why I raised this issue https://github.com/kizniche/Mycodo/issues/497
PID doesn't suit for that kind of use. 


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 5 years ago
Posts: 0
29/05/2019 7:09 pm  

References:
https://github.com/kizniche/Mycodo/issues/660
https://github.com/kizniche/Mycodo/issues/661

I haven't made any progress on the dedicated AC/Heat function, but here are a few things I can comment about this setup:

Setting up a conditional may be the simpler route and will yield sufficient results, however I do believe two PIDs can be tuned in unison while using the same output (AC compressor) for controlling both lowering of humidity and cooling. However, I think it will be difficult to tune. With that being said, I don't really have any advice to begin testing, other than try to be conservative with PID values, and make very small increments. With the solving of the above issues, you can now use the same output on multiple activated PIDs and the Min Off Duration will be respected, which should allow safe testing from here on out. If you can provide preliminary data in the form of graphs with PID outputs, Outputs, and Inputs, along with the PID tuning parameters, I can give advice about what direction you should try regarding PID tuning. You may also want to explore using the Statistics Math controller to calculate the average of certain sensor measurements in order to smooth out the data going into the PIDs in order to have more metered responses from them. With the new features that I'm going to try to release tonight, this should let you begin testing.

This post was modified 4 months ago by Kyle Gabriel

ReplyQuote
floriske
(@floriske)
Active Member
Joined: 4 months ago
Posts: 7
30/05/2019 11:55 am  

Thanks for the quick response regarding the 2 referenced issues. 

In the meantime I've been playing around with the different needed PID's one by one to dial them in. The updated possibility of using the same output on 2 PID's respecting each others min. off duration helped a lot with this. 

I will take some screenshots of my current settings and graphs soon and post them here. 

Thanks again for all the effort


ReplyQuote
floriske
(@floriske)
Active Member
Joined: 4 months ago
Posts: 7
30/05/2019 2:21 pm  

As promised some screenshots. 

First of all the current temperature and humidity graphs. I use 2 AM2302 sensors and use the average of both for the PID controllers. 

PID Scr-4.jpg

Next up the temp. lower PID which is the one I started with. The min. on duration is to prevent useless switching of the fridge since 60 seconds has hardly any effect on the temperature. 

PID Scr-5.jpg

The temp. raise PID (which has a min on time for the same reason)

PID Scr-6.jpg

humidity lower (uses the fridge so the same min. on and off duration)

PID Scr-7.jpg

And the humidity raise which is still a work in progress and hard to test atm since the external humidity is quite high. I added the 10 sec. max for now because the humidity gets of the charts if the humidifier is turned on too long. 

PID Scr-8.jpg

This post was modified 4 months ago 2 times by Kyle Gabriel

ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 5 years ago
Posts: 0
30/05/2019 3:08 pm  

Thanks for the data.

First, I would recommend only using one PID for raising/lowering temperature, and one PID for raising/lowering humidity. Each PID is capable of utilizing a raising device and a lowering device within one PID. Using 4 PIDs may cause a lot of conflicts so I would start with a minimal configuration and then only expand out to more if a minimal setup is not looking sufficient.

Second, I would recommend experimenting with using the Band option, which will allow you to target a specific humidity and temperature range (Band). Make sure to enable the PID Band (Upper and Lower) in the graph rather than the Setpoint.

However, the regulation you have so far looks good. Are you satisfied with this degree of oscillation? My Band suggestion and only using 2 PIDs could improve the competition between the lowering/raising devices and reduce the oscillation.

This post was modified 4 months ago 2 times by Kyle Gabriel

ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 5 years ago
Posts: 0
30/05/2019 3:26 pm  

Another suggestion is to use two "Average (Past, Single Channel)" Math Controllers rather than one "Average (Last, Multiple Channels)". What you are using now will average only the last measurement of each channel, which will not smooth the data. To do this, you will need to create two "Average (Past, Single Channel)" Math Controllers, one for each humidity measurement, for a Period of several minutes in the past, which will average over that period of time. Then, use one "Average (Last, Multiple Channels)" Math controller to average these two newly-created Math Controllers. This effectively averages both humidity measurements that occur over a period of time. This may smooth out the response that can cause oscillation, but it may not provide as quick of a response as you would like to counteract the oscillation. For that, you may need to explore alternative devices for affecting humidity. It is notoriously difficult to smooth humidity fluctuations in small refrigerated environments, as the condenser can quickly pull humidity out of the air as it cools and condenses humidity.


ReplyQuote
floriske
(@floriske)
Active Member
Joined: 4 months ago
Posts: 7
30/05/2019 3:49 pm  

As you can see in the screenshots the raise and lower devices for the temperature require quite different values regarding P gain. If I combine them I can't get it to function properly. Either cooling lacks out at lower gain or heating overshoots at higher gain. 

Using the band settings I noticed the temperature started regulating worse than without. I had it set at first but after removing it I had a lot better results. 

I will look into the tips regarding the averages! 


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 5 years ago
Posts: 0
30/05/2019 3:55 pm  

Here are some of my thoughts on your PID tuning thus far.

I would base the Temperature PID Period on how long it takes the compressor to have an effect on the system (to lower the temperature). The current Period of 30 seconds and a Min On Duration of 60 seconds means the PID output must always exceed the Period in order for the output to go on at all. Additionally, when the output does go on, it stays on for several 30-second periods (I count it turning on for 3 to 4 times per period of activity) before it turns off (and stays off for >900 seconds). I would increase your Period to something over the Min On Duration that also is larger than the combined durations the output stays on for, so something around 180 seconds, and see how the PID performs with that. You should see that the PID output on the graph now has only one output duration per period. This may also curb the response to start heating if the temperature isn't reduced so quickly in such a short period of time.

As for the temperature (-) PID gains, I believe your Kp is too high. Currently, your error is not very much (<1 degree). With your current Kp = 150, an error of 1 would equate to 150 seconds on. Since your Ki and Kd are set to 0, you are effectively using a simple P-controller. I would recommend reducing your Kp by 75% or 50% and increasing the Ki to something like 0.1 and start slowly incrementing upward and see the effect. With Ki = 0.1 and your Integrator Min set to -100, the maximum the I value will contribute to the PID output will be I = 100 * 0.1 = 10. Keep in mind that if you increase your Period, you will need to calculate new gains if you want the new tuning to have the same effect as the previous tuning. For example, with a 30 second Period and a Kp = 150 (150 output every 30 seconds if error = 1), if you change the Period to 180, and keep the gains unchanged, you will have an output of 150 seconds every 180 seconds (instead of every 30 seconds). Again, your current configuration has the output exceeding the Period, so you probably don't need to recalculate Kp, and can merely change the Period form 30 to 180 and just see how the system responds.

This post was modified 4 months ago 2 times by Kyle Gabriel

ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 5 years ago
Posts: 0
30/05/2019 4:00 pm  
Posted by: floriske

As you can see in the screenshots the raise and lower devices for the temperature require quite different values regarding P gain. If I combine them I can't get it to function properly. Either cooling lacks out at lower gain or heating overshoots at higher gain. 

Using the band settings I noticed the temperature started regulating worse than without. I had it set at first but after removing it I had a lot better results. 

Yes, if different gains are necessary, that is a good point to using multiple PIDs. Did you try using the same (or similar) band for both PIDs or was the band only applied to one PID? You seem to be on the right track as far as experimentation goes. I can only be of so much help with recommendations because it's now about just experimenting with different tunings and parameters and keeping good notes to identify what works and what doesn't.

This post was modified 4 months ago by Kyle Gabriel

ReplyQuote
floriske
(@floriske)
Active Member
Joined: 4 months ago
Posts: 7
30/05/2019 4:48 pm  

Those are some very helpful thoughts! I never even considered increasing the period from 60 to 180 seconds because most of the times the fridge is on for that period or longer. 

Back to experimenting 😉 

P.s. I had the band set in both PID's

This post was modified 4 months ago by floriske

ReplyQuote
floriske
(@floriske)
Active Member
Joined: 4 months ago
Posts: 7
05/06/2019 2:08 pm  

In the meantime I tried both the longer pid period for the temp. as well as the average humidity over the past several minutes suggestions.

Both turned out to yield lesser results compared to my earlier settings. So for now I reverted back to those but I will most definitely experiment again in a later stage. 

Thank you for all your help so far! I learned a lot from your info as well as by messing around based on it. 


ReplyQuote