diff --git a/src/Mod/Path/Generators/helix_generator.py b/src/Mod/Path/Generators/helix_generator.py index cbbae52190..e3535a67a2 100644 --- a/src/Mod/Path/Generators/helix_generator.py +++ b/src/Mod/Path/Generators/helix_generator.py @@ -32,7 +32,7 @@ __doc__ = "Generates the helix for a single spot targetshape" __contributors__ = "russ4262 (Russell Johnson), Lorenz Hüdepohl" -if True: +if False: PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) PathLog.trackModule(PathLog.thisModule()) else: @@ -56,7 +56,6 @@ def generate( startPoint = edge.Vertexes[0].Point endPoint = edge.Vertexes[1].Point - PathLog.track( "(helix: <{}, {}>\n hole radius {}\n inner radius {}\n step over {}\n start point {}\n end point {}\n step_down {}\n tool diameter {}\n direction {}\n startat {})".format( startPoint.x, @@ -73,18 +72,18 @@ def generate( ) ) - if hole_radius < 0.0: - raise ValueError("hole_radius < 0") - - if not type(hole_radius) is float: + if not type(hole_radius) in [float, int]: raise ValueError("hole_radius must be a float") - if not type(inner_radius) is float: + if not type(inner_radius) in [float, int]: raise ValueError("inner_radius must be a float") - if not type(tool_diameter) is float: + if not type(tool_diameter) in [float, int]: raise ValueError("tool_diameter must be a float") + if hole_radius < 0.0: + raise ValueError("hole_radius < 0") + if inner_radius > 0 and hole_radius - inner_radius < tool_diameter: raise ValueError( "hole_radius - inner_radius = {0} is < tool diameter of {1}".format( @@ -114,7 +113,6 @@ def generate( if startPoint.z < endPoint.z: raise ValueError("start point is below end point") - if inner_radius > 0: PathLog.debug("(annulus mode)\n") hole_radius = hole_radius - tool_diameter / 2 @@ -147,8 +145,11 @@ def generate( 2 * hole_radius, tool_diameter ) ) - nz = max(int(ceil((startPoint.z - endPoint.z) / step_down)), 2) - zi = linspace(startPoint.z, endPoint.z, 2 * nz + 1) + # calculate the number of full and partial turns required + # Each full turn is two 180 degree arcs. Zsteps is equally spaced step + # down values + turncount = max(int(ceil((startPoint.z - endPoint.z) / step_down)), 2) + zsteps = linspace(startPoint.z, endPoint.z, 2 * turncount + 1) def helix_cut_r(r): commandlist = [] @@ -157,14 +158,14 @@ def generate( Path.Command("G0", {"X": startPoint.x + r, "Y": startPoint.y}) ) commandlist.append(Path.Command("G1", {"Z": startPoint.z})) - for i in range(1, nz + 1): + for i in range(1, turncount + 1): commandlist.append( Path.Command( arc_cmd, { "X": startPoint.x - r, "Y": startPoint.y, - "Z": zi[2 * i - 1], + "Z": zsteps[2 * i - 1], "I": -r, "J": 0.0, }, @@ -176,7 +177,7 @@ def generate( { "X": startPoint.x + r, "Y": startPoint.y, - "Z": zi[2 * i], + "Z": zsteps[2 * i], "I": r, "J": 0.0, }, @@ -206,6 +207,12 @@ def generate( }, ) ) + if hole_radius <= tool_diameter: + # no plug remains, safe to move to center for retract + commandlist.append( + Path.Command("G0", {"X": endPoint.x, "Y": endPoint.y, "Z": endPoint.z}) + ) + commandlist.append(Path.Command("G0", {"Z": startPoint.z})) commandlist.append( Path.Command( "G0", {"X": startPoint.x, "Y": startPoint.y, "Z": startPoint.z} diff --git a/src/Mod/Path/PathTests/TestPathHelixGenerator.py b/src/Mod/Path/PathTests/TestPathHelixGenerator.py index 0f804b76a8..27b44117b6 100644 --- a/src/Mod/Path/PathTests/TestPathHelixGenerator.py +++ b/src/Mod/Path/PathTests/TestPathHelixGenerator.py @@ -59,8 +59,10 @@ G2 I-7.500000 J0.000000 X-2.500000 Y5.000000 Z18.500000\ G2 I7.500000 J0.000000 X12.500000 Y5.000000 Z18.000000\ G2 I-7.500000 J0.000000 X-2.500000 Y5.000000 Z18.000000\ G2 I7.500000 J0.000000 X12.500000 Y5.000000 Z18.000000\ +G0 Z20.000000\ G0 X5.000000 Y5.000000 Z20.000000" + def test00(self): """Test Basic Helix Generator Return""" args = _resetArgs() @@ -69,6 +71,7 @@ G0 X5.000000 Y5.000000 Z20.000000" self.assertTrue(type(result[0]) is Path.Command) gcode = "".join([r.toGCode() for r in result]) + print(gcode) self.assertTrue( gcode == self.expectedHelixGCode, "Incorrect helix g-code generated" ) @@ -76,7 +79,7 @@ G0 X5.000000 Y5.000000 Z20.000000" def test01(self): """Test Basic Helix Generator hole_radius is float > 0""" args = _resetArgs() - args["hole_radius"] = 10 + args["hole_radius"] = '10' self.assertRaises(ValueError, generator.generate, **args) args["hole_radius"] = -10.0 @@ -85,13 +88,13 @@ G0 X5.000000 Y5.000000 Z20.000000" def test02(self): """Test Basic Helix Generator inner_radius is float""" args = _resetArgs() - args["inner_radius"] = 2 + args["inner_radius"] = '2' self.assertRaises(ValueError, generator.generate, **args) def test03(self): """Test Basic Helix Generator tool_diameter is float""" args = _resetArgs() - args["tool_diameter"] = 5 + args["tool_diameter"] = '5' self.assertRaises(ValueError, generator.generate, **args) def test04(self):