Skip to content

Commit

Permalink
removed debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
moggieuk committed Dec 13, 2024
1 parent 9610f04 commit 2e843a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
34 changes: 13 additions & 21 deletions extras/mmu/mmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ def motors_off(self, motor="all"):
se = stepper_enable.lookup_enable(stepper.get_name())
se.motor_disable(self.mmu_toolhead.get_last_move_time())
if motor in ["all", "selector"]:
self.selector.restore_gate(self.TOOL_GATE_UNKNOWN) # PAUL added to reset tmc current
self.selector.restore_gate(self.TOOL_GATE_UNKNOWN)
self._set_gate_selected(self.TOOL_GATE_UNKNOWN)
self._set_tool_selected(self.TOOL_GATE_UNKNOWN)
self.selector.disable_motors()
Expand Down Expand Up @@ -2084,8 +2084,6 @@ def cmd_MMU_SYNC_GEAR_MOTOR(self, gcmd):
grip = gcmd.get_int('GRIP', 1, minval=0, maxval=1)
servo = gcmd.get_int('SERVO', 1, minval=0, maxval=1) # Deprecated (use GRIP=0 instead)
sync = gcmd.get_int('SYNC', 1, minval=0, maxval=1)
# PAUL force_in_print = bool(gcmd.get_int('FORCE_IN_PRINT', 0, minval=0, maxval=1)) # Mimick in-print current
# PAUL self.sync_gear_to_extruder(sync, grip=(grip and servo), current=self.is_in_print(force_in_print))
self.sync_gear_to_extruder(sync, grip=(grip and servo), current=True)


Expand Down Expand Up @@ -4021,7 +4019,6 @@ def _load_gate(self, allow_retry=True, adjust_grip_on_error=True):
endstop_name = self._get_gate_endstop_name()
msg = ("Initial homing to %s sensor" % endstop_name) if i == 0 else ("Retry homing to gate sensor (retry #%d)" % i)
actual,homed,measured,_ = self.trace_filament_move(msg, self.gate_homing_max, motor="gear", homing_move=1, endstop_name=endstop_name)
#homed=True # PAUL temp
if homed:
self.log_debug("Endstop %s reached after %.1fmm (measured %.1fmm)" % (endstop_name, actual, measured))
self._set_gate_status(self.gate_selected, max(self.gate_status[self.gate_selected], self.GATE_AVAILABLE)) # Don't reset if filament is buffered
Expand Down Expand Up @@ -4097,7 +4094,6 @@ def _unload_gate(self, homing_max=None):
else: # Using mmu_gate or mmu_gear_N sensor
endstop_name = self._get_gate_endstop_name()
actual,homed,_,_ = self.trace_filament_move("Reverse homing to %s sensor" % endstop_name, -homing_max, motor="gear", homing_move=-1, endstop_name=endstop_name)
#homed=True # PAUL temp
if homed:
self._set_filament_pos_state(self.FILAMENT_POS_HOMED_GATE)
self.trace_filament_move("Final parking", -self.gate_parking_distance)
Expand Down Expand Up @@ -5334,7 +5330,7 @@ def buzz_gear_motor(self):
# grip: True=grip/release, False=don't mess
# current: True=optionally reduce, False=restore to current default
def sync_gear_to_extruder(self, sync, gate=None, grip=False, current=False):
self.log_error("sync_gear_to_extruder(sync=%s, gate=%s, grip=%s, current=%s)" % (sync, gate, grip, current))
#self.log_error("PAUL TEMP: sync_gear_to_extruder(sync=%s, gate=%s, grip=%s, current=%s)" % (sync, gate, grip, current))

# Safety in case somehow called with bypass/unknown selected. Usually this is called after
# self.gate_selected is set, but can be before on type-B designs hence optional gate parameter
Expand Down Expand Up @@ -5370,19 +5366,16 @@ def sync_gear_to_extruder(self, sync, gate=None, grip=False, current=False):
# into Happy Hare during a print. It also ensures that grip (e.g. servo) and current are correctly restored
@contextlib.contextmanager
def wrap_sync_gear_to_extruder(self):
self.log_error("wrap_sync_gear_to_extruder() ENTRY")
prev_sync = self.mmu_machine.filament_always_gripped or self.mmu_toolhead.sync_mode == MmuToolHead.GEAR_SYNCED_TO_EXTRUDER
prev_current = self.gear_percentage_run_current != 100
prev_grip = self.selector.get_filament_grip_state()
try:
yield self
finally:
self.log_error("wrap_sync_gear_to_extruder() FINALLY")
if self.gate_selected >= 0: # PAUL new check
if self.gate_selected >= 0:
self.sync_gear_to_extruder(prev_sync, grip=prev_grip != self.selector.get_filament_grip_state(), current=prev_current)
else: # PAUL new
self.sync_gear_to_extruder(False, grip=True, current=False) # PAUL new
self.log_error("wrap_sync_gear_to_extruder() END")
else:
self.sync_gear_to_extruder(False, grip=True, current=False)

