Skip to content

Commit

Permalink
CF3B5 reverse fan (#51)
Browse files Browse the repository at this point in the history
* add temperature_fan the reverse working mode to some internal circulation heating fans

* add temperature_fan the reverse working mode to some internal circulation heating fans(fix line longer)

* temperature_fan: add reverse working mode

* temperature_fan: add reverse working mode

* Add default is False in comment

* black

---------

Co-authored-by: CF3B5 <locke.cm@gmail.com>
Co-authored-by: CF3B5 <cf3b5bb@gmail.com>
  • Loading branch information
3 people committed Sep 5, 2023
1 parent 9082240 commit 57734dd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Features merged into the master branch:

- [fan: Normalising Fan PWM power](https://github.com/DangerKlippers/danger-klipper/pull/44) ([klipper#6307](https://github.com/Klipper3d/klipper/pull/6307))

- [fan: Reverse FAN](https://github.com/DangerKlippers/danger-klipper/pull/51) ([klipper#4983](https://github.com/Klipper3d/klipper/pull/4983))

- [heater: Modify PID without reload](https://github.com/DangerKlippers/danger-klipper/pull/35)

- [heater: Velocity PID](https://github.com/DangerKlippers/danger-klipper/pull/47) ([klipper#6272](https://github.com/Klipper3d/klipper/pull/6272))
Expand All @@ -22,6 +24,7 @@ Features merged into the master branch:

- [probe: Drop the first result](https://github.com/DangerKlippers/danger-klipper/pull/2) ([klipper#3397](https://github.com/Klipper3d/klipper/issues/3397))


"Dangerous Klipper for dangerous users"

[![Klipper](docs/img/klipper-logo-small.png)](https://DangerKlippers.github.io/danger-klipper/)
Expand Down
5 changes: 5 additions & 0 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2892,6 +2892,11 @@ information.
#gcode_id:
# If set, the temperature will be reported in M105 queries using the
# given id. The default is to not report the temperature via M105.
#reverse: False
# If true, the working mode of the fan is reversed. If the temperature
# is lower than the target temperature, the fan speed increases;
# otherwise, the fan speed decreases.
# The default is False.
```

### [fan_generic]
Expand Down
42 changes: 28 additions & 14 deletions klippy/extras/temperature_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,22 @@ def set_max_speed(self, speed):
class ControlBangBang:
def __init__(self, temperature_fan, config):
self.temperature_fan = temperature_fan
self.reverse = config.getboolean("reverse", False)
self.max_delta = config.getfloat("max_delta", 2.0, above=0.0)
self.heating = False

def temperature_callback(self, read_time, temp):
current_temp, target_temp = self.temperature_fan.get_temp(read_time)
if self.heating and temp >= target_temp + self.max_delta:
self.heating = False
elif not self.heating and temp <= target_temp - self.max_delta:
self.heating = True
if (
self.heating != self.reverse
and temp >= target_temp + self.max_delta
):
self.heating = self.reverse
elif (
not self.heating == self.reverse
and temp <= target_temp - self.max_delta
):
self.heating = not self.reverse
if self.heating:
self.temperature_fan.set_speed(read_time, 0.0)
else:
Expand All @@ -167,13 +174,15 @@ def temperature_callback(self, read_time, temp):
class ControlPID:
def __init__(self, temperature_fan, config):
self.temperature_fan = temperature_fan
self.reverse = config.getboolean("reverse", False)
self.Kp = config.getfloat("pid_Kp") / PID_PARAM_BASE
self.Ki = config.getfloat("pid_Ki") / PID_PARAM_BASE
self.Kd = config.getfloat("pid_Kd") / PID_PARAM_BASE
self.min_deriv_time = config.getfloat("pid_deriv_time", 2.0, above=0.0)
self.temp_integ_max = 0.0
if self.Ki:
self.temp_integ_max = self.temperature_fan.get_max_speed() / self.Ki
imax = config.getfloat(
"pid_integral_max", self.temperature_fan.get_max_speed(), minval=0.0
)
self.temp_integ_max = imax / self.Ki
self.prev_temp = AMBIENT_TEMP
self.prev_temp_time = 0.0
self.prev_temp_deriv = 0.0
Expand All @@ -198,13 +207,18 @@ def temperature_callback(self, read_time, temp):
# Calculate output
co = self.Kp * temp_err + self.Ki * temp_integ - self.Kd * temp_deriv
bounded_co = max(0.0, min(self.temperature_fan.get_max_speed(), co))
self.temperature_fan.set_speed(
read_time,
max(
self.temperature_fan.get_min_speed(),
self.temperature_fan.get_max_speed() - bounded_co,
),
)
if not self.reverse:
self.temperature_fan.set_speed(
read_time,
max(
self.temperature_fan.get_min_speed(),
self.temperature_fan.get_max_speed() - bounded_co,
),
)
else:
self.temperature_fan.set_speed(
read_time, max(self.temperature_fan.get_min_speed(), bounded_co)
)
# Store state for next measurement
self.prev_temp = temp
self.prev_temp_time = read_time
Expand Down

0 comments on commit 57734dd

Please sign in to comment.