PID question. Hatch box for bee queens

Hi

I've built a hatch box for hatching bee queens.
The optimal temperature for the hatching is 34.5 degrees celsius.
I would like to keep that temperature +-0.2 degrees...

For acheiving this I have a PID regulator that controls a relay for the 240VAC mains.
It's all working nicely, but now I have to trim the PID regulator, and I don't really know where to start.

I've run the PID with P=5, I=3 and D=3, and the following graph shows how it looks right now.
Set point is 30.0 degrees celsius.

Red = Set point
Blue = Actual temp (Process value)
Green = PID output, 10 equals 0%, 20 equals 100%
Yellow = Output relay, 0 equals off, 10 equals on
(Horizontal division is 200 seconds)

Here's the code:

Which parameter should I start changing for getting a more stable temp?

Thanks
/jon

Which parameter should I start changing for getting a more stable temp?

All three of them... Google “tuning PID with Ziegler Nichols” and find the correct system constant, then calculate. You don’t guess.

Your time proportional code in writeToHeatingRelay looks suspicious. An expansion of of the horizontal time base should show a direct correlation between PID output value and the on versus off time of your heater.

Your selected window time may also be a factor, it depends on the watt density of your heater and how quickly the temperature rises when the heater is on.

Thanks for the google tip. I'll look into that.

Also I will give the code some thinking time. :slight_smile:

/jon

Are you convinced that PID is the right answer? Simple bang-bang control might get you there, or abandoning the I & D components.

Simple bang-bang control might get you there

Tried that first.
Overshot with 10 degrees.

However, loosing the I and D might be a start.

The hatchbox is an old heater for warming your lunch, as you would have found in every work place (at least here in Sweden) before the microwaver came. It stores a lot of heat before it starts to cool down.

This is not mine, but it's the same.

/jon

Are you convinced that PID is the right answer?

I would also question this approach. PID is often used to control for external variations , and an oven is a stable thermal environment with pretty constant loss. Is the hatch box indoors in a heated space, or outdoors in the wind, sun and darkness.

Is the oven brought to temperature before the queen eggs are introduced?

How many amps does the hatch box draw when the heater is on? One thing to look at is if you can control the AC with a variac. Getting the heater closely balanced to the load is a good place to start and makes any fine tuning easier.

wildbill:
Are you convinced that PID is the right answer? Simple bang-bang control might get you there, or abandoning the I & D components.

No no, if you want 0.2C control proportional control is definitely going to make it much easier to achieve.

First I'd start the tuning process just using P term. Find the value at which oscillation is triggered and back off 25% or so. This sets a basic loop gain.

Then start increasing I (probably only a tiny bit is needed for I), until instability starts again.

Back off P and I say 10% each, that'll probably give fairly close control, but may be rather slow to heat up.

Adding D allows faster convergence (you have to add D, then see if P can be increased while maintaining
stability). The D term allows higher loop gain without overshooting so much - ie more rapid heating at start up.
You may not care about this for this application.

Too much D will lead to random fluctuations dominating, knock it back if that happens.

Basically fiddle with the parameters for the best performance (edge of stability), then take the values down a small amount to stop any tendency to oscillate.

Too much I will cause oscillation, too little will mean very slow convergence to exact final temperature.
I = 0 means the set point will never be reached, the error cannot be driven down to zero without I.

Too much D will cause random fluctuations, too little gives less performance than optimal.

Too much P will cause oscillation, too little will mean slower change, and if I=0 will mean more temperature
error at steady state.

Thermal control has some extra issues - usually heating and cooling have different rates - this is a form of non-linearity, which means control is more difficult. You will need a PID library that supports some form of integral-wind-up limiting. (You almost always need this, its seldom mentioned in introductory explanations of PID control).

Its also very time-consuming to tune, because everything is so slow (compared to motor controller PID).

(BTW what temperature sensor are you using? It needs to have a resolution well below 0.2C)

BTW what temperature sensor are you using? It needs to have a resolution well below 0.2C

From the earlier posting link I believe he is using a DHT22 which has these specs

Accuracy humidity +-2%RH(Max +-5%RH); temperature <+-0.5Celsius
Resolution or sensitivity humidity 0.1%RH; temperature 0.1Celsius
Repeatability humidity +-1%RH; temperature +-0.2Celsius

That's not accurate enough. The sensor needs to be an order of magnitude better than the desired temperature
target band, as the control system needs to sense when the temperature starts to change well before it leaves the target temperature band. Basically it needs low hysteresis and fine resolution (absolute accuracy is less important).

Think of a control loop as steering along a road - if the road is 10 yards wide you need something much better than 10 yard visual resolution to retain good control - 1 yard would be good and keep you off the verge, you
might weave around a few yards, but should be able to stay on the road.

So 0.02C resolution would be desirable, 0.05 might be the least you could tolerate.