# This is used to protect just the mmu_toolhead sync state and is used to wrap individual moves. Typically
# the starting state will be unsynced so this will simply unsync at the end of the move. It does not manage
Expand Down Expand Up @@ -5456,14 +5449,14 @@ def _set_tmc_current(self, stepper, run_current, msg):
prev_cur, prev_hold_cur, req_hold_cur, max_cur = current_helper.get_current()
new_cur = max(min(run_current, max_cur), 0)
current_helper.set_current(new_cur, req_hold_cur, print_time)
self.log_info(msg.format(new_cur))
self.log_debug(msg.format(new_cur))
except Exception as e:
# Fallback
self.log_debug("Unexpected error setting stepper current: %s. Falling back to default approach" % str(e))
self.log_info(msg.format(run_current))
self.log_debug(msg.format(run_current))
self.gcode.run_script_from_command("SET_TMC_CURRENT STEPPER=%s CURRENT=%.2f" % (stepper, run_current))
else:
self.log_info(msg.format(run_current))
self.log_debug(msg.format(run_current))
self.gcode.run_script_from_command("SET_TMC_CURRENT STEPPER=%s CURRENT=%.2f" % (stepper, run_current))

@contextlib.contextmanager
Expand Down Expand Up @@ -5959,10 +5952,10 @@ def cmd_MMU_HOME(self, gcmd):
force_unload = gcmd.get_int('FORCE_UNLOAD', None, minval=0, maxval=1)

try:
# PAUL with self.wrap_sync_gear_to_extruder():
self.home(tool, force_unload=force_unload)
if tool == -1:
self.log_always("Homed")
with self.wrap_sync_gear_to_extruder():
self.home(tool, force_unload=force_unload)
if tool == -1:
self.log_always("Homed")
except MmuError as ee:
self.handle_mmu_error(str(ee))

Expand Down Expand Up @@ -6009,7 +6002,6 @@ def _select(self, bypass, tool, gate):
try:
if bypass != -1:
self.select_bypass()
# PAUL TODO should this unsync gear? problem is that callers will resync it afterwads..
elif tool != -1:
self.select_tool(tool)
else:
Expand Down Expand Up @@ -6412,7 +6404,7 @@ def cmd_MMU_RECOVER(self, gcmd):
self._remap_tool(tool, gate, loaded)

elif mod_gate >= 0: # If only gate specified then just reset and ensure tool is correct
self.selector.restore_gate(mod_gate) # PAUL added to manage stepper current
self.selector.restore_gate(mod_gate)
self._set_gate_selected(mod_gate)
self._ensure_ttg_match()

Expand Down
6 changes: 1 addition & 5 deletions extras/mmu/mmu_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,19 @@ def home(self, tool = None, force_unload = None):
pass

def select_gate(self, gate):
#self.mmu.log_error("PAUL TEMP: -------selector.select_gate(%d)%s" % (gate, " - IGNORED" if gate == self.mmu.gate_selected else ""))
#if gate == self.mmu.gate_selected: return # TODO: there appears to be a corner case where this fails, so for now always select
if gate == self.mmu.gate_selected: return
self.mmu_toolhead.select_gear_stepper(gate) # Select correct drive stepper or none if bypass

# Sync new MMU gear stepper now if design requires it
if self.mmu.mmu_machine.filament_always_gripped:
self.mmu.sync_gear_to_extruder(gate >= 0, gate, current=True)
#self.mmu.log_error("PAUL TEMP: -------selector.select_gate(END)")

def restore_gate(self, gate):
#self.mmu.log_error("PAUL TEMP: -------selector.restore_gate(%s)" % gate)
self.mmu.mmu_toolhead.select_gear_stepper(gate) # Select correct drive stepper or none if bypass

# Sync MMU gear stepper now if design requires it
if self.mmu.mmu_machine.filament_always_gripped:
self.mmu.sync_gear_to_extruder(gate >= 0, gate, current=True)
#self.mmu.log_error("PAUL TEMP: -------selector.restore_gate(END)")

def filament_drive(self):
pass
Expand Down

0 comments on commit 2e843a0

Please sign in to comment.