soloam / ha-pid-controller

PID Controller to Home Assistant
MIT License
97 stars 12 forks source link

Integrator in saturation #19

Open pterodaktil02 opened 1 year ago

pterodaktil02 commented 1 year ago

In steady state PID = Kp * error + Ki(previous integral + error) + Kd(error - last) = 0 + Ki (previous integral + error) + 0 = Ki (previous integral + error) So output of PID controller at the steady state is equal to integral term.

A problem arises if the regulator is in the saturation zone for a very long time. Therefore, if the regulator is in the saturation zone, it is necessary to reduce the integral component. I tried this but my knowledge of python is very low.
Instead of self._i_term += self._ki * error * delta_time I set this code

        if self._last_output == 0 :
           self._i_term += 0
        elif self._last_output == 100 :
           self._i_term += 0 
        else:           
           self._i_term += self._ki * error * delta_time 

Maybe add this fix to the main plugin?

soloam commented 1 year ago

Basicly what you mean is that the pid should not do anything if reaches 0 or 100? Doesn't he already do that? The min and max values are constrained, it should not raise above the maximum, or lower bellow the minimum!

lukepighetti commented 1 year ago

I'm also having extreme saturation problems with the integral component, I believe

pterodaktil02 commented 1 year ago

Basicly what you mean is that the pid should not do anything if reaches 0 or 100? Doesn't he already do that? The min and max values are constrained, it should not raise above the maximum, or lower bellow the minimum!

When the control action on the object reaches saturation, the feedback is broken (the control action does not depend on the state of the system). Even with windup, the integrator continues to integrate, the signal at its output grows, but this signal does not participate in the regulation process. I suggest turning off the integration when the regulator is in saturation. This will have a good effect on the transient process, reduce oscillations after exiting saturation.

soloam commented 1 year ago

I have seen that behavior, turn off the integrator, when the system is saturated!

You could do this if you use templating in the 'I' variable, but I agree that should be automatic!

I'll look into it!

Tks

pterodaktil02 commented 1 year ago

I added the solution in the start thread. I just don't know how to add commits.

soloam commented 1 year ago

I'll try to take a look at this tomorrow, let me see what I can do!

hauard commented 1 year ago

I'll try to take a look at this tomorrow, let me see what I can do!

Any luck with this? Having the same issue

pterodaktil02 commented 1 year ago

I'll try to take a look at this tomorrow, let me see what I can do!

Any luck with this? Having the same issue You can make it yourself - just open pidcontroller.py and change after code after

# Calculate terms

from self._i_term += self._ki * error * delta_time to

        if self._last_output == 0 :
           self._i_term += 0
        elif self._last_output == 100 :
           self._i_term += 0 
        else:           
           self._i_term += self._ki * error * delta_time 
soloam commented 1 year ago

Merged into 1.1.5

hauard commented 1 year ago

I'm no expert in coding, but after the last update, it seems that the readout of the integral-attribute is in saturation, but maybe not the regulator itself? I get the attribute i: 2.3816e-16

I have the min/max to 0-100, windup to 100, and earlier the readout of the integral was the max-vaule, 100

soloam commented 1 year ago

The expected behavior is to the PID to increment the "I" until the output reaches the maximum. When on maximum the "I" will stop incrementing and remain constant. That is the expected. But should resume incrementing the "I" if the output falls bellow the maximum.