Skip to content

Commit

Permalink
More 'next_pos' refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
Dendrowen committed Mar 12, 2024
1 parent a50a2f4 commit 5efe0c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
6 changes: 3 additions & 3 deletions components/mmu_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ def copy_next_position_to_toolhange_param(file_path, tmp_file):
with open(file_path, 'r') as in_file:
in_content = in_file.read()
# Look for tool changes (Tx) and the next move command (G0/1) and fetch the XYZ locations. Then place a new command
# above the toolchange (_MMU_POS_AFTER_NEXT_TOOLCHANGE POS="xx.xx,yy.yy,zz.zz")
# above the toolchange (MMU_CHANGE_TOOL TOOL=x NEXT_POS="xx.xx,yy.yy")
out_content = re.sub(
r'(?P<tool>^T\d{1,3})(?P<other>[\s\S]+?)(?P<cmd>G[01](?:\s+X(?P<X>[\d.]*)|\s+Y(?P<Y>[\d.]*)|\s+Z(?P<Z>[\d.]*))+.*)',
r'_MMU_POS_AFTER_NEXT_TOOLCHANGE POS="\g<X>,\g<Y>,\g<Z>"\n\g<tool>\g<other>\g<cmd>',
r'^T(?P<tool>\d{1,3})(?P<other>[\s\S]+?)(?P<cmd>G[01](?:\s+X(?P<X>[\d.]*)|\s+Y(?P<Y>[\d.]*)|\s+F(?P<F>[\d]*))+.*)',
r'MMU_CHANGE_TOOL TOOL=\g<tool> NEXT_POS="\g<X>,\g<Y>" ; T\g<tool>\n\g<other>\g<cmd>',
in_content,
flags=re.MULTILINE
)
Expand Down
5 changes: 2 additions & 3 deletions config/base/mmu_sequence.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ gcode:
{% set vars = printer['gcode_macro _MMU_SEQUENCE_VARS'] %}
{% set park_vars = printer['gcode_macro _MMU_PARK'] %}
{% set x,y,z = park_vars.saved_xyz|map('float') %}
{% set nx,ny,nz = park_vars.next_xyz|map('float') %}
{% set nz = nz if nz >= 0 else z %}
{% set nx,ny = park_vars.next_xyz|map('float') %}
{% set travel_speed = vars.travel_speed|default(200)|float * 60 %}
{% set lift_speed = vars.lift_speed|default(15)|float * 60 %}
{% set advance_xy_pos = vars.advance_xy_pos|default(true)|lower == 'true' %}
Expand All @@ -134,7 +133,7 @@ gcode:
{% if advance_xy_pos and park_vars.next_pos %}
G1 X{nx} Y{ny} F{travel_speed} # Restore X,Y position
{% if 'z' in printer.toolhead.homed_axes %}
G1 Z{nz} F{lift_speed} # Restore Z position as last step
G1 Z{z} F{lift_speed} # Restore Z position as last step
{% endif %}
{% elif park_vars.saved_pos %}
{% if restore_xy_pos or not printing %} # Are we or slicer restoring position
Expand Down
18 changes: 9 additions & 9 deletions extras/mmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,6 @@ def __init__(self, config):
self.gcode.register_command('MMU_TOOL_OVERRIDES', self.cmd_MMU_TOOL_OVERRIDES, desc = self.cmd_MMU_TOOL_OVERRIDES_help)
self.gcode.register_command('MMU_SLICER_TOOL_MAP', self.cmd_MMU_SLICER_TOOL_MAP, desc = self.cmd_MMU_SLICER_TOOL_MAP_help)

self.gcode.register_command('_MMU_POS_AFTER_NEXT_TOOLCHANGE', self.cmd_MMU_POS_AFTER_NEXT_TOOLCHANGE, desc = self.cmd_MMU_POS_AFTER_NEXT_TOOLCHANGE_help)

# For use in user controlled load and unload macros
self.gcode.register_command('_MMU_STEP_LOAD_GATE', self.cmd_MMU_STEP_LOAD_GATE, desc = self.cmd_MMU_STEP_LOAD_GATE_help)
self.gcode.register_command('_MMU_STEP_UNLOAD_GATE', self.cmd_MMU_STEP_UNLOAD_GATE, desc = self.cmd_MMU_STEP_UNLOAD_GATE_help)
Expand Down Expand Up @@ -5077,7 +5075,7 @@ def _unload_tool(self, skip_tip=False, runout=False):
self._wrap_track_time('post_unload', self._wrap_gcode_command(self.post_unload_macro, exception=True))

# This is the main function for initiating a tool change, it will handle unload if necessary
def _change_tool(self, tool, skip_tip=True):
def _change_tool(self, tool, skip_tip=True, next_pos=''):
self._log_debug("Tool change initiated %s" % ("with slicer tip forming" if skip_tip else "with standalone MMU tip forming"))
self._track_time_start('total')
skip_unload = False
Expand Down Expand Up @@ -5119,6 +5117,9 @@ def _change_tool(self, tool, skip_tip=True):
if not skip_unload:
self._unload_tool(skip_tip=skip_tip)

if next_pos:
self._set_next_position(next_pos)

self._select_and_load_tool(tool)
self._track_swap_completed()

Expand Down Expand Up @@ -5311,6 +5312,7 @@ def cmd_MMU_CHANGE_TOOL(self, gcmd):

quiet = gcmd.get_int('QUIET', 0, minval=0, maxval=1)
standalone = bool(gcmd.get_int('STANDALONE', 0, minval=0, maxval=1))
next_pos = gcmd.get('NEXT_POS', '')
cmd = gcmd.get_command().strip()
match = re.match(r'[Tt](\d{1,3})$', cmd)
if match:
Expand All @@ -5334,7 +5336,7 @@ def cmd_MMU_CHANGE_TOOL(self, gcmd):
try:
for i in range(attempts):
try:
if self._change_tool(tool, skip_tip):
if self._change_tool(tool, skip_tip, next_pos):
self._dump_statistics(job=not quiet, gate=not quiet)
continue
except MmuError as ee:
Expand Down Expand Up @@ -6436,14 +6438,12 @@ def cmd_MMU_SLICER_TOOL_MAP(self, gcmd):
msg += "\nDETAIL=1 to see purge volumes"
self._log_always(msg)

cmd_MMU_POS_AFTER_NEXT_TOOLCHANGE_help = "Set the next location after the next toolchange. The toolhead can then travel to that location instead of the old one"
def cmd_MMU_POS_AFTER_NEXT_TOOLCHANGE(self, gcmd):
pos = gcmd.get('POS', '').split(',')
def _set_next_position(self, next_pos):
pos = next_pos.split(',')
if pos[0] and pos[1]:
x = pos[0]
y = pos[1]
z = pos[2] or -1
self._wrap_gcode_command(f"SET_GCODE_VARIABLE MACRO=_MMU_PARK VARIABLE=next_xyz VALUE=\"{x}, {y}, {z}\"")
self._wrap_gcode_command(f"SET_GCODE_VARIABLE MACRO=_MMU_PARK VARIABLE=next_xyz VALUE=\"{x}, {y}\"")
self._wrap_gcode_command(f"SET_GCODE_VARIABLE MACRO=_MMU_PARK VARIABLE=next_pos VALUE={True}")
else:
self._wrap_gcode_command(f"SET_GCODE_VARIABLE MACRO=_MMU_PARK VARIABLE=next_pos VALUE={False}")
Expand Down

0 comments on commit 5efe0c5

Please sign in to comment.