Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Tweaked for allowing TUNE_PID_DELTA to pass through gcode
  • Loading branch information
SHKinsem authored Sep 21, 2023
1 parent 8ef0f7d commit 930514d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions klippy/extras/pid_calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ def __init__(self, config):
def cmd_PID_CALIBRATE(self, gcmd):
heater_name = gcmd.get('HEATER')
target = gcmd.get_float('TARGET')
tune_pid_delta = gcmd.get_float('TUNE_PID_DELTA', 5.0)
write_file = gcmd.get_int('WRITE_FILE', 0)
pheaters = self.printer.lookup_object('heaters')
try:
heater = pheaters.lookup_heater(heater_name)
except self.printer.config_error as e:
raise gcmd.error(str(e))
self.printer.lookup_object('toolhead').get_last_move_time()
calibrate = ControlAutoTune(heater, target)
calibrate = ControlAutoTune(heater, target, tune_pid_delta)
old_control = heater.set_control(calibrate)
try:
pheaters.set_temperature(heater, target, True)
Expand All @@ -39,6 +40,7 @@ def cmd_PID_CALIBRATE(self, gcmd):
Kp, Ki, Kd = calibrate.calc_final_pid()
logging.info("Autotune: final: Kp=%f Ki=%f Kd=%f", Kp, Ki, Kd)
gcmd.respond_info(
"File had been changed."
"PID parameters: pid_Kp=%.3f pid_Ki=%.3f pid_Kd=%.3f\n"
"The SAVE_CONFIG command will update the printer config file\n"
"with these parameters and restart the printer." % (Kp, Ki, Kd))
Expand All @@ -49,13 +51,13 @@ def cmd_PID_CALIBRATE(self, gcmd):
configfile.set(heater_name, 'pid_Ki', "%.3f" % (Ki,))
configfile.set(heater_name, 'pid_Kd', "%.3f" % (Kd,))

TUNE_PID_DELTA = 5.0

class ControlAutoTune:
def __init__(self, heater, target):
def __init__(self, heater, target, tune_pid_delta):
self.heater = heater
self.heater_max_power = heater.get_max_power()
self.calibrate_temp = target
self.tune_pid_delta = tune_pid_delta
# Heating control
self.heating = False
self.peak = 0.
Expand All @@ -80,7 +82,7 @@ def temperature_update(self, read_time, temp, target_temp):
if self.heating and temp >= target_temp:
self.heating = False
self.check_peaks()
self.heater.alter_target(self.calibrate_temp - TUNE_PID_DELTA)
self.heater.alter_target(self.calibrate_temp - self.tune_pid_delta)
elif not self.heating and temp <= target_temp:
self.heating = True
self.check_peaks()
Expand Down

0 comments on commit 930514d

Please sign in to comment.