pid_calibrate: Use new GCodeCommand wrappers

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-04-24 22:51:06 -04:00
parent 12b20c6e77
commit a79096efdf
1 changed files with 9 additions and 10 deletions

View File

@ -9,20 +9,19 @@ import heaters
class PIDCalibrate:
def __init__(self, config):
self.printer = config.get_printer()
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command(
'PID_CALIBRATE', self.cmd_PID_CALIBRATE,
desc=self.cmd_PID_CALIBRATE_help)
gcode = self.printer.lookup_object('gcode')
gcode.register_command('PID_CALIBRATE', self.cmd_PID_CALIBRATE,
desc=self.cmd_PID_CALIBRATE_help)
cmd_PID_CALIBRATE_help = "Run PID calibration test"
def cmd_PID_CALIBRATE(self, params):
heater_name = self.gcode.get_str('HEATER', params)
target = self.gcode.get_float('TARGET', params)
write_file = self.gcode.get_int('WRITE_FILE', params, 0)
def cmd_PID_CALIBRATE(self, gcmd):
heater_name = gcmd.get('HEATER')
target = gcmd.get_float('TARGET')
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 self.gcode.error(str(e))
raise gcmd.error(str(e))
self.printer.lookup_object('toolhead').get_last_move_time()
calibrate = ControlAutoTune(heater, target)
old_control = heater.set_control(calibrate)
@ -38,7 +37,7 @@ class PIDCalibrate:
# Log and report results
Kp, Ki, Kd = calibrate.calc_final_pid()
logging.info("Autotune: final: Kp=%f Ki=%f Kd=%f", Kp, Ki, Kd)
self.gcode.respond_info(
gcmd.respond_info(
"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))