fan: Add support for heater_fan objects

Add support for fans designed to cool the components of an extruder or
heater.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-07-04 12:24:11 -04:00
parent 519e81d0fa
commit 969485c754
5 changed files with 63 additions and 6 deletions

View File

@ -322,3 +322,17 @@ max_z_accel: 30
# centripetal velocity cornering algorithm. A larger number will
# permit higher "cornering speeds" at the junction of two moves. The
# default is 0.02mm.
# Heater cooling fans (one may define any number of sections with a
# "heater_fan" prefix). A "heater fan" is a fan that will be enabled
# whenever its associated heater is active.
#[heater_fan my_nozzle_fan]
# See the "fan" section for fan configuration parameters.
#pin: ar7
# The remaining variables are specific to heater_fan.
#heater: extruder
# Name of the config section defining the heater that this fan is
# associated with. The default is "extruder".
#heater_temp: 50.0
# A temperature (in Celsius) that the heater must drop below before
# the fan is disabled. The default is 50 Celsius.

View File

@ -72,11 +72,14 @@ max_temp: 100
[fan]
pin: PH5
[heater_fan nozzle_fan]
pin: PH3
max_power: 0.61
hard_pwm: 1
[mcu]
serial: /dev/ttyACM0
custom:
# Nozzle fan
set_pwm_out pin=PH3 cycle_ticks=1 value=155
# Turn off yellow led
set_digital_out pin=PB7 value=0
# Stepper micro-step pins

View File

@ -243,3 +243,13 @@ def get_printer_extruders(printer):
break
out.append(extruder)
return out
def get_printer_heater(printer, name):
if name == 'heater_bed':
return printer.objects.get(name)
if name == 'extruder':
name = 'extruder0'
extruder = printer.objects.get(name)
if extruder is None:
return None
return extruder.get_heater()

View File

@ -1,9 +1,11 @@
# Printer fan support
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import extruder
FAN_MIN_TIME = 0.1
PWM_CYCLE_TIME = 0.010
@ -16,12 +18,10 @@ class PrinterFan:
pin = config.get('pin')
hard_pwm = config.getint('hard_pwm', 0)
self.mcu_fan = printer.mcu.create_pwm(pin, PWM_CYCLE_TIME, hard_pwm, 0.)
# External commands
def set_speed(self, print_time, value):
def set_pwm(self, mcu_time, value):
value = max(0., min(self.max_power, value))
if value == self.last_fan_value:
return
mcu_time = self.mcu_fan.print_to_mcu_time(print_time)
mcu_time = max(self.last_fan_time + FAN_MIN_TIME, mcu_time)
if (value and value < self.max_power
and not self.last_fan_value and self.kick_start_time):
@ -31,7 +31,34 @@ class PrinterFan:
self.mcu_fan.set_pwm(mcu_time, value)
self.last_fan_time = mcu_time
self.last_fan_value = value
# External commands
def set_speed(self, print_time, value):
mcu_time = self.mcu_fan.print_to_mcu_time(print_time)
self.set_pwm(mcu_time, value)
class PrinterHeaterFan:
def __init__(self, printer, config):
self.fan = PrinterFan(printer, config)
heater = config.get("heater", "extruder0")
self.heater = extruder.get_printer_heater(printer, heater)
if self.heater is None:
raise config.error("Unknown heater '%s'" % (heater,))
self.heater_temp = config.getfloat("heater_temp", 50.0)
printer.reactor.register_timer(self.callback, printer.reactor.NOW)
def callback(self, eventtime):
current_temp, target_temp = self.heater.get_temp()
if not current_temp and not target_temp and not self.fan.last_fan_time:
# Printer still starting
return eventtime + 1.
power = 0.
if target_temp or current_temp > self.heater_temp:
power = 1.
mcu_time = self.fan.mcu_fan.system_to_mcu_time(eventtime + FAN_MIN_TIME)
self.fan.set_pwm(mcu_time, power)
return eventtime + 1.
def add_printer_objects(printer, config):
if config.has_section('fan'):
printer.add_object('fan', PrinterFan(printer, config.getsection('fan')))
for s in config.get_prefix_sections('heater_fan '):
printer.add_object(s.section, PrinterHeaterFan(printer, s))

View File

@ -107,6 +107,9 @@ class ConfigWrapper:
return ConfigWrapper(self.printer, section)
def has_section(self, section):
return self.printer.fileconfig.has_section(section)
def get_prefix_sections(self, prefix):
return [self.getsection(s) for s in self.printer.fileconfig.sections()
if s.startswith(prefix)]
class ConfigLogger():
def __init__(self, cfg, bglogger):