From 11816295e798f841a5b06447daba6bafc258af55 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 18 May 2018 19:34:17 -0400 Subject: [PATCH] stepper: Raise an error if position_endstop is not in min/max range Raise an error during config parsing if the position_endstop is not between the position_min and position_max. This avoids a confusing error message during homing. Signed-off-by: Kevin O'Connor --- klippy/delta.py | 11 ++++++----- klippy/stepper.py | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/klippy/delta.py b/klippy/delta.py index dd4edb46..7a518593 100644 --- a/klippy/delta.py +++ b/klippy/delta.py @@ -15,13 +15,14 @@ class DeltaKinematics: def __init__(self, toolhead, printer, config): stepper_configs = [config.getsection('stepper_' + n) for n in ['a', 'b', 'c']] - stepper_a = stepper.PrinterHomingStepper(printer, stepper_configs[0]) + stepper_a = stepper.PrinterHomingStepper( + printer, stepper_configs[0], need_position_minmax = False) stepper_b = stepper.PrinterHomingStepper( - printer, stepper_configs[1], - default_position=stepper_a.position_endstop) + printer, stepper_configs[1], need_position_minmax = False, + default_position_endstop=stepper_a.position_endstop) stepper_c = stepper.PrinterHomingStepper( - printer, stepper_configs[2], - default_position=stepper_a.position_endstop) + printer, stepper_configs[2], need_position_minmax = False, + default_position_endstop=stepper_a.position_endstop) self.steppers = [stepper_a, stepper_b, stepper_c] self.need_motor_enable = self.need_home = True self.radius = radius = config.getfloat('delta_radius', above=0.) diff --git a/klippy/stepper.py b/klippy/stepper.py index 2bad5e8a..8767fd12 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -71,21 +71,31 @@ class PrinterStepper: # Support for stepper controlled linear axis with an endstop class PrinterHomingStepper(PrinterStepper): - def __init__(self, printer, config, default_position=None): + def __init__(self, printer, config, need_position_minmax=True, + default_position_endstop=None): PrinterStepper.__init__(self, printer, config) # Endstop and its position ppins = printer.lookup_object('pins') self.mcu_endstop = ppins.setup_pin('endstop', config.get('endstop_pin')) self.mcu_endstop.add_stepper(self.mcu_stepper) - if default_position is None: + if default_position_endstop is None: self.position_endstop = config.getfloat('position_endstop') else: self.position_endstop = config.getfloat( - 'position_endstop', default_position) + 'position_endstop', default_position_endstop) # Axis range - self.position_min = config.getfloat('position_min', 0.) - self.position_max = config.getfloat( - 'position_max', 0., above=self.position_min) + if need_position_minmax: + self.position_min = config.getfloat('position_min', 0.) + self.position_max = config.getfloat( + 'position_max', above=self.position_min) + else: + self.position_min = 0. + self.position_max = self.position_endstop + if (self.position_endstop < self.position_min + or self.position_endstop > self.position_max): + raise config.error( + "position_endstop in section '%s' must be between" + " position_min and position_max" % config.get_name()) # Homing mechanics self.homing_speed = config.getfloat('homing_speed', 5.0, above=0.) self.homing_retract_dist = config.getfloat(