From ee684e810178035323e64c8b00053d4cf2aa13b4 Mon Sep 17 00:00:00 2001 From: Juan Pablo Caram Date: Sun, 11 Oct 2015 20:58:21 -0400 Subject: [PATCH] Further work on multi-pass cuts. --- camlib.py | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/camlib.py b/camlib.py index 69e6cb73..4c332650 100644 --- a/camlib.py +++ b/camlib.py @@ -2797,6 +2797,7 @@ class CNCjob(Geometry): depth = 0 while depth > self.z_cut: depth -= depthpercut + # TODO: Working... # G-code # Note: self.linear2gcode() and self.point2gcode() will # lower and raise the tool every time. @@ -3051,7 +3052,9 @@ class CNCjob(Geometry): # TODO: This takes forever. Too much data? self.solid_geometry = cascaded_union([geo['geom'] for geo in self.gcode_parsed]) - def linear2gcode(self, linear, tolerance=0, down=True, up=True): + def linear2gcode(self, linear, tolerance=0, down=True, up=True, + zcut=None, ztravel=None, downrate=None, + feedrate=None, cont=False): """ Generates G-code to cut along the linear feature. @@ -3060,33 +3063,55 @@ class CNCjob(Geometry): :param tolerance: All points in the simplified object will be within the tolerance distance of the original geometry. :type tolerance: float - :return: G-code to cut alon the linear feature. + :return: G-code to cut along the linear feature. :rtype: str """ + if zcut is None: + zcut = self.z_cut + + if ztravel is None: + ztravel = self.z_move + + if downrate is None: + downrate = self.zdownrate + + if feedrate is None: + feedrate = self.feedrate + + t = "G0%d " + CNCjob.defaults["coordinate_format"] + "\n" + + # Simplify paths? if tolerance > 0: target_linear = linear.simplify(tolerance) else: target_linear = linear gcode = "" - #t = "G0%d X%.4fY%.4f\n" - t = "G0%d " + CNCjob.defaults["coordinate_format"] + "\n" + path = list(target_linear.coords) - gcode += t % (0, path[0][0], path[0][1]) # Move to first point - if self.zdownrate is not None: - gcode += "F%.2f\n" % self.zdownrate - gcode += "G01 Z%.4f\n" % self.z_cut # Start cutting - gcode += "F%.2f\n" % self.feedrate - else: - gcode += "G01 Z%.4f\n" % self.z_cut # Start cutting + # Move fast to 1st point + if not cont: + gcode += t % (0, path[0][0], path[0][1]) # Move to first point + # Move down to cutting depth + if down: + # Different feedrate for vertical cut? + if self.zdownrate is not None: + gcode += "F%.2f\n" % downrate + gcode += "G01 Z%.4f\n" % zcut # Start cutting + gcode += "F%.2f\n" % feedrate # Restore feedrate + else: + gcode += "G01 Z%.4f\n" % zcut # Start cutting + + # Cutting... for pt in path[1:]: gcode += t % (1, pt[0], pt[1]) # Linear motion to point + # Up to travelling height. if up: - gcode += "G00 Z%.4f\n" % self.z_move # Stop cutting + gcode += "G00 Z%.4f\n" % ztravel # Stop cutting return gcode