Skip to content

Commit

Permalink
Tweaks to wipe tower fix
Browse files Browse the repository at this point in the history
  • Loading branch information
adammhaile committed May 29, 2022
1 parent 1d4010b commit 82b239b
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions rrfpost/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from contextlib import suppress
import sys
import os
import re
import argparse
import math

from numpy import isin
from . version import VERSION

MOVE_RE = '([XYZEF] *-?\d*.?\d*)'
Expand All @@ -13,7 +16,6 @@ def __init__(self, num, line):
self.line = line
self.pre = None
self.post = None
self.suppress = False

def IsRetract(self):
if self.line.startswith('G10 ; retract'):
Expand All @@ -29,11 +31,11 @@ def IsUnretract(self):

def get_lines(self, comments=True):
res = ''
if not self.suppress:
if(self.pre is not None): res += (self.pre + '\n')
if comments or ((not comments) and (not self.line.lstrip().startswith(';'))):
res += (self.line + '\n')
if(self.post is not None): res += (self.post + '\n')

if(self.pre is not None): res += (self.pre + '\n')
if comments or ((not comments) and (not self.line.lstrip().startswith(';'))):
res += (self.line + '\n')
if(self.post is not None): res += (self.post + '\n')
return res

def __str__(self):
Expand Down Expand Up @@ -63,6 +65,13 @@ def IsUnretract(self):
return True

return False

def RemoveMove(self):
if self.line.startswith('G1 '):
if self.f is not None:
self.line = f'G1 F{int(self.f)*60}'
else:
self.line = ''

def gen_relative_xyz(self, x, y, z):
rx = 0.0
Expand Down Expand Up @@ -414,26 +423,36 @@ def wipe_tower_fix(self):
last_retract = (-1, None)
last_unretract = (-1, None)
unretract_insert = None
suppress_moves = False
for i in range(len(self.lines)):
l = self.lines[i]

if unretract_insert is not None and l.line.startswith('; CP TOOLCHANGE WIPE'):
out_lines.append(unretract_insert)
unretract_insert = None
if unretract_insert is not None:
if l.line.startswith('; CP TOOLCHANGE WIPE'):
out_lines.append(unretract_insert)
unretract_insert = None
suppress_moves = False
elif isinstance(l, Move) and suppress_moves and (l.x or l.y):
#while waiting for Tool Change command, suppress moves, but leave feed
l.RemoveMove()

out_lines.append(l)
if l.IsRetract():
last_retract = (len(out_lines)-1, l)
if l.IsUnretract():
last_unretract = (len(out_lines)-1, l)

if suppress_moves and isinstance(l, ToolChange):
suppress_moves = False

if l.line.startswith('; CP TOOLCHANGE START'):
ri, rl = last_retract
ui, ul = last_unretract
if ui == ri+2:
out_lines[ri+1].suppress = True
out_lines[ui].suppress = True
out_lines[ri+1].RemoveMove()
unretract_insert = GCodeLine(ul.num, ul.line)
out_lines[ui].line = ''
suppress_moves = True

last_retract = (-1, None)
last_unretract = (-1, None)
Expand Down

0 comments on commit 82b239b

Please sign in to comment.