aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2024-03-05 19:24:03 -0500
committerKevin O'Connor <kevin@koconnor.net>2024-03-13 21:41:04 -0400
commitbddefdde36cab33b19df7e46824e922e9c045527 (patch)
tree2d0ace1c9e2068f27914b32c71ed64a01d9b3cef
parent0105aa330f2a4865b01cbbc548cba1322be5371e (diff)
downloadkutter-bddefdde36cab33b19df7e46824e922e9c045527.tar.gz
kutter-bddefdde36cab33b19df7e46824e922e9c045527.tar.xz
kutter-bddefdde36cab33b19df7e46824e922e9c045527.zip
pid_calibrate: Fix PID_CALIBRATE command when used with heater_generic
Make sure the SAVE_CONFIG command saves the calculated PID parameters to the correct config name. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--klippy/extras/heaters.py11
-rw-r--r--klippy/extras/pid_calibrate.py9
2 files changed, 12 insertions, 8 deletions
diff --git a/klippy/extras/heaters.py b/klippy/extras/heaters.py
index 1c29aae8..6c8fb822 100644
--- a/klippy/extras/heaters.py
+++ b/klippy/extras/heaters.py
@@ -18,7 +18,8 @@ PID_PARAM_BASE = 255.
class Heater:
def __init__(self, config, sensor):
self.printer = config.get_printer()
- self.name = config.get_name().split()[-1]
+ self.name = config.get_name()
+ self.short_name = short_name = self.name.split()[-1]
# Setup sensor
self.sensor = sensor
self.min_temp = config.getfloat('min_temp', minval=KELVIN_TO_CELSIUS)
@@ -55,11 +56,11 @@ class Heater:
self.mcu_pwm.setup_cycle_time(pwm_cycle_time)
self.mcu_pwm.setup_max_duration(MAX_HEAT_TIME)
# Load additional modules
- self.printer.load_object(config, "verify_heater %s" % (self.name,))
+ self.printer.load_object(config, "verify_heater %s" % (short_name,))
self.printer.load_object(config, "pid_calibrate")
gcode = self.printer.lookup_object("gcode")
gcode.register_mux_command("SET_HEATER_TEMPERATURE", "HEATER",
- self.name, self.cmd_SET_HEATER_TEMPERATURE,
+ short_name, self.cmd_SET_HEATER_TEMPERATURE,
desc=self.cmd_SET_HEATER_TEMPERATURE_help)
def set_pwm(self, read_time, value):
if self.target_temp <= 0.:
@@ -87,6 +88,8 @@ class Heater:
self.can_extrude = (self.smoothed_temp >= self.min_extrude_temp)
#logging.debug("temp: %.3f %f = %f", read_time, temp)
# External commands
+ def get_name(self):
+ return self.name
def get_pwm_delay(self):
return self.pwm_delay
def get_max_power(self):
@@ -127,7 +130,7 @@ class Heater:
last_pwm_value = self.last_pwm_value
is_active = target_temp or last_temp > 50.
return is_active, '%s: target=%.0f temp=%.1f pwm=%.3f' % (
- self.name, target_temp, last_temp, last_pwm_value)
+ self.short_name, target_temp, last_temp, last_pwm_value)
def get_status(self, eventtime):
with self.lock:
target_temp = self.target_temp
diff --git a/klippy/extras/pid_calibrate.py b/klippy/extras/pid_calibrate.py
index f32f1be7..20641167 100644
--- a/klippy/extras/pid_calibrate.py
+++ b/klippy/extras/pid_calibrate.py
@@ -43,11 +43,12 @@ class PIDCalibrate:
"The SAVE_CONFIG command will update the printer config file\n"
"with these parameters and restart the printer." % (Kp, Ki, Kd))
# Store results for SAVE_CONFIG
+ cfgname = heater.get_name()
configfile = self.printer.lookup_object('configfile')
- configfile.set(heater_name, 'control', 'pid')
- configfile.set(heater_name, 'pid_Kp', "%.3f" % (Kp,))
- configfile.set(heater_name, 'pid_Ki', "%.3f" % (Ki,))
- configfile.set(heater_name, 'pid_Kd', "%.3f" % (Kd,))
+ configfile.set(cfgname, 'control', 'pid')
+ configfile.set(cfgname, 'pid_Kp', "%.3f" % (Kp,))
+ configfile.set(cfgname, 'pid_Ki', "%.3f" % (Ki,))
+ configfile.set(cfgname, 'pid_Kd', "%.3f" % (Kd,))
TUNE_PID_DELTA = 5.0