From 857eb01bfa4389e6e475bacfe506424f2a158d15 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 13 Sep 2017 10:50:52 -0400 Subject: [PATCH] homing: Move query_endstop() code from kinematic classes to homing.py Signed-off-by: Kevin O'Connor --- klippy/cartesian.py | 5 ++--- klippy/corexy.py | 5 ++--- klippy/delta.py | 5 ++--- klippy/homing.py | 25 ++++++++++++++++++------- klippy/stepper.py | 6 ------ klippy/toolhead.py | 5 +---- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/klippy/cartesian.py b/klippy/cartesian.py index bc5ead70..ede84af9 100644 --- a/klippy/cartesian.py +++ b/klippy/cartesian.py @@ -62,6 +62,8 @@ class CartKinematics: # Set final homed position coord[axis] = s.position_endstop + s.get_homed_offset() homing_state.set_homed_position(coord) + def query_endstops(self, print_time): + return homing.query_endstops(print_time, self.steppers) def motor_off(self, print_time): self.limits = [(1.0, -1.0)] * 3 for stepper in self.steppers: @@ -74,9 +76,6 @@ class CartKinematics: self.steppers[i].motor_enable(print_time, 1) need_motor_enable |= self.steppers[i].need_motor_enable self.need_motor_enable = need_motor_enable - def query_endstops(self, print_time): - endstops = [(s, s.query_endstop(print_time)) for s in self.steppers] - return [(s.name, es.query_endstop_wait()) for s, es in endstops] def _check_endstops(self, move): end_pos = move.end_pos for i in StepList: diff --git a/klippy/corexy.py b/klippy/corexy.py index b92e2672..bde541b2 100644 --- a/klippy/corexy.py +++ b/klippy/corexy.py @@ -67,6 +67,8 @@ class CoreXYKinematics: # Support endstop phase detection on Z axis coord[axis] = s.position_endstop + s.get_homed_offset() homing_state.set_homed_position(coord) + def query_endstops(self, print_time): + return homing.query_endstops(print_time, self.steppers) def motor_off(self, print_time): self.limits = [(1.0, -1.0)] * 3 for stepper in self.steppers: @@ -82,9 +84,6 @@ class CoreXYKinematics: for i in StepList: need_motor_enable |= self.steppers[i].need_motor_enable self.need_motor_enable = need_motor_enable - def query_endstops(self, print_time): - endstops = [(s, s.query_endstop(print_time)) for s in self.steppers] - return [(s.name, es.query_endstop_wait()) for s, es in endstops] def _check_endstops(self, move): end_pos = move.end_pos for i in StepList: diff --git a/klippy/delta.py b/klippy/delta.py index 0c523d71..8e7d4b20 100644 --- a/klippy/delta.py +++ b/klippy/delta.py @@ -123,6 +123,8 @@ class DeltaKinematics: + self.steppers[i].get_homed_offset() for i in StepList] homing_state.set_homed_position(self._actuator_to_cartesian(spos)) + def query_endstops(self, print_time): + return homing.query_endstops(print_time, self.steppers) def motor_off(self, print_time): self.limit_xy2 = -1. for stepper in self.steppers: @@ -132,9 +134,6 @@ class DeltaKinematics: for i in StepList: self.steppers[i].motor_enable(print_time, 1) self.need_motor_enable = False - def query_endstops(self, print_time): - endstops = [(s, s.query_endstop(print_time)) for s in self.steppers] - return [(s.name, es.query_endstop_wait()) for s, es in endstops] def check_move(self, move): end_pos = move.end_pos xy2 = end_pos[0]**2 + end_pos[1]**2 diff --git a/klippy/homing.py b/klippy/homing.py index c3b9723b..f75a7d06 100644 --- a/klippy/homing.py +++ b/klippy/homing.py @@ -36,18 +36,18 @@ class Homing: print_time = self.toolhead.get_last_move_time() endstops = [] for s in steppers: - es = s.enable_endstop_checking(print_time, s.step_dist / speed) - endstops.append((s, es, s.mcu_stepper.get_mcu_position())) + s.mcu_endstop.home_start(print_time, s.step_dist / speed) + endstops.append((s, s.mcu_stepper.get_mcu_position())) self.toolhead.move(self._fill_coord(movepos), speed) move_end_print_time = self.toolhead.get_last_move_time() self.toolhead.reset_print_time() - for s, es, last_pos in endstops: - es.home_finalize(move_end_print_time) + for s, last_pos in endstops: + s.mcu_endstop.home_finalize(move_end_print_time) # Wait for endstops to trigger - for s, es, last_pos in endstops: + for s, last_pos in endstops: try: - es.home_wait() - except es.error as e: + s.mcu_endstop.home_wait() + except s.mcu_endstop.error as e: raise EndstopError("Failed to home stepper %s: %s" % ( s.name, str(e))) post_home_pos = s.mcu_stepper.get_mcu_position() @@ -57,6 +57,17 @@ class Homing: def set_homed_position(self, pos): self.toolhead.set_position(self._fill_coord(pos)) +def query_endstops(print_time, steppers): + for s in steppers: + s.mcu_endstop.query_endstop(print_time) + out = [] + for s in steppers: + try: + out.append((s.name, s.mcu_endstop.query_endstop_wait())) + except s.mcu_endstop.error as e: + raise EndstopError(str(e)) + return out + class EndstopError(Exception): pass diff --git a/klippy/stepper.py b/klippy/stepper.py index 6bec852a..1d0c0a50 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -95,12 +95,6 @@ class PrinterHomingStepper(PrinterStepper): self.homing_stepper_phases = None if self.mcu_endstop.get_mcu().is_fileoutput(): self.homing_endstop_accuracy = self.homing_stepper_phases - def enable_endstop_checking(self, print_time, step_time): - self.mcu_endstop.home_start(print_time, step_time) - return self.mcu_endstop - def query_endstop(self, print_time): - self.mcu_endstop.query_endstop(print_time) - return self.mcu_endstop def get_homing_speed(self): # Round the configured homing speed so that it is an even # number of ticks per step. diff --git a/klippy/toolhead.py b/klippy/toolhead.py index 9f7cd133..7611e0bf 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -347,10 +347,7 @@ class ToolHead: eventtime = self.reactor.pause(eventtime + 0.100) def query_endstops(self): last_move_time = self.get_last_move_time() - try: - return self.kin.query_endstops(last_move_time) - except self.mcu.error as e: - raise homing.EndstopError(str(e)) + return self.kin.query_endstops(last_move_time) def set_extruder(self, extruder): last_move_time = self.get_last_move_time() self.extruder.set_active(last_move_time, False)