From ca83c13f375578baa289a18ff31a5f602ae74225 Mon Sep 17 00:00:00 2001 From: Dmitry Butyugin Date: Sat, 10 May 2025 20:25:46 +0200 Subject: [PATCH] generic_cartesian: Fixed safe_z_home and manual_probe for new kinematics Signed-off-by: Dmitry Butyugin Signed-off-by: Kevin O'Connor --- klippy/extras/manual_probe.py | 35 +++++++++++++++++++++++++---------- klippy/extras/probe.py | 7 ++----- klippy/extras/safe_z_home.py | 5 ++++- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/klippy/extras/manual_probe.py b/klippy/extras/manual_probe.py index 496455fa..92f2d0f6 100644 --- a/klippy/extras/manual_probe.py +++ b/klippy/extras/manual_probe.py @@ -5,6 +5,14 @@ # This file may be distributed under the terms of the GNU GPLv3 license. import logging, bisect +# Helper to lookup the Z stepper config section +def lookup_z_endstop_config(config): + if config.has_section('stepper_z'): + return config.getsection('stepper_z') + elif config.has_section('carriage z'): + return config.getsection('carriage z') + return None + class ManualProbe: def __init__(self, config): self.printer = config.get_printer() @@ -14,9 +22,13 @@ class ManualProbe: self.gcode.register_command('MANUAL_PROBE', self.cmd_MANUAL_PROBE, desc=self.cmd_MANUAL_PROBE_help) # Endstop value for cartesian printers with separate Z axis - zconfig = config.getsection('stepper_z') - self.z_position_endstop = zconfig.getfloat('position_endstop', None, - note_valid=False) + zconfig = lookup_z_endstop_config(config) + if zconfig is not None: + self.z_position_endstop = zconfig.getfloat('position_endstop', None, + note_valid=False) + self.z_endstop_config_name = zconfig.get_name() + else: + self.z_position_endstop = self.z_endstop_config_name = None # Endstop values for linear delta printers with vertical A,B,C towers a_tower_config = config.getsection('stepper_a') self.a_position_endstop = a_tower_config.getfloat('position_endstop', @@ -67,11 +79,13 @@ class ManualProbe: return z_pos = self.z_position_endstop - kin_pos[2] self.gcode.respond_info( - "stepper_z: position_endstop: %.3f\n" + "%s: position_endstop: %.3f\n" "The SAVE_CONFIG command will update the printer config file\n" - "with the above and restart the printer." % (z_pos,)) + "with the above and restart the printer." % ( + self.z_endstop_config_name, z_pos,)) configfile = self.printer.lookup_object('configfile') - configfile.set('stepper_z', 'position_endstop', "%.3f" % (z_pos,)) + configfile.set(self.z_endstop_config_name, 'position_endstop', + "%.3f" % (z_pos,)) cmd_Z_ENDSTOP_CALIBRATE_help = "Calibrate a Z endstop" def cmd_Z_ENDSTOP_CALIBRATE(self, gcmd): ManualProbeHelper(self.printer, gcmd, self.z_endstop_finalize) @@ -83,11 +97,12 @@ class ManualProbe: else: new_calibrate = self.z_position_endstop - offset self.gcode.respond_info( - "stepper_z: position_endstop: %.3f\n" + "%s: position_endstop: %.3f\n" "The SAVE_CONFIG command will update the printer config file\n" - "with the above and restart the printer." % (new_calibrate)) - configfile.set('stepper_z', 'position_endstop', - "%.3f" % (new_calibrate,)) + "with the above and restart the printer." % ( + self.z_endstop_config_name, new_calibrate)) + configfile.set(self.z_endstop_config_name, 'position_endstop', + "%.3f" % (new_calibrate,)) def cmd_Z_OFFSET_APPLY_DELTA_ENDSTOPS(self,gcmd): offset = self.gcode_move.get_status()['homing_origin'].z configfile = self.printer.lookup_object('configfile') diff --git a/klippy/extras/probe.py b/klippy/extras/probe.py index 64d5f855..3de192c0 100644 --- a/klippy/extras/probe.py +++ b/klippy/extras/probe.py @@ -174,11 +174,8 @@ class ProbeCommandHelper: # Helper to lookup the minimum Z position for the printer def lookup_minimum_z(config): - if config.has_section('stepper_z'): - zconfig = config.getsection('stepper_z') - return zconfig.getfloat('position_min', 0., note_valid=False) - elif config.has_section('carriage z'): - zconfig = config.getsection('carriage z') + zconfig = manual_probe.lookup_z_endstop_config(config) + if zconfig is not None: return zconfig.getfloat('position_min', 0., note_valid=False) pconfig = config.getsection('printer') return pconfig.getfloat('minimum_z_position', 0., note_valid=False) diff --git a/klippy/extras/safe_z_home.py b/klippy/extras/safe_z_home.py index 32b515b9..1693487a 100644 --- a/klippy/extras/safe_z_home.py +++ b/klippy/extras/safe_z_home.py @@ -3,6 +3,7 @@ # Copyright (C) 2019 Florian Heilmann # # This file may be distributed under the terms of the GNU GPLv3 license. +from . import manual_probe class SafeZHoming: def __init__(self, config): @@ -11,7 +12,9 @@ class SafeZHoming: self.home_x_pos, self.home_y_pos = x_pos, y_pos self.z_hop = config.getfloat("z_hop", default=0.0) self.z_hop_speed = config.getfloat('z_hop_speed', 15., above=0.) - zconfig = config.getsection('stepper_z') + zconfig = manual_probe.lookup_z_endstop_config(config) + if zconfig is None: + raise gcmd.error('Missing Z endstop config for safe_z_homing') self.max_z = zconfig.getfloat('position_max', note_valid=False) self.speed = config.getfloat('speed', 50.0, above=0.) self.move_to_previous = config.getboolean('move_to_previous', False)