pid_calibrate: Support saving calibration data via SAVE_CONFIG

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-09-17 19:28:07 -04:00 committed by KevinOConnor
parent 531134f092
commit 5a1b2d61ae
2 changed files with 11 additions and 4 deletions

View File

@ -139,8 +139,8 @@ To calibrate the extruder, navigate to the OctoPrint terminal tab and
run the PID_CALIBRATE command. For example: `PID_CALIBRATE run the PID_CALIBRATE command. For example: `PID_CALIBRATE
HEATER=extruder TARGET=170` HEATER=extruder TARGET=170`
At the completion of the tuning test, update the printer.cfg file with At the completion of the tuning test run `SAVE_CONFIG` to update the
the recommended pid_Kp, pid_Ki, and pid_Kd values. printer.cfg file the new PID settings.
If the printer has a heated bed and it supports being driven by PWM If the printer has a heated bed and it supports being driven by PWM
(Pulse Width Modulation) then it is recommended to use PID control for (Pulse Width Modulation) then it is recommended to use PID control for

View File

@ -35,12 +35,19 @@ class PIDCalibrate:
heater.set_control(old_control) heater.set_control(old_control)
if write_file: if write_file:
calibrate.write_file('/tmp/heattest.txt') calibrate.write_file('/tmp/heattest.txt')
# Log and report results
Kp, Ki, Kd = calibrate.calc_final_pid() Kp, Ki, Kd = calibrate.calc_final_pid()
logging.info("Autotune: final: Kp=%f Ki=%f Kd=%f", Kp, Ki, Kd) logging.info("Autotune: final: Kp=%f Ki=%f Kd=%f", Kp, Ki, Kd)
self.gcode.respond_info( self.gcode.respond_info(
"PID parameters: pid_Kp=%.3f pid_Ki=%.3f pid_Kd=%.3f\n" "PID parameters: pid_Kp=%.3f pid_Ki=%.3f pid_Kd=%.3f\n"
"To use these parameters, update the printer config file with\n" "The SAVE_CONFIG command will update the printer config file\n"
"the above and then issue a RESTART command" % (Kp, Ki, Kd)) "with these parameters and restart the printer." % (Kp, Ki, Kd))
# Store results for SAVE_CONFIG
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,))
TUNE_PID_DELTA = 5.0 TUNE_PID_DELTA = 5.0