fan: Allow the fan shutdown_speed to be configured

Add a shutdown_speed config option to fans so that users can specify
the speed on a shutdown event.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-05-18 19:12:03 -04:00
parent 5712283e91
commit 2740838b2e
5 changed files with 41 additions and 25 deletions

View File

@ -193,12 +193,17 @@
# 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. In the event of an MCU
# software error the heater_fan will be set to its max_power.
# whenever its associated heater is active. By default, a heater_fan
# has a shutdown_speed equal to max_power.
#[heater_fan my_nozzle_fan]
# See the "fan" section for fan configuration parameters.
#pin: ar4
# The remaining variables are specific to heater_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.
#heater: extruder
# Name of the config section defining the heater that this fan is
# associated with. The default is "extruder".
@ -212,18 +217,23 @@
# 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 set temperature. In the event of an MCU software error the
# temperature_fan will be set to its max_power.
# sections with a "temperature_fan" prefix). A "temperature fan" is a
# fan that will be enabled whenever its associated sensor is above a
# set temperature. By default, a heater_fan has a shutdown_speed equal
# to max_power.
#[temperature_fan my_temp_fan]
# See the "fan" section for fan configuration parameters.
#pin: ar4
# See the "heater" section for details about the sensor_type and
# sensor_pin parameters.
#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.
#sensor_type: EPCOS 100K B57560G104F
#sensor_pin: analog13
# The remaining variables are specific to temperature_fan.
# See the "heater" section for details about the sensor_type and
# sensor_pin parameters.
#min_temp: 0
#max_temp: 100
# The maximum range of valid temperatures (in Celsius) that the
@ -234,12 +244,13 @@
# that reasonable temperatures do not result in an error. These
# parameters must be provided.
#target_temp: 40.0
# A temperature (in Celsius) that will be the target temperature
# A temperature (in Celsius) that will be the target temperature.
# The default is 40 degrees.
#max_speed: 1.0
# The fan speed (expressed as a value from 0.0 to 1.0) that the fan
# will be set to when the sensor temperature exceeds the set value.
# The default is 1.0.
#min_speed: 1.0
#min_speed: 0.3
# The minumin fan speed (expressed as a value from 0.0 to 1.0) that the fan
# will be set to when the sensor temperature is the set value.
# The default is 0.3.
@ -249,10 +260,10 @@
#pid_Kp: 40
# Kp is the "proportional" constant for the pid. This parameter must
# be provided for PID heaters.
pid_Ki: 0.2
#pid_Ki: 0.2
# Ki is the "integral" constant for the pid. This parameter must be
# provided for PID heaters.
pid_Kd: 0.1
#pid_Kd: 0.1
# Kd is the "derivative" constant for the pid. This parameter must
# be provided for PID heaters.
#pid_deriv_time: 2.0
@ -263,6 +274,7 @@ pid_Kd: 0.1
# The maximum "windup" the integral term may accumulate. The default
# is to use the same value as max_power.
# Additional micro-controllers (one may define any number of sections
# with an "mcu" prefix). Additional micro-controllers introduce
# additional pins that may be configured as heaters, steppers, fans,

View File

@ -229,6 +229,10 @@ pin: ar9
# will be scaled between zero and max_power (for example, if
# max_power is .9 and a fan speed of 80% is requested then the fan
# power will be set to 72%). The default is 1.0.
#shutdown_speed: 0
# The desired fan speed (expressed as a value from 0.0 to 1.0) if
# the micro-controller software enters an error state. The default
# is 0.
#cycle_time: 0.010
# The amount of time (in seconds) for each PWM power cycle to the
# fan. It is recommended this be 10 milliseconds or greater when

View File

@ -7,7 +7,7 @@
FAN_MIN_TIME = 0.100
class PrinterFan:
def __init__(self, config):
def __init__(self, config, default_shutdown_speed=0.):
self.last_fan_value = 0.
self.last_fan_time = 0.
self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.)
@ -18,8 +18,10 @@ class PrinterFan:
cycle_time = config.getfloat('cycle_time', 0.010, above=0.)
hardware_pwm = config.getboolean('hardware_pwm', False)
self.mcu_fan.setup_cycle_time(cycle_time, hardware_pwm)
def set_shutdown_speed(self, speed):
self.mcu_fan.setup_start_value(0., max(0., min(self.max_power, speed)))
shutdown_speed = config.getfloat(
'shutdown_speed', default_shutdown_speed, minval=0., maxval=1.)
self.mcu_fan.setup_start_value(
0., max(0., min(self.max_power, shutdown_speed)))
def set_speed(self, print_time, value):
value = max(0., min(self.max_power, value * self.max_power))
if value == self.last_fan_value:

View File

@ -12,10 +12,9 @@ class PrinterHeaterFan:
self.printer = config.get_printer()
self.heater_name = config.get("heater", "extruder0")
self.heater_temp = config.getfloat("heater_temp", 50.0)
self.fan = fan.PrinterFan(config)
self.fan = fan.PrinterFan(config, default_shutdown_speed=1.)
self.mcu = self.fan.mcu_fan.get_mcu()
self.fan_speed = config.getfloat("fan_speed", 1., minval=0., maxval=1.)
self.fan.set_shutdown_speed(1.)
def printer_state(self, state):
if state == 'ready':
pheater = self.printer.lookup_object('heater')

View File

@ -14,7 +14,7 @@ class TemperatureFan:
def __init__(self, config):
self.name = config.get_name()
self.printer = config.get_printer()
self.fan = fan.PrinterFan(config)
self.fan = fan.PrinterFan(config, default_shutdown_speed=1.)
self.mcu = self.fan.mcu_fan.get_mcu()
self.min_temp = config.getfloat('min_temp', minval=KELVIN_TO_CELCIUS)
self.max_temp = config.getfloat('max_temp', above=self.min_temp)
@ -22,7 +22,6 @@ class TemperatureFan:
self.sensor.setup_minmax(self.min_temp, self.max_temp)
self.sensor.setup_callback(self.temperature_callback)
self.speed_delay = self.sensor.get_report_time_delta()
self.fan.set_shutdown_speed(1.)
self.max_speed = config.getfloat('max_speed', 1., above=0., maxval=1.)
self.min_speed = config.getfloat('min_speed', 0.3, above=0., maxval=1.)
self.last_temp = 0.