mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-07 15:07:33 -06:00
endstop_phase: Move endstop phase homing code to new "extras" module
Move the endstop phase tracking code from stepper.py to a new extras/endstop_phase.py module. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
216905ceca
commit
a2df01b88e
5 changed files with 114 additions and 89 deletions
|
@ -162,63 +162,6 @@ class PrinterRail:
|
|||
raise config.error(
|
||||
"Unable to infer homing_positive_dir in section '%s'" % (
|
||||
config.get_name(),))
|
||||
# Endstop stepper phase position tracking
|
||||
self.homing_stepper_phases = config.getint(
|
||||
'homing_stepper_phases', None, minval=0)
|
||||
endstop_accuracy = config.getfloat(
|
||||
'homing_endstop_accuracy', None, above=0.)
|
||||
self.homing_endstop_accuracy = self.homing_endstop_phase = None
|
||||
if self.homing_stepper_phases:
|
||||
self.homing_step_dist = step_dist = stepper.get_step_dist()
|
||||
self.homing_endstop_phase = config.getint(
|
||||
'homing_endstop_phase', None, minval=0
|
||||
, maxval=self.homing_stepper_phases-1)
|
||||
if (self.homing_endstop_phase is not None
|
||||
and config.getboolean('homing_endstop_align_zero', False)):
|
||||
# Adjust the endstop position so 0.0 is always at a full step
|
||||
micro_steps = self.homing_stepper_phases // 4
|
||||
phase_offset = (
|
||||
((self.homing_endstop_phase + micro_steps // 2)
|
||||
% micro_steps) - micro_steps // 2) * step_dist
|
||||
full_step = micro_steps * step_dist
|
||||
es_pos = (int(self.position_endstop / full_step + .5)
|
||||
* full_step + phase_offset)
|
||||
if es_pos != self.position_endstop:
|
||||
logging.info("Changing %s endstop position to %.3f"
|
||||
" (from %.3f)", self.name,
|
||||
es_pos, self.position_endstop)
|
||||
self.position_endstop = es_pos
|
||||
if endstop_accuracy is None:
|
||||
self.homing_endstop_accuracy = self.homing_stepper_phases//2 - 1
|
||||
elif self.homing_endstop_phase is not None:
|
||||
self.homing_endstop_accuracy = int(math.ceil(
|
||||
endstop_accuracy * .5 / step_dist))
|
||||
else:
|
||||
self.homing_endstop_accuracy = int(math.ceil(
|
||||
endstop_accuracy / step_dist))
|
||||
if self.homing_endstop_accuracy >= self.homing_stepper_phases // 2:
|
||||
logging.info("Endstop for %s is not accurate enough for stepper"
|
||||
" phase adjustment", self.name)
|
||||
self.homing_stepper_phases = None
|
||||
if mcu_endstop.get_mcu().is_fileoutput():
|
||||
self.homing_endstop_accuracy = self.homing_stepper_phases
|
||||
def get_homed_offset(self):
|
||||
if not self.homing_stepper_phases:
|
||||
return 0.
|
||||
pos = self.steppers[0].get_mcu_position()
|
||||
pos %= self.homing_stepper_phases
|
||||
if self.homing_endstop_phase is None:
|
||||
logging.info("Setting %s endstop phase to %d", self.name, pos)
|
||||
self.homing_endstop_phase = pos
|
||||
return 0.
|
||||
delta = (pos - self.homing_endstop_phase) % self.homing_stepper_phases
|
||||
if delta >= self.homing_stepper_phases - self.homing_endstop_accuracy:
|
||||
delta -= self.homing_stepper_phases
|
||||
elif delta > self.homing_endstop_accuracy:
|
||||
raise homing.EndstopError(
|
||||
"Endstop %s incorrect phase (got %d vs %d)" % (
|
||||
self.name, pos, self.homing_endstop_phase))
|
||||
return delta * self.homing_step_dist
|
||||
def get_range(self):
|
||||
return self.position_min, self.position_max
|
||||
def get_homing_info(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue