diff --git a/klippy/cartesian.py b/klippy/cartesian.py index 2f4651ad..a295ee92 100644 --- a/klippy/cartesian.py +++ b/klippy/cartesian.py @@ -51,14 +51,14 @@ class CartKinematics: homepos[axis] = s.position_endstop coord = [None, None, None, None] coord[axis] = pos - homing_state.home(list(coord), homepos, [s], homing_speed) + homing_state.home(coord, homepos, s.get_endstops(), homing_speed) # Retract coord[axis] = rpos - homing_state.retract(list(coord), homing_speed) + homing_state.retract(coord, homing_speed) # Home again coord[axis] = r2pos - homing_state.home( - list(coord), homepos, [s], homing_speed/2.0, second_home=True) + homing_state.home(coord, homepos, s.get_endstops(), + homing_speed/2.0, second_home=True) # Set final homed position coord[axis] = s.position_endstop + s.get_homed_offset() homing_state.set_homed_position(coord) diff --git a/klippy/corexy.py b/klippy/corexy.py index dd62cf1c..cd51410b 100644 --- a/klippy/corexy.py +++ b/klippy/corexy.py @@ -59,14 +59,14 @@ class CoreXYKinematics: homepos[axis] = s.position_endstop coord = [None, None, None, None] coord[axis] = pos - homing_state.home(list(coord), homepos, [s], homing_speed) + homing_state.home(coord, homepos, s.get_endstops(), homing_speed) # Retract coord[axis] = rpos - homing_state.retract(list(coord), homing_speed) + homing_state.retract(coord, homing_speed) # Home again coord[axis] = r2pos - homing_state.home( - list(coord), homepos, [s], homing_speed/2.0, second_home=True) + homing_state.home(coord, homepos, s.get_endstops(), + homing_speed/2.0, second_home=True) if axis == 2: # Support endstop phase detection on Z axis coord[axis] = s.position_endstop + s.get_homed_offset() diff --git a/klippy/delta.py b/klippy/delta.py index 5d1452b1..b0ad094e 100644 --- a/klippy/delta.py +++ b/klippy/delta.py @@ -102,6 +102,7 @@ class DeltaKinematics: def home(self, homing_state): # All axes are homed simultaneously homing_state.set_axes([0, 1, 2]) + endstops = [es for s in self.steppers for es in s.get_endstops()] s = self.steppers[0] # Assume homing speed same for all steppers self.need_home = False # Initial homing @@ -109,14 +110,14 @@ class DeltaKinematics: homepos = [0., 0., self.max_z, None] coord = list(homepos) coord[2] = -1.5 * math.sqrt(self.arm_length2-self.max_xy2) - homing_state.home(list(coord), homepos, self.steppers, homing_speed) + homing_state.home(coord, homepos, endstops, homing_speed) # Retract coord[2] = homepos[2] - s.homing_retract_dist - homing_state.retract(list(coord), homing_speed) + homing_state.retract(coord, homing_speed) # Home again coord[2] -= s.homing_retract_dist - homing_state.home(list(coord), homepos, self.steppers - , homing_speed/2.0, second_home=True) + homing_state.home(coord, homepos, endstops, + homing_speed/2.0, second_home=True) # Set final homed position spos = self._cartesian_to_actuator(homepos) spos = [spos[i] + self.steppers[i].position_endstop - self.max_z diff --git a/klippy/homing.py b/klippy/homing.py index abaafa6a..9fde0000 100644 --- a/klippy/homing.py +++ b/klippy/homing.py @@ -29,58 +29,57 @@ class Homing: return thcoord def retract(self, newpos, speed): self.toolhead.move(self._fill_coord(newpos), speed) - def home(self, forcepos, movepos, steppers, speed, second_home=False): + def home(self, forcepos, movepos, endstops, speed, second_home=False): # Alter kinematics class to think printer is at forcepos self.toolhead.set_position(self._fill_coord(forcepos)) # Start homing and issue move if not second_home: est_move_d = sum([abs(forcepos[i]-movepos[i]) for i in range(3) if movepos[i] is not None]) - est_steps = sum( - [est_move_d / mcu_stepper.get_step_dist() - for s in steppers - for mcu_endstop, mcu_stepper, name in s.get_endstops()]) + est_steps = sum([est_move_d / s.get_step_dist() + for es, n in endstops for s in es.get_steppers()]) self.toolhead.dwell(est_steps * HOMING_STEP_DELAY, check_stall=False) print_time = self.toolhead.get_last_move_time() - endstops = [] - for s in steppers: - 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())) + start_mcu_pos = [(s, name, s.get_mcu_position()) + for es, name in endstops for s in es.get_steppers()] + for mcu_endstop, name in endstops: + min_step_dist = min([s.get_step_dist() + for s in mcu_endstop.get_steppers()]) + mcu_endstop.home_start( + print_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT, + min_step_dist / speed) 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 mcu_endstop, mcu_stepper, name, last_pos in endstops: + for mcu_endstop, name in endstops: mcu_endstop.home_finalize(move_end_print_time) # Wait for endstops to trigger - for mcu_endstop, mcu_stepper, name, last_pos in endstops: + for mcu_endstop, name in endstops: try: mcu_endstop.home_wait() except mcu_endstop.error as e: raise EndstopError("Failed to home stepper %s: %s" % ( 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" % ( - name,)) + # Verify retract led to some movement on second home + if second_home and self.verify_retract: + for s, name, pos in start_mcu_pos: + if s.get_mcu_position() == pos: + raise EndstopError( + "Endstop %s still triggered after retract" % (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 [(name.upper(), mcu_stepper.get_mcu_position()) - for s in steppers - for mcu_endstop, mcu_stepper, name in s.get_endstops()] + return [(s.name.upper(), s.mcu_stepper.get_mcu_position()) + for s in steppers] for s in steppers: - for mcu_endstop, mcu_stepper, name in s.get_endstops(): + for mcu_endstop, name in s.get_endstops(): mcu_endstop.query_endstop(print_time) out = [] for s in steppers: - for mcu_endstop, mcu_stepper, name in s.get_endstops(): + for mcu_endstop, name in s.get_endstops(): try: out.append((name, mcu_endstop.query_endstop_wait())) except mcu_endstop.error as e: diff --git a/klippy/mcu.py b/klippy/mcu.py index 93474b1a..aa4f6297 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -150,6 +150,8 @@ class MCU_endstop: if stepper.get_mcu() is not self._mcu: raise pins.error("Endstop and stepper must be on the same mcu") self._steppers.append(stepper) + def get_steppers(self): + return list(self._steppers) def build_config(self): self._oid = self._mcu.create_oid() self._mcu.add_config_cmd( diff --git a/klippy/stepper.py b/klippy/stepper.py index 7d365f5f..d0a6bc80 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -118,7 +118,7 @@ class PrinterHomingStepper(PrinterStepper): 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)] + return [(self.mcu_endstop, self.name)] def get_homing_speed(self): # Round the configured homing speed so that it is an even # number of ticks per step. @@ -162,8 +162,7 @@ class PrinterMultiStepper(PrinterHomingStepper): if extraendstop is not None: mcu_endstop = pins.setup_pin(printer, 'endstop', extraendstop) mcu_endstop.add_stepper(extra.mcu_stepper) - self.endstops.append( - (mcu_endstop, extra.mcu_stepper, extra.name)) + self.endstops.append((mcu_endstop, extra.name)) else: self.mcu_endstop.add_stepper(extra.mcu_stepper) self.step_const = self.step_multi_const