Skip to content

Commit

Permalink
homing: Log a warning if probe alters stepper kinematic positions
Browse files Browse the repository at this point in the history
After a probe attempt the toolhead position needs to be recalculated
to the position that the toolhead ultimately halted at.  Check that
the position setting wouldn't actually change the internal view of the
stepper motor and log a warning if any skew is detected.

Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Oct 27, 2024
1 parent b381f50 commit 31fe50f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 12 additions & 2 deletions klippy/extras/homing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Helper code for implementing homing operations
#
# Copyright (C) 2016-2021 Kevin O'Connor <[email protected]>
# Copyright (C) 2016-2024 Kevin O'Connor <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, math
Expand Down Expand Up @@ -29,10 +29,17 @@ def __init__(self, stepper, endstop_name):
self.endstop_name = endstop_name
self.stepper_name = stepper.get_name()
self.start_pos = stepper.get_mcu_position()
self.start_cmd_pos = stepper.mcu_to_commanded_position(self.start_pos)
self.halt_pos = self.trig_pos = None
def note_home_end(self, trigger_time):
self.halt_pos = self.stepper.get_mcu_position()
self.trig_pos = self.stepper.get_past_mcu_position(trigger_time)
def verify_no_probe_skew(self, haltpos):
new_start_pos = self.stepper.get_mcu_position(self.start_cmd_pos)
if new_start_pos != self.start_pos:
logging.warning(
"Stepper '%s' position skew after probe: pos %d now %d",
self.stepper.get_name(), self.start_pos, new_start_pos)

# Implementation of homing/probing moves
class HomingMove:
Expand Down Expand Up @@ -121,6 +128,9 @@ def homing_move(self, movepos, speed, probe_pos=False,
haltpos = trigpos = self.calc_toolhead_pos(kin_spos, trig_steps)
if trig_steps != halt_steps:
haltpos = self.calc_toolhead_pos(kin_spos, halt_steps)
self.toolhead.set_position(haltpos)
for sp in self.stepper_positions:
sp.verify_no_probe_skew(haltpos)
else:
haltpos = trigpos = movepos
over_steps = {sp.stepper_name: sp.halt_pos - sp.trig_pos
Expand All @@ -130,7 +140,7 @@ def homing_move(self, movepos, speed, probe_pos=False,
halt_kin_spos = {s.get_name(): s.get_commanded_position()
for s in kin.get_steppers()}
haltpos = self.calc_toolhead_pos(halt_kin_spos, over_steps)
self.toolhead.set_position(haltpos)
self.toolhead.set_position(haltpos)
# Signal homing/probing move complete
try:
self.printer.send_event("homing:homing_move_end", self)
Expand Down
6 changes: 4 additions & 2 deletions klippy/stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ def set_position(self, coord):
def get_commanded_position(self):
ffi_main, ffi_lib = chelper.get_ffi()
return ffi_lib.itersolve_get_commanded_pos(self._stepper_kinematics)
def get_mcu_position(self):
mcu_pos_dist = self.get_commanded_position() + self._mcu_position_offset
def get_mcu_position(self, cmd_pos=None):
if cmd_pos is None:
cmd_pos = self.get_commanded_position()
mcu_pos_dist = cmd_pos + self._mcu_position_offset
mcu_pos = mcu_pos_dist / self._step_dist
if mcu_pos >= 0.:
return int(mcu_pos + 0.5)
Expand Down

0 comments on commit 31fe50f

Please sign in to comment.