fixes 6826. Simplifies logic for calculating helix stepovers

This commit is contained in:
sliptonic
2022-05-15 13:31:41 -05:00
parent aa19e21662
commit 9adf4c4e33
3 changed files with 37 additions and 28 deletions

View File

@@ -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

View File

@@ -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"):

View File

@@ -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"
)