Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to modify PID parameters without a reload #35

Merged
merged 3 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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