controller_fan: Add support for a fan cooling the controller-board (#1070)

Whenever a stepper driver or a heater becomes active, it is desirable to turn on a fan cooling the associated parts on the controller board. This module implements such a fan that turns on whenever a stepper or specified heater turns on, decelerates to a configurable speed when all of the watched parts turn off, and returns to an off-speed, when a user-defined timeout is met.

Signed-off-by: Nils Friedchen <Nils.Friedchen@googlemail.com>
This commit is contained in:
Master92 2019-01-10 18:12:15 +01:00 committed by KevinOConnor
parent 0ba1f5109d
commit a27838bc05
2 changed files with 83 additions and 0 deletions

View File

@ -414,6 +414,36 @@
# is 1.0
# Controller cooling fan. A "controller fan" is a fan that will be
# enabled whenever its associated heater or any configured stepper
# driver is active. The fan will stop, whenever an idle_timeout is
# reached to ensure no overheating will occur after deactivating a
# watched component.
#[controller_fan]
#pin:
#max_power:
#shutdown_speed:
#cycle_time:
#hardware_pwm:
#kick_start_time:
# See the "fan" section in example.cfg for a description of the
# above parameters.
#idle_timeout:
# The ammount of time (in seconds) after a stepper driver or heater
# was active and the fan should be kept running. The default
# is 30 seconds.
#idle_speed:
# The fan speed (expressed as a value from 0.0 to 1.0) that the fan
# will be set to when a heater or stepper driver was active and before
# the idle_timeout is reached. This must be greater or equal
# max_power. The default is max_power
#heater:
# Name of the config section defining the heater that this fan is
# associated with. If a comma separated list of heater names is
# provided here, then the fan will be enabled when any of the given
# heaters are enabled. The default is "extruder".
# Temperature-triggered cooling fans (one may define any number of
# sections with a "temperature_fan" prefix). A "temperature fan" is a
# fan that will be enabled whenever its associated sensor is above a

View File

@ -0,0 +1,53 @@
# Support a fan for cooling the MCU whenever a stepper or heater is on
#
# Copyright (C) 2019 Nils Friedchen <nils.friedchen@googlemail.com>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import fan
PIN_MIN_TIME = 0.100
class ControllerFan:
def __init__(self, config):
self.printer = config.get_printer()
self.printer.register_event_handler("klippy:ready", self.handle_ready)
self.steppers = []
self.fan = fan.PrinterFan(config)
self.mcu = self.fan.mcu_fan.get_mcu()
self.max_power = config.getfloat(
'max_power', 1., minval=0., maxval=1.)
self.idle_speed = config.getfloat(
'idle_speed', self.max_power, minval=0., maxval=self.max_power)
self.idle_timeout = config.getint("idle_timeout", 30, minval=0)
self.heater_name = config.get("heater", "extruder")
self.last_on = self.idle_timeout
def handle_ready(self):
pheater = self.printer.lookup_object('heater')
self.heaters = [pheater.lookup_heater(n.strip())
for n in self.heater_name.split(',')]
kin = self.printer.lookup_object('toolhead').get_kinematics()
self.steppers = kin.get_steppers()
reactor = self.printer.get_reactor()
reactor.register_timer(self.callback, reactor.NOW)
def callback(self, eventtime):
power = 0.
active = False
for stepper in self.steppers:
active |= stepper.is_motor_enabled()
for heater in self.heaters:
currentTemp, targetTemp = heater.get_temp(eventtime)
if targetTemp:
active = True
if active:
self.last_on = 0
power = self.max_power
else:
if self.last_on < self.idle_timeout:
power = self.idle_speed
self.last_on += 1
print_time = self.mcu.estimated_print_time(eventtime) + PIN_MIN_TIME
self.fan.set_speed(print_time, power)
return eventtime + 1.
def load_config(config):
return ControllerFan(config)