From 9887e725702aa4867f4fa03fecb243a32e5c8880 Mon Sep 17 00:00:00 2001 From: fess Date: Fri, 17 May 2019 20:47:27 -0700 Subject: [PATCH] probe: ProbePointsHelper adjustable minimum points Factor out minimum required points check for ProbePointsHelper in prep for setting different values for quad_gantry_level and z_tilt_adjust Signed-off-by: John "Fess" Fessenden --- klippy/extras/bed_mesh.py | 1 + klippy/extras/bed_tilt.py | 1 + klippy/extras/delta_calibrate.py | 1 + klippy/extras/probe.py | 10 ++++++---- klippy/extras/quad_gantry_level.py | 1 + klippy/extras/screws_tilt_adjust.py | 1 + klippy/extras/z_tilt.py | 1 + 7 files changed, 12 insertions(+), 4 deletions(-) diff --git a/klippy/extras/bed_mesh.py b/klippy/extras/bed_mesh.py index ec2b88ad..84977805 100644 --- a/klippy/extras/bed_mesh.py +++ b/klippy/extras/bed_mesh.py @@ -195,6 +195,7 @@ class BedMeshCalibrate: self._init_probe_params(config, points) self.probe_helper = probe.ProbePointsHelper( config, self.probe_finalize, points) + self.probe_helper.minimum_points(3) # setup persistent storage self.profiles = {} self._load_storage(config) diff --git a/klippy/extras/bed_tilt.py b/klippy/extras/bed_tilt.py index b94bf189..0826f765 100644 --- a/klippy/extras/bed_tilt.py +++ b/klippy/extras/bed_tilt.py @@ -44,6 +44,7 @@ class BedTiltCalibrate: self.printer = config.get_printer() self.bedtilt = bedtilt self.probe_helper = probe.ProbePointsHelper(config, self.probe_finalize) + self.probe_helper.minimum_points(3) # Register BED_TILT_CALIBRATE command self.gcode = self.printer.lookup_object('gcode') self.gcode.register_command( diff --git a/klippy/extras/delta_calibrate.py b/klippy/extras/delta_calibrate.py index 429779aa..cc74c0b8 100644 --- a/klippy/extras/delta_calibrate.py +++ b/klippy/extras/delta_calibrate.py @@ -143,6 +143,7 @@ class DeltaCalibrate: points.append((math.cos(r) * dist, math.sin(r) * dist)) self.probe_helper = probe.ProbePointsHelper( config, self.probe_finalize, default_points=points) + self.probe_helper.minimum_points(3) # Restore probe stable positions self.last_probe_positions = [] for i in range(999): diff --git a/klippy/extras/probe.py b/klippy/extras/probe.py index 09363056..84bf5c9d 100644 --- a/klippy/extras/probe.py +++ b/klippy/extras/probe.py @@ -226,6 +226,7 @@ class ProbePointsHelper: self.printer = config.get_printer() self.finalize_callback = finalize_callback self.probe_points = default_points + self.name = config.get_name() # Read config settings if default_points is None or config.get('points', None) is not None: points = config.get('points').split('\n') @@ -235,10 +236,7 @@ class ProbePointsHelper: for p in points] except: raise config.error("Unable to parse probe points in %s" % ( - config.get_name())) - if len(self.probe_points) < 3: - raise config.error("Need at least 3 probe points for %s" % ( - config.get_name())) + self.name)) self.horizontal_move_z = config.getfloat('horizontal_move_z', 5.) self.speed = self.lift_speed = config.getfloat('speed', 50., above=0.) self.probe_offsets = (0., 0., 0.) @@ -252,6 +250,10 @@ class ProbePointsHelper: self.results = [] self.busy = self.manual_probe = False self.gcode = self.toolhead = None + def minimum_points(self,n): + if len(self.probe_points) < n: + raise self.printer.config_error( + "Need at least %d probe points for %s" % (n, self.name)) def get_lift_speed(self): return self.lift_speed def _lift_z(self, z_pos, add=False, speed=None): diff --git a/klippy/extras/quad_gantry_level.py b/klippy/extras/quad_gantry_level.py index 32dd3b7d..09f7e886 100644 --- a/klippy/extras/quad_gantry_level.py +++ b/klippy/extras/quad_gantry_level.py @@ -14,6 +14,7 @@ class QuadGantryLevel: self.printer.register_event_handler("klippy:connect", self.handle_connect) self.probe_helper = probe.ProbePointsHelper(config, self.probe_finalize) + self.probe_helper.minimum_points(3) gantry_corners = config.get('gantry_corners').split('\n') try: gantry_corners = [line.split(',', 1) diff --git a/klippy/extras/screws_tilt_adjust.py b/klippy/extras/screws_tilt_adjust.py index 663127c2..35a87699 100644 --- a/klippy/extras/screws_tilt_adjust.py +++ b/klippy/extras/screws_tilt_adjust.py @@ -46,6 +46,7 @@ class ScrewsTiltAdjust: self.probe_helper = probe.ProbePointsHelper(self.config, self.probe_finalize, default_points=points) + self.probe_helper.minimum_points(3) # Register command self.gcode = self.printer.lookup_object('gcode') self.gcode.register_command("SCREWS_TILT_CALCULATE", diff --git a/klippy/extras/z_tilt.py b/klippy/extras/z_tilt.py index d679d398..db8f76dd 100644 --- a/klippy/extras/z_tilt.py +++ b/klippy/extras/z_tilt.py @@ -23,6 +23,7 @@ class ZTilt: if len(z_positions) < 2: raise config.error("z_tilt requires at least two z_positions") self.probe_helper = probe.ProbePointsHelper(config, self.probe_finalize) + self.probe_helper.minimum_points(3) self.z_steppers = [] # Register Z_TILT_ADJUST command self.gcode = self.printer.lookup_object('gcode')