mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-24 23:24:01 -06:00
endstop_phase: Add support for detecting phase via TMC stepper drivers
The Trinamic stepper motor drivers are capable of reporting the stepper phase - add support for using that capability to the enddstop_phases module. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
a2df01b88e
commit
def524bdf4
4 changed files with 38 additions and 8 deletions
|
@ -6,17 +6,30 @@
|
|||
import math, logging
|
||||
import homing
|
||||
|
||||
TRINAMIC_DRIVERS = ["tmc2130", "tmc2208"]
|
||||
|
||||
class EndstopPhase:
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
self.name = config.get_name().split()[1]
|
||||
stepper_config = config.getsection(self.name)
|
||||
self.step_dist = step_dist = stepper_config.getfloat('step_distance')
|
||||
self.phases = config.getint('phases', minval=1)
|
||||
# Determine number of stepper phases
|
||||
for driver in TRINAMIC_DRIVERS:
|
||||
driver_name = "%s %s" % (driver, self.name)
|
||||
if config.has_section(driver_name):
|
||||
module = self.printer.try_load_module(config, driver_name)
|
||||
self.get_phase = module.get_phase
|
||||
self.phases = module.get_microsteps() * 4
|
||||
break
|
||||
else:
|
||||
self.get_phase = None
|
||||
self.phases = config.getint('phases', minval=1)
|
||||
# Determine endstop phase position
|
||||
self.endstop_phase = config.getint('endstop_phase', None,
|
||||
minval=0, maxval=self.phases-1)
|
||||
self.endstop_align_zero = config.getboolean('endstop_align_zero', False)
|
||||
# Determine endstop accuracy
|
||||
stepper_config = config.getsection(self.name)
|
||||
self.step_dist = step_dist = stepper_config.getfloat('step_distance')
|
||||
endstop_accuracy = config.getfloat('endstop_accuracy', None, above=0.)
|
||||
if endstop_accuracy is None:
|
||||
self.endstop_accuracy = self.phases//2 - 1
|
||||
|
@ -44,8 +57,15 @@ class EndstopPhase:
|
|||
full_step = microsteps * self.step_dist
|
||||
return int(pos / full_step + .5) * full_step + phase_offset
|
||||
def get_homed_offset(self, stepper):
|
||||
pos = stepper.get_mcu_position()
|
||||
phase = pos % self.phases
|
||||
if self.get_phase is not None:
|
||||
try:
|
||||
phase = self.get_phase()
|
||||
except Exception as e:
|
||||
msg = "Unable to get stepper %s phase: %s" % (self.name, str(e))
|
||||
logging.exception(msg)
|
||||
raise homing.EndstopError(msg)
|
||||
else:
|
||||
phase = stepper.get_mcu_position() % self.phases
|
||||
if self.endstop_phase is None:
|
||||
logging.info("Setting %s endstop phase to %d", self.name, phase)
|
||||
self.endstop_phase = phase
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue