From ade7a4df3c667e674f48be7662b44cc02bec666c Mon Sep 17 00:00:00 2001 From: Gareth Farrington Date: Sat, 3 Feb 2024 09:16:38 -0800 Subject: [PATCH] PR: Enable multiple z_thermal_adjust sections Multiple `z_thermal_adjust` sections may now be defined in config to compensate for different sources of z thermal expansion that happen at different rates. Signed-off-by: Gareth Farrington --- docs/Config_Reference.md | 4 +++- docs/G-Codes.md | 14 +++++++++----- klippy/extras/z_thermal_adjust.py | 23 +++++++++++++++++++---- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index 860674754..03ba8044b 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -1240,7 +1240,9 @@ the nature of skew correction these lengths are set via gcode. See Temperature-dependant toolhead Z position adjustment. Compensate for vertical toolhead movement caused by thermal expansion of the printer's frame in real-time using a temperature sensor (typically coupled to a vertical section -of frame). +of frame). Multiple sections may be defined as [z_thermal_adjust component] to +compensate for thermal expansion in different printer components, such as the +hotend, heatbreak and frame. See also: [extended g-code commands](G-Codes.md#z_thermal_adjust). diff --git a/docs/G-Codes.md b/docs/G-Codes.md index b22728875..39d06d50d 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -1486,15 +1486,19 @@ The following commands are available when the is enabled. #### SET_Z_THERMAL_ADJUST -`SET_Z_THERMAL_ADJUST [ENABLE=<0:1>] [TEMP_COEFF=] [REF_TEMP=]`: -Enable or disable the Z thermal adjustment with `ENABLE`. Disabling does not +`SET_Z_THERMAL_ADJUST [COMPONENT=name] [ENABLE=<0:1>] [TEMP_COEFF=] + [REF_TEMP=]`: +- `COMPONENT`: if multiple thermal adjustments are defined use `COMPONENT` to +specify which one to adjust. +- `ENABLE`: Enable or disable the Z thermal adjustment. Disabling does not remove any adjustment already applied, but will freeze the current adjustment value - this prevents potentially unsafe downward Z movement. Re-enabling can potentially cause upward tool movement as the adjustment is updated and applied. -`TEMP_COEFF` allows run-time tuning of the adjustment temperature coefficient +- `TEMP_COEFF`: allows run-time tuning of the adjustment temperature coefficient (i.e. the `TEMP_COEFF` config parameter). `TEMP_COEFF` values are not saved to -the config. `REF_TEMP` manually overrides the reference temperature typically -set during homing (for use in e.g. non-standard homing routines) - will be reset +the config. +- `REF_TEMP` manually overrides the reference temperature typically set during +homing (for use in e.g. non-standard homing routines) - will be reset automatically upon homing. ### [z_tilt] diff --git a/klippy/extras/z_thermal_adjust.py b/klippy/extras/z_thermal_adjust.py index 0fa0bff0d..f633b0818 100644 --- a/klippy/extras/z_thermal_adjust.py +++ b/klippy/extras/z_thermal_adjust.py @@ -56,8 +56,15 @@ class ZThermalAdjuster: self.next_transform = None # Register gcode commands - self.gcode.register_command('SET_Z_THERMAL_ADJUST', - self.cmd_SET_Z_THERMAL_ADJUST, + full_name = config.get_name() + self.component = None + if not full_name == "z_thermal_adjust": + self.component = full_name.split(maxsplit=1)[-1] + self.register_commands(self.component) + + def register_commands(self, component): + self.gcode.register_mux_command("SET_Z_THERMAL_ADJUST", "COMPONENT", + component, self.cmd_SET_Z_THERMAL_ADJUST, desc=self.cmd_SET_Z_THERMAL_ADJUST_help) def handle_connect(self): @@ -169,13 +176,18 @@ class ZThermalAdjuster: state = '1 (enabled)' if self.adjust_enable else '0 (disabled)' override = ' (manual)' if self.ref_temp_override else '' - msg = ("enable: %s\n" + component = '' + if not self.component is None: + component = "component: %s\n" % (self.component,) + msg = ("%s" + "enable: %s\n" "temp_coeff: %f mm/degC\n" "ref_temp: %.2f degC%s\n" "-------------------\n" "Current Z temp: %.2f degC\n" "Applied Z adjustment: %.4f mm" - % (state, + % (component, + state, self.temp_coeff, self.ref_temperature, override, self.smoothed_temp, @@ -185,5 +197,8 @@ class ZThermalAdjuster: cmd_SET_Z_THERMAL_ADJUST_help = 'Set/query Z Thermal Adjust parameters.' +def load_config_prefix(config): + return ZThermalAdjuster(config) + def load_config(config): return ZThermalAdjuster(config)