From 9adf4c4e332ef3f185e5073e93d5e4d135659f8a Mon Sep 17 00:00:00 2001 From: sliptonic Date: Sun, 15 May 2022 13:31:41 -0500 Subject: [PATCH] fixes 6826. Simplifies logic for calculating helix stepovers --- src/Mod/Path/Generators/helix_generator.py | 38 +++++++------------ src/Mod/Path/PathScripts/PathHelix.py | 1 + .../Path/PathTests/TestPathHelixGenerator.py | 26 +++++++++++-- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/Mod/Path/Generators/helix_generator.py b/src/Mod/Path/Generators/helix_generator.py index 1d83095025..ecd63d8457 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 False: +if True: PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) PathLog.trackModule(PathLog.thisModule()) else: @@ -47,7 +47,7 @@ def generate( tool_diameter, inner_radius=0.0, direction="CW", - startAt="Inside", + startAt="Outside", ): """generate(edge, hole_radius, inner_radius, step_over) ... generate helix commands. hole_radius, inner_radius: outer and inner radius of the hole @@ -120,17 +120,7 @@ def generate( if startPoint.z < endPoint.z: raise ValueError("start point is below end point") - if inner_radius > 0: - PathLog.debug("(annulus mode)\n") - outer_radius = hole_radius - tool_diameter / 2 - step_radius = inner_radius + tool_diameter / 2 - if abs((outer_radius - step_radius) / step_over_distance) < 1e-5: - radii = [(outer_radius + inner_radius) / 2] - else: - nr = max(int(ceil((outer_radius - inner_radius) / step_over_distance)), 2) - radii = linspace(outer_radius, step_radius, nr) - - elif hole_radius <= 2 * tool_diameter: + if hole_radius <= tool_diameter: PathLog.debug("(single helix mode)\n") radii = [hole_radius - tool_diameter / 2] if radii[0] <= 0: @@ -140,19 +130,17 @@ def generate( ) ) outer_radius = hole_radius - else: - PathLog.debug("(full hole mode)\n") - outer_radius = hole_radius - tool_diameter / 2 - nr = max(1 + int(ceil((outer_radius - inner_radius) / step_over_distance)), 2) - PathLog.debug("nr: {}".format(nr)) - radii = [r for r in linspace(outer_radius, inner_radius, nr) if r > 0] - if not radii: - raise ValueError( - "Cannot helix a hole of diameter {0} with a tool of diameter {1}".format( - 2 * hole_radius, tool_diameter - ) - ) + else: # inner_radius > 0: + PathLog.debug("(annulus mode / full hole)\n") + outer_radius = hole_radius - tool_diameter / 2 + step_radius = inner_radius + tool_diameter / 2 + if abs((outer_radius - step_radius) / step_over_distance) < 1e-5: + radii = [(outer_radius + inner_radius) / 2] + else: + nr = max(int(ceil((outer_radius - inner_radius) / step_over_distance)), 2) + radii = linspace(outer_radius, step_radius, nr) + PathLog.debug("Radii: {}".format(radii)) # calculate the number of full and partial turns required # Each full turn is two 180 degree arcs. Zsteps is equally spaced step diff --git a/src/Mod/Path/PathScripts/PathHelix.py b/src/Mod/Path/PathScripts/PathHelix.py index b64efd0c0b..0b2eaf8a73 100644 --- a/src/Mod/Path/PathScripts/PathHelix.py +++ b/src/Mod/Path/PathScripts/PathHelix.py @@ -146,6 +146,7 @@ class ObjectHelix(PathCircularHoleBase.ObjectOp): ENUMS = self.helixOpPropertyEnumerations() for n in ENUMS: setattr(obj, n[0], n[1]) + obj.StepOver = 50 def opOnDocumentRestored(self, obj): if not hasattr(obj, "StartRadius"): diff --git a/src/Mod/Path/PathTests/TestPathHelixGenerator.py b/src/Mod/Path/PathTests/TestPathHelixGenerator.py index d3707f9236..b6588901b7 100644 --- a/src/Mod/Path/PathTests/TestPathHelixGenerator.py +++ b/src/Mod/Path/PathTests/TestPathHelixGenerator.py @@ -51,7 +51,26 @@ def _resetArgs(): class TestPathHelixGenerator(PathTestUtils.PathTestBase): - expectedHelixGCode = "G0 X12.500000 Y5.000000\ + + expectedHelixGCode = "G0 X7.500000 Y5.000000\ +G1 Z20.000000\ +G2 I-2.500000 J0.000000 X2.500000 Y5.000000 Z19.500000\ +G2 I2.500000 J0.000000 X7.500000 Y5.000000 Z19.000000\ +G2 I-2.500000 J0.000000 X2.500000 Y5.000000 Z18.500000\ +G2 I2.500000 J0.000000 X7.500000 Y5.000000 Z18.000000\ +G2 I-2.500000 J0.000000 X2.500000 Y5.000000 Z18.000000\ +G2 I2.500000 J0.000000 X7.500000 Y5.000000 Z18.000000\ +G0 X5.000000 Y5.000000 Z18.000000\ +G0 Z20.000000G0 X10.000000 Y5.000000\ +G1 Z20.000000\ +G2 I-5.000000 J0.000000 X0.000000 Y5.000000 Z19.500000\ +G2 I5.000000 J0.000000 X10.000000 Y5.000000 Z19.000000\ +G2 I-5.000000 J0.000000 X0.000000 Y5.000000 Z18.500000\ +G2 I5.000000 J0.000000 X10.000000 Y5.000000 Z18.000000\ +G2 I-5.000000 J0.000000 X0.000000 Y5.000000 Z18.000000\ +G2 I5.000000 J0.000000 X10.000000 Y5.000000 Z18.000000\ +G0 X5.000000 Y5.000000 Z18.000000\ +G0 Z20.000000G0 X12.500000 Y5.000000\ G1 Z20.000000\ G2 I-7.500000 J0.000000 X-2.500000 Y5.000000 Z19.500000\ G2 I7.500000 J0.000000 X12.500000 Y5.000000 Z19.000000\ @@ -59,8 +78,8 @@ 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 X5.000000 Y5.000000 Z18.000000\ -G0 Z20.000000" +G0 X5.000000 Y5.000000 Z18.000000G0 Z20.000000" + def test00(self): """Test Basic Helix Generator Return""" @@ -70,6 +89,7 @@ G0 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" )