diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2021-08-06 00:38:49 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2021-08-08 22:28:10 -0400 |
commit | f759df3cd72d0b1cb05615b2e4b04bbf5e8d62f8 (patch) | |
tree | 7c5b3753c03c96b5bf303b2f611c2225f83d8eae /klippy/extras/endstop_phase.py | |
parent | 06b8169f56f264a9175b7790ba39cadc187ec2de (diff) | |
download | kutter-f759df3cd72d0b1cb05615b2e4b04bbf5e8d62f8.tar.gz kutter-f759df3cd72d0b1cb05615b2e4b04bbf5e8d62f8.tar.xz kutter-f759df3cd72d0b1cb05615b2e4b04bbf5e8d62f8.zip |
endstop_phase: Convert to using tmc mcu_phase_offset
Now that the TMC drivers track the phase offset, use that to implement
endstop phase.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/endstop_phase.py')
-rw-r--r-- | klippy/extras/endstop_phase.py | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/klippy/extras/endstop_phase.py b/klippy/extras/endstop_phase.py index 5c762b2e..fa57a0fc 100644 --- a/klippy/extras/endstop_phase.py +++ b/klippy/extras/endstop_phase.py @@ -25,7 +25,7 @@ class PhaseCalc: if module is not None: self.tmc_module = module if self.phases is None: - self.phases = module.get_microsteps() * 4 + phase_offset, self.phases = module.get_phase_offset() break if self.phases is not None: self.phase_history = [0] * self.phases @@ -34,18 +34,15 @@ class PhaseCalc: return (int(float(driver_phase) / driver_phases * phases + .5) % phases) def calc_phase(self, stepper): mcu_pos = stepper.get_mcu_position() - if self.tmc_module is None: - phase = mcu_pos % self.phases - else: - try: - driver_phase, driver_phases = self.tmc_module.get_phase() - except Exception as e: - msg = "Unable to get stepper %s phase: %s" % (self.name, str(e)) - logging.exception(msg) - raise self.printer.command_error(msg) - if stepper.is_dir_inverted(): - driver_phase = (driver_phases - 1) - driver_phase - phase = self.convert_phase(driver_phase, driver_phases) + mcu_phase_offset = 0 + if self.tmc_module is not None: + mcu_phase_offset, phases = self.tmc_module.get_phase_offset() + if mcu_phase_offset is None: + if self.printer.get_start_args().get('debugoutput') is None: + raise self.printer.command_error("Stepper %s phase unknown" + % (self.name,)) + mcu_phase_offset = 0 + phase = (mcu_pos + mcu_phase_offset) % self.phases self.phase_history[phase] += 1 self.last_phase = phase self.last_mcu_position = mcu_pos |