Skip to content

Commit

Permalink
Add ability to modify PID parameters without a reload (#35)
Browse files Browse the repository at this point in the history
* Add ability to set heater PID without on the fly

* Add docs for Set_HEATER_PID

* Fix line-length limit

Co-authored-by: Lasse Dalegaard <dalegaard@gmail.com>
  • Loading branch information
kmobs and dalegaard authored Nov 5, 2022
1 parent ae06f7b commit e886821
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/G-Codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,11 @@ WRITE_FILE parameter is enabled, then the file /tmp/heattest.txt will
be created with a log of all temperature samples taken during the
test.

#### SET_HEATER_PID
`SET_HEATER_PID HEATER=<config_name> KP=<kp> KI=<ki> KD=<kd>`: Will
allow one to manually change PID parameters of heaters without a
reload of the firmware.

### [pause_resume]

The following commands are available when the
Expand Down
22 changes: 22 additions & 0 deletions klippy/extras/heaters.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ def __init__(self, config, sensor):
self.cmd_SET_HEATER_TEMPERATURE,
desc=self.cmd_SET_HEATER_TEMPERATURE_help,
)
gcode.register_mux_command(
"SET_HEATER_PID",
"HEATER",
self.name,
self.cmd_SET_HEATER_PID,
desc=self.cmd_SET_HEATER_PID_help,
)

def set_pwm(self, read_time, value):
if self.target_temp <= 0.0:
Expand Down Expand Up @@ -180,6 +187,21 @@ def cmd_SET_HEATER_TEMPERATURE(self, gcmd):
pheaters = self.printer.lookup_object("heaters")
pheaters.set_temperature(self, temp)

cmd_SET_HEATER_PID_help = "Sets a heater PID parameter"

def cmd_SET_HEATER_PID(self, gcmd):
if not isinstance(self.control, ControlPID):
raise gcmd.error("Not a PID controlled heater")
kp = gcmd.get_float("KP", None)
if kp is not None:
self.control.Kp = kp / PID_PARAM_BASE
ki = gcmd.get_float("KI", None)
if ki is not None:
self.control.Ki = ki / PID_PARAM_BASE
kd = gcmd.get_float("KD", None)
if kd is not None:
self.control.Kd = kd / PID_PARAM_BASE


######################################################################
# Bang-bang control algo
Expand Down

0 comments on commit e886821

Please sign in to comment.