Skip to content

Commit

Permalink
Fixes PID-Profiles for heater_generic and fixed doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeanon authored and rogerlz committed May 23, 2024
1 parent f52b1d0 commit c02b0f4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
11 changes: 8 additions & 3 deletions docs/G-Codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1042,15 +1042,20 @@ noise readings might allow 0.01, to be used, while noisy reading might
require a value of 0.03 or higher.

#### SET_HEATER_PID
`SET_HEATER_PID HEATER=<config_name> KP=<kp> KI=<ki> KD=<kd>`: Will
`SET_HEATER_PID HEATER=<heater_name> KP=<kp> KI=<ki> KD=<kd>`: Will
allow one to manually change PID parameters of heaters without a
reload of the firmware.
HEATER takes the short name (so for `heater_generic chamber` you would only
write `chamber`)

### [pid_profile]

The PID_PROFILE module is automatically loaded if a heater is defined
in the config file.

HEATER generally takes the short name (so for `heater_generic chamber` you would
only write `chamber`)

#### PID_PROFILE
`PID_PROFILE LOAD=<profile_name> HEATER=<heater_name> [DEFAULT=<profile_name>]
[VERBOSE=<verbosity>] [KEEP_TARGET=0|1] [LOAD_CLEAN=0|1]`:
Expand All @@ -1068,11 +1073,11 @@ started up, if set to 0, the profile will retain previous heating information.
By default the information will be kept to reduce overshoot, change this value
if you encounter weird behaviour while switching profiles.

`PID_PROFILE SAVE=<profile_name> HEATER=<config_name>`:
`PID_PROFILE SAVE=<profile_name> HEATER=<heater_name>`:
Saves the currently loaded profile of the specified heater to the config under
the given name.

`PID_PROFILE REMOVE=<profile_name> HEATER=<config_name>`:
`PID_PROFILE REMOVE=<profile_name> HEATER=<heater_name>`:
Removes the given profile from the profiles List for the current session and config if SAVE_CONFIG is issued afterwards.

`PID_PROFILE SET_VALUES=<profile_name> HEATER=<heater_name> TARGET=<target_temp> TOLERANCE=<tolerance>
Expand Down
32 changes: 19 additions & 13 deletions klippy/extras/heaters.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,12 @@ def __init__(self, outer_instance):
self.incompatible_profiles = []
# Fetch stored profiles from Config
stored_profs = self.outer_instance.config.get_prefix_sections(
"pid_profile %s" % self.outer_instance.name
"pid_profile %s" % self.outer_instance.short_name
)
for profile in stored_profs:
self._init_profile(profile, profile.get_name().split(" ", 2)[2])
self._init_profile(
profile, profile.get_name().split(" ", 2)[-1]
)

def _init_profile(self, config_section, name):
version = config_section.getint("pid_version", 1)
Expand Down Expand Up @@ -331,7 +333,7 @@ def _init_profile(self, config_section, name):
raise self.outer_instance.printer.config_error(
"Unknown control type '%s' "
"in [pid_profile %s %s]."
% (control, self.outer_instance.name, name)
% (control, self.outer_instance.short_name, name)
)
temp_profile["control"] = control
temp_profile["name"] = name
Expand All @@ -349,17 +351,21 @@ def _check_value_config(self, key, config_section, type, can_be_none):
raise self.outer_instance.gcode.error(
"pid_profile: '%s' has to be "
"specified in [pid_profile %s %s]."
% (key, self.outer_instance.name, config_section.get_name())
% (
key,
self.outer_instance.short_name,
config_section.get_name(),
)
)
return value

def _compute_section_name(self, profile_name):
return (
self.outer_instance.name
self.outer_instance.short_name
if profile_name == "default"
else (
"pid_profile "
+ self.outer_instance.name
+ self.outer_instance.short_name
+ " "
+ profile_name
)
Expand Down Expand Up @@ -494,7 +500,7 @@ def save_profile(self, profile_name=None, gcmd=None, verbose=True):
"has been saved to profile [%s] "
"for the current session. The SAVE_CONFIG command will\n"
"update the printer config file and restart the printer."
% (self.outer_instance.name, profile_name)
% (self.outer_instance.short_name, profile_name)
)

def load_profile(self, profile_name, gcmd, verbose):
Expand All @@ -512,7 +518,7 @@ def load_profile(self, profile_name, gcmd, verbose):
if verbose == "high" or verbose == "low":
self.outer_instance.gcode.respond_info(
"PID Profile [%s] already loaded for heater [%s]."
% (profile_name, self.outer_instance.name)
% (profile_name, self.outer_instance.short_name)
)
return
keep_target = self._check_value_gcmd(
Expand All @@ -525,15 +531,15 @@ def load_profile(self, profile_name, gcmd, verbose):
if default is None:
raise self.outer_instance.gcode.error(
"pid_profile: Unknown profile [%s] for heater [%s]."
% (profile_name, self.outer_instance.name)
% (profile_name, self.outer_instance.short_name)
)
profile = self.profiles.get(default, None)
defaulted = True
if profile is None:
raise self.outer_instance.gcode.error(
"pid_profile: Unknown default "
"profile [%s] for heater [%s]."
% (default, self.outer_instance.name)
% (default, self.outer_instance.short_name)
)
control = self.outer_instance.lookup_control(profile, load_clean)
self.outer_instance.set_control(control, keep_target)
Expand All @@ -545,11 +551,11 @@ def load_profile(self, profile_name, gcmd, verbose):
"Couldn't find profile "
"[%s] for heater [%s]"
", defaulted to [%s]."
% (profile_name, self.outer_instance.name, default)
% (profile_name, self.outer_instance.short_name, default)
)
self.outer_instance.gcode.respond_info(
"PID Profile [%s] loaded for heater [%s].\n"
% (profile["name"], self.outer_instance.name)
% (profile["name"], self.outer_instance.short_name)
)
if verbose == "high":
smooth_time = (
Expand Down Expand Up @@ -587,7 +593,7 @@ def remove_profile(self, profile_name, gcmd, verbose):
"removed from storage for this session.\n"
"The SAVE_CONFIG command will update the printer\n"
"configuration and restart the printer"
% (profile_name, self.outer_instance.name)
% (profile_name, self.outer_instance.short_name)
)
else:
self.outer_instance.gcode.respond_info(
Expand Down
25 changes: 18 additions & 7 deletions test/klippy/pid_profile.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ pid_Kd: 114
min_temp: 0
max_temp: 210

[extruder_stepper my_extra_stepper]
extruder: extruder
step_pin: PH5
dir_pin: PH6
enable_pin: !PB5
microsteps: 16
rotation_distance: 28.2
[heater_generic chamber]
heater_pin: PH5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PH6
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 120


[mcu]
serial: /dev/ttyACM0
Expand All @@ -73,3 +77,10 @@ control: pid
pid_kp: 22.200
pid_ki: 1.080
pid_kd: 114.000

[pid_profile chamber TEST]
pid_version: 1
control: pid
pid_kp: 22.200
pid_ki: 1.080
pid_kd: 114.000
6 changes: 5 additions & 1 deletion test/klippy/pid_profile.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ G1 X25 Y25 E7.5
PID_PROFILE SAVE=TESTPROFILE HEATER=extruder
PID_PROFILE LOAD=TESTPROFILE HEATER=extruder

PID_PROFILE LOAD=TEST HEATER=chamber
PID_PROFILE SAVE=TESTPROFILE HEATER=chamber
PID_PROFILE LOAD=TESTPROFILE HEATER=chamber

# set the smooth time and save to the profile
SET_SMOOTH_TIME HEATER=extruder SMOOTH_TIME=1 SAVE_TO_PROFILE=1

# remove an existing profile
PID_PROFILE REMOVE=FROM_CONFIG HEATER=extruder
PID_PROFILE REMOVE=TEST HEATER=chamber

# PID_PROFILE SET_VALUES cant be tested

0 comments on commit c02b0f4

Please sign in to comment.