diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2021-06-03 23:24:44 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2021-08-28 16:08:57 -0400 |
commit | 950477849d0871766ce9d4240ddd5976a9086e33 (patch) | |
tree | b7ab57f4c86321502a84a6d8beac9c96f140aba1 /klippy | |
parent | 2e131497ca342514d543fc91cb559df2d2802462 (diff) | |
download | kutter-950477849d0871766ce9d4240ddd5976a9086e33.tar.gz kutter-950477849d0871766ce9d4240ddd5976a9086e33.tar.xz kutter-950477849d0871766ce9d4240ddd5976a9086e33.zip |
mcu: Support multi-mcu homing
Support endstops and probes attached to a different micro-controller
than their associated steppers.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r-- | klippy/mcu.py | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/klippy/mcu.py b/klippy/mcu.py index eb1f319f..d568d194 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -125,6 +125,9 @@ class MCU_trsync: s.note_homing_end() return params['trigger_reason'] +TRSYNC_TIMEOUT = 0.025 +TRSYNC_SINGLE_MCU_TIMEOUT = 0.250 + class MCU_endstop: RETRY_QUERY = 1.000 def __init__(self, mcu, pin_params): @@ -139,15 +142,27 @@ class MCU_endstop: self._rest_ticks = 0 ffi_main, ffi_lib = chelper.get_ffi() self._trdispatch = ffi_main.gc(ffi_lib.trdispatch_alloc(), ffi_lib.free) - self._trsync = MCU_trsync(mcu, self._trdispatch) + self._trsyncs = [MCU_trsync(mcu, self._trdispatch)] def get_mcu(self): return self._mcu def add_stepper(self, stepper): - if stepper.get_mcu() is not self._mcu: - raise pins.error("Endstop and stepper must be on the same mcu") - self._trsync.add_stepper(stepper) + trsyncs = {trsync.get_mcu(): trsync for trsync in self._trsyncs} + trsync = trsyncs.get(stepper.get_mcu()) + if trsync is None: + trsync = MCU_trsync(stepper.get_mcu(), self._trdispatch) + self._trsyncs.append(trsync) + trsync.add_stepper(stepper) + # Check for unsupported multi-mcu shared stepper rails + sname = stepper.get_name() + if sname.startswith('stepper_'): + for ot in self._trsyncs: + for s in ot.get_steppers(): + if ot is not trsync and s.get_name().startswith(sname[:9]): + cerror = self._mcu.get_printer().config_error + raise cerror("Multi-mcu homing not supported on" + " multi-mcu shared axis") def get_steppers(self): - return self._trsync.get_steppers() + return [s for trsync in self._trsyncs for s in trsync.get_steppers()] def _build_config(self): # Setup config self._mcu.add_config_cmd("config_endstop oid=%d pin=%s pull_up=%d" @@ -157,7 +172,7 @@ class MCU_endstop: " rest_ticks=0 pin_value=0 trsync_oid=0 trigger_reason=0" % (self._oid,), on_restart=True) # Lookup commands - cmd_queue = self._trsync.get_command_queue() + cmd_queue = self._trsyncs[0].get_command_queue() self._home_cmd = self._mcu.lookup_command( "endstop_home oid=%c clock=%u sample_ticks=%u sample_count=%c" " rest_ticks=%u pin_value=%c trsync_oid=%c trigger_reason=%c", @@ -173,8 +188,12 @@ class MCU_endstop: self._rest_ticks = rest_ticks reactor = self._mcu.get_printer().get_reactor() self._trigger_completion = reactor.completion() - etrsync = self._trsync - etrsync.start(print_time, self._trigger_completion, .250) + expire_timeout = TRSYNC_TIMEOUT + if len(self._trsyncs) == 1: + expire_timeout = TRSYNC_SINGLE_MCU_TIMEOUT + for trsync in self._trsyncs: + trsync.start(print_time, self._trigger_completion, expire_timeout) + etrsync = self._trsyncs[0] ffi_main, ffi_lib = chelper.get_ffi() ffi_lib.trdispatch_start(self._trdispatch, etrsync.REASON_HOST_REQUEST) self._home_cmd.send( @@ -183,7 +202,7 @@ class MCU_endstop: etrsync.get_oid(), etrsync.REASON_ENDSTOP_HIT], reqclock=clock) return self._trigger_completion def home_wait(self, home_end_time): - etrsync = self._trsync + etrsync = self._trsyncs[0] etrsync.set_home_end_time(home_end_time) if self._mcu.is_fileoutput(): self._trigger_completion.complete(True) @@ -191,10 +210,10 @@ class MCU_endstop: self._home_cmd.send([self._oid, 0, 0, 0, 0, 0, 0, 0]) ffi_main, ffi_lib = chelper.get_ffi() ffi_lib.trdispatch_stop(self._trdispatch) - res = etrsync.stop() - if res == etrsync.REASON_COMMS_TIMEOUT: + res = [trsync.stop() for trsync in self._trsyncs] + if any([r == etrsync.REASON_COMMS_TIMEOUT for r in res]): return -1. - if res != etrsync.REASON_ENDSTOP_HIT: + if res[0] != etrsync.REASON_ENDSTOP_HIT: return 0. if self._mcu.is_fileoutput(): return home_end_time |