From 38643f52c97dc85bcc2bf020927852f9cfe9fff6 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 7 Nov 2017 12:29:51 -0500 Subject: [PATCH] stepper: Add get_endstops() / set_position wrappers Add wrappers around mcu_endstop and mcu_stepper so that the kinematic classes do not need to directly access these low-level classes. Signed-off-by: Kevin O'Connor --- klippy/cartesian.py | 2 +- klippy/corexy.py | 2 +- klippy/delta.py | 2 +- klippy/homing.py | 42 ++++++++++++++++++++++++------------------ klippy/mcu.py | 2 ++ klippy/stepper.py | 4 ++++ 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/klippy/cartesian.py b/klippy/cartesian.py index 685e0c7e..4907b6d1 100644 --- a/klippy/cartesian.py +++ b/klippy/cartesian.py @@ -28,7 +28,7 @@ class CartKinematics: min(max_halt_velocity, self.max_z_velocity), max_accel) def set_position(self, newpos): for i in StepList: - self.steppers[i].mcu_stepper.set_position(newpos[i]) + self.steppers[i].set_position(newpos[i]) def home(self, homing_state): # Each axis is homed independently and in order for axis in homing_state.get_axes(): diff --git a/klippy/corexy.py b/klippy/corexy.py index d459682a..8b92d118 100644 --- a/klippy/corexy.py +++ b/klippy/corexy.py @@ -32,7 +32,7 @@ class CoreXYKinematics: def set_position(self, newpos): pos = (newpos[0] + newpos[1], newpos[0] - newpos[1], newpos[2]) for i in StepList: - self.steppers[i].mcu_stepper.set_position(pos[i]) + self.steppers[i].set_position(pos[i]) def home(self, homing_state): # Each axis is homed independently and in order for axis in homing_state.get_axes(): diff --git a/klippy/delta.py b/klippy/delta.py index 0d9b92ec..5d1452b1 100644 --- a/klippy/delta.py +++ b/klippy/delta.py @@ -97,7 +97,7 @@ class DeltaKinematics: def set_position(self, newpos): pos = self._cartesian_to_actuator(newpos) for i in StepList: - self.steppers[i].mcu_stepper.set_position(pos[i]) + self.steppers[i].set_position(pos[i]) self.limit_xy2 = -1. def home(self, homing_state): # All axes are homed simultaneously diff --git a/klippy/homing.py b/klippy/homing.py index c4092fff..a8ad2e70 100644 --- a/klippy/homing.py +++ b/klippy/homing.py @@ -38,41 +38,47 @@ class Homing: print_time = self.toolhead.get_last_move_time() endstops = [] for s in steppers: - s.mcu_endstop.home_start(print_time, ENDSTOP_SAMPLE_TIME, - ENDSTOP_SAMPLE_COUNT, s.step_dist / speed) - endstops.append((s, s.mcu_stepper.get_mcu_position())) + for mcu_endstop, mcu_stepper, name in s.get_endstops(): + mcu_endstop.home_start( + print_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT, + mcu_stepper.get_step_dist() / speed) + endstops.append((mcu_endstop, mcu_stepper, name, + 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(print_time) - for s, last_pos in endstops: - s.mcu_endstop.home_finalize(move_end_print_time) + for mcu_endstop, mcu_stepper, name, last_pos in endstops: + mcu_endstop.home_finalize(move_end_print_time) # Wait for endstops to trigger - for s, last_pos in endstops: + for mcu_endstop, mcu_stepper, name, last_pos in endstops: try: - s.mcu_endstop.home_wait() - except s.mcu_endstop.error as e: + mcu_endstop.home_wait() + except 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() + name, str(e))) + post_home_pos = mcu_stepper.get_mcu_position() if second_home and self.verify_retract and last_pos == post_home_pos: raise EndstopError("Endstop %s still triggered after retract" % ( - s.name,)) + name,)) def set_homed_position(self, pos): self.toolhead.set_position(self._fill_coord(pos)) def query_endstops(print_time, query_flags, steppers): if query_flags == "get_mcu_position": # Only the commanded position is requested - return [(s.name.upper(), s.mcu_stepper.get_mcu_position()) - for s in steppers] + return [(name.upper(), mcu_stepper.get_mcu_position()) + for s in steppers + for mcu_endstop, mcu_stepper, name in s.get_endstops()] for s in steppers: - s.mcu_endstop.query_endstop(print_time) + for mcu_endstop, mcu_stepper, name in s.get_endstops(): + 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)) + for mcu_endstop, mcu_stepper, name in s.get_endstops(): + try: + out.append((name, mcu_endstop.query_endstop_wait())) + except mcu_endstop.error as e: + raise EndstopError(str(e)) return out class EndstopError(Exception): diff --git a/klippy/mcu.py b/klippy/mcu.py index 98d516fb..e2bd222d 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -61,6 +61,8 @@ class MCU_stepper: self._mcu.register_stepqueue(self._stepqueue) def get_oid(self): return self._oid + def get_step_dist(self): + return self._step_dist def set_position(self, pos): if pos >= 0.: steppos = int(pos * self._inv_step_dist + 0.5) diff --git a/klippy/stepper.py b/klippy/stepper.py index 5370c804..692273c0 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -41,6 +41,8 @@ class PrinterStepper: 2. * self.step_dist, max_halt_velocity, max_accel) min_stop_interval = second_last_step_time - last_step_time self.mcu_stepper.setup_min_stop_interval(min_stop_interval) + def set_position(self, pos): + self.mcu_stepper.set_position(pos) def motor_enable(self, print_time, enable=0): if enable and self.need_motor_enable: self.mcu_stepper.reset_step_clock(print_time) @@ -115,6 +117,8 @@ 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 get_endstops(self): + return [(self.mcu_endstop, self.mcu_stepper, self.name)] def get_homing_speed(self): # Round the configured homing speed so that it is an even # number of ticks per step.