Skip to content

Saturation prevention blocks integral part calculation when output is below zero #64

@koopee

Description

@koopee

I use PID controller with input that is quite small and quite often drops below zero. When input drops below zero, the PID integration does not work. Saturation prevents decrementing the integral value i_term when input is less than zero.

I fixed mine by setting the comparison self._last_output > -100 and self._last_output < 100

    # Calculate I and avoids Sturation
    if self._last_output is None or (
        self._last_output > 0 and self._last_output < 100
    ):
        self._i_term += self._ki * error * delta_time
        self._i_term = self.clamp_value(self._i_term, self._windup)

https://github.com/soloam/ha-pid-controller/blob/60052392bdaa114dc9296fcf7d3b58db48129993/custom_components/pid_controller/pidcontroller.py#L88C1-L90C11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions