Skip to content

Commit

Permalink
fix: use gcode save/restore
Browse files Browse the repository at this point in the history
  • Loading branch information
ammmze committed Oct 8, 2024
1 parent 406d65d commit b175d1a
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions AFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ def __init__(self, config):
self.current = None
self.failure = False
self.lanes = {}
# tool position when tool change was requested
self.change_tool_pos = None
# whether we failed during a tool change. used to determine if the restore position macro
# should actually restore gcode state
self.failed_in_toolchange = False

# SPOOLMAN
self.spoolman = config.getboolean('spoolman', False)
Expand Down Expand Up @@ -647,30 +648,27 @@ def TOOL_UNLOAD(self, CUR_LANE):

cmd_CHANGE_TOOL_help = "change filaments in tool head"
def cmd_CHANGE_TOOL(self, gcmd):
#self.toolhead = self.printer.lookup_object('toolhead')
lane = gcmd.get('LANE', None)
self.failed_in_toolchange = False
if lane != self.current:
store_pos = self.toolhead.get_position()
if self.is_printing() and not self.is_paused():
self.change_tool_pos = store_pos
# Create save state
self.gcode.run_script_from_command("SAVE_GCODE_STATE NAME=_AFC_CHANGE_TOOL")
if self.current != None:
CUR_LANE = self.printer.lookup_object('AFC_stepper ' + self.current)
self.TOOL_UNLOAD(CUR_LANE)
CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane)
self.TOOL_LOAD(CUR_LANE)
newpos = self.toolhead.get_position()
newpos[2] = store_pos[2]
self.toolhead.manual_move(newpos, self.tool_unload_speed)
self.toolhead.wait_moves()
if self.is_printing() and not self.is_paused():
self.change_tool_pos = None
# Restore state
self.gcode.run_script_from_command("RESTORE_GCODE_STATE NAME=_AFC_CHANGE_TOOL MOVE=1 MOVE_SPEED={}".format(self.tool_unload_speed))
if self.is_printing() and self.is_paused():
self.failed_in_toolchange = True

Check failure on line 664 in AFC.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

AFC.py:664:49: W291 Trailing whitespace

cmd_RESTORE_CHANGE_TOOL_POS_help = "change filaments in tool head"
def cmd_RESTORE_CHANGE_TOOL_POS(self, gcmd):
if self.change_tool_pos:
restore_pos = self.change_tool_pos[:3]
self.toolhead.manual_move(restore_pos, self.tool_unload_speed)
self.toolhead.wait_moves()
if self.failed_in_toolchange:
# Restore previous state
self.failed_in_toolchange = False
self.gcode.run_script_from_command("RESTORE_GCODE_STATE NAME=_AFC_CHANGE_TOOL MOVE=1 MOVE_SPEED={}".format(self.tool_unload_speed))

def hub_cut(self, lane):
CUR_LANE=self.printer.lookup_object('AFC_stepper '+lane)
Expand Down

0 comments on commit b175d1a

Please sign in to comment.