Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong saturation prevention in I-part #43

Open
wsw2016 opened this issue May 29, 2023 · 0 comments
Open

Wrong saturation prevention in I-part #43

wsw2016 opened this issue May 29, 2023 · 0 comments

Comments

@wsw2016
Copy link

wsw2016 commented May 29, 2023

Current implementation of saturation prevention creates deadlocks.
Assume we have an I-controller (P & D are 0).
The error is big and the I-term is growing with a step of 10:
step n: i_term == 95, last_output == 95
step n + 1: i_term == 105, last_output == 100
Now, the current evaluation of i_term:

if self._last_output is None or (
            self._last_output > 0 and self._last_output < 100
        ):
     ...   update i_term

the i_term will never be updated again as the last_output == 100.

The correct implementation would be:

  self._i_term += i_term_delta
  self._i_term = self.clamp_value(self._i_term, (0, 100))

without any conditions.

Another issue is the windup, which is claimed to be The maximum value to increment in the integral portion of the PID.
Current implementation:
self._i_term = self.clamp_value(self._i_term, self._windup)
sets the maximum value of the integral part of PID itself.
The correct implementation would be (together with the previous code snippet):

# Calculate I and avoid saturation  
  i_term_delta = self._ki * error * delta_time
  i_term_delta = self.clamp_value(i_term_delta, self._windup)
  self._i_term += i_term_delta
  self._i_term = self.clamp_value(self._i_term, (0, 100))
JulianHi pushed a commit to JulianHi/ha-pid-controller that referenced this issue Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant