temperature_fan modified to have working pid option
Module: temperature_fan: ControlPID option modified to get the expected behavior. Module: Config_Reference: To correspond to the modified ControlPID class.
Whereas the bang-bang control works as expected (fan turns on when measured temp is > reference temp), the ControlPID as designed doesn't have the same behavior and the computed duty cycle is max_speed - PID value, which is not the expected behavior. (in my point of view)
The correction allows the PID to work as expected: the fan will turn on if temperature increase above reference and will speed up if the difference increase. It will eventually shut down if the temperature is below reference. When powered on the fan stays within min_speeed<->max_speed range.
In this case, the minimum fan speed should be defined near the minimum PWM duty cycle value to keep the fan spinning. A tolerance equal to max_delta has been programmed to avoid that the fan oscillate rapidly between 0 and min_speed near the reference value. It only kick-in when the measured temperature is >reference temperature + max_delta and turns off at reference temperature - max_delta, making the fan control effectively back to bang-bang between 0 and min_speed.
The temp_err variable is < 0 when the fan should power-on and if the value is lower, the fan must speed up, so all PID coefficients must be negative. (or the temp_err should be inverted).
Used successfully to control the radiator fan of a water-cooled printer more silently than with the bang-bang control: A stable heat source (head + motors) results in a stable fan rpm near the reference temperature and if the heat stops, the fan stops with some delay.
As modified, it can be used to control the exhaust (or intake) fan of an enclosure, if it is passively heated by the bed, and maintain its reference temperature independently of the bed surface temp (as long as the bed's power is sufficient).
See canceled commit #6547 for a long discussion about the opportunity to have a PID control at all.
The goal of this PR is only to make the option functional without questioning its specific utility.
Signed-off-by: Luc JOB [email protected]
Thank you for submitting a PR, pleas refer to point 3 in "What to expect in a review" in https://github.com/Klipper3d/klipper/blob/master/docs/CONTRIBUTING.md and provide a signed off by line.
Thanks James
Thank you for your contribution to Klipper. Unfortunately, a reviewer has not assigned themselves to this GitHub Pull Request. All Pull Requests are reviewed before merging, and a reviewer will need to volunteer. Further information is available at: https://www.klipper3d.org/CONTRIBUTING.html
There are some steps that you can take now:
- Perform a self-review of your Pull Request by following the steps at: https://www.klipper3d.org/CONTRIBUTING.html#what-to-expect-in-a-review If you have completed a self-review, be sure to state the results of that self-review explicitly in the Pull Request comments. A reviewer is more likely to participate if the bulk of a review has already been completed.
- Consider opening a topic on the Klipper Discourse server to discuss this work. The Discourse server is a good place to discuss development ideas and to engage users interested in testing. Reviewers are more likely to prioritize Pull Requests with an active community of users.
- Consider helping out reviewers by reviewing other Klipper Pull Requests. Taking the time to perform a careful and detailed review of others work is appreciated. Regular contributors are more likely to prioritize the contributions of other regular contributors.
Unfortunately, if a reviewer does not assign themselves to this GitHub Pull Request then it will be automatically closed. If this happens, then it is a good idea to move further discussion to the Klipper Discourse server. Reviewers can reach out on that forum to let you know if they are interested and when they are available.
Best regards, ~ Your friendly GitIssueBot
PS: I'm just an automated script, not a human being.