Skip to content

Commit 21a597a

Browse files
CAM: Post Processor Dyna_4060_Post - various bug fixes and updates (FreeCAD#27202)
* various bug fixes and updates * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1c90c1e commit 21a597a

File tree

1 file changed

+48
-29
lines changed

1 file changed

+48
-29
lines changed

src/Mod/CAM/Path/Post/scripts/dynapath_4060_post.py

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,6 @@
5050
delta_4060_post.export(object,"/path/to/file.ncc","")
5151
"""
5252

53-
# Preamble text will appear at the beginning of the GCODE output file.
54-
PREAMBLE = """G17
55-
G90
56-
G80
57-
G40
58-
"""
59-
60-
# Postamble text will appear following the last operation.
61-
POSTAMBLE = """M05
62-
G80
63-
G40
64-
G17
65-
G90
66-
M30
67-
"""
68-
6953
parser = argparse.ArgumentParser(prog="delta_4060", add_help=False)
7054
parser.add_argument("--no-header", action="store_true", help="suppress header output")
7155
parser.add_argument("--no-comments", action="store_true", help="suppress comment output")
@@ -78,17 +62,11 @@
7862
parser.add_argument("--precision", default="3", help="number of digits of precision, default=3")
7963
parser.add_argument(
8064
"--preamble",
81-
help='set commands to be issued before the first command, default="'
82-
+ PREAMBLE.replace("\n", "\\n")
83-
+ '"',
84-
default=PREAMBLE,
65+
help='set commands to be issued before the first command, default="G17\\nG90\\nG80\\nG40\\n"',
8566
)
8667
parser.add_argument(
8768
"--postamble",
88-
help='set commands to be issued after the last command, default="'
89-
+ POSTAMBLE.replace("\n", "\\n")
90-
+ '"',
91-
default=POSTAMBLE,
69+
help='set commands to be issued after the last command, default="M09\\nM05\\nG80\\nG40\\nG17\\nG90\\nM30\\n"',
9270
)
9371
parser.add_argument(
9472
"--inches", action="store_true", help="Convert output for US imperial mode (G70)"
@@ -131,7 +109,7 @@
131109
UNITS = "G71" # G71 for metric, G70 for US standard
132110
UNIT_SPEED_FORMAT = "mm/min"
133111
UNIT_FORMAT = "mm"
134-
MACHINE_NAME = "Delta 4060"
112+
MACHINE_NAME = "Delta_4060"
135113
CORNER_MIN = {"x": 0, "y": 0, "z": 0}
136114
CORNER_MAX = {"x": 660, "y": 355, "z": 152}
137115
PRECISION = 3
@@ -151,6 +129,21 @@
151129
"G59": "E06",
152130
}
153131

132+
# Preamble text will appear at the beginning of the GCODE output file.
133+
PREAMBLE = """G17
134+
G90
135+
G80
136+
G40
137+
"""
138+
139+
# Postamble text will appear following the last operation.
140+
POSTAMBLE = """M05
141+
G80
142+
G40
143+
G17
144+
G90
145+
M30
146+
"""
154147
# Create following variable for use with the 2nd reference plane.
155148
clearanceHeight = None
156149

@@ -299,7 +292,7 @@ def export(objectslist, filename, argstring):
299292

300293
if FreeCAD.GuiUp and SHOW_EDITOR:
301294
dia = PostUtils.GCodeEditorDialog()
302-
dia.editor.setPlainText(gcode)
295+
dia.editor.setText(gcode)
303296
result = dia.exec_()
304297
if result:
305298
final = dia.editor.toPlainText()
@@ -405,7 +398,33 @@ def parse(pathobj):
405398

406399
if c.Name.startswith("(") and not OUTPUT_COMMENTS: # command is a comment
407400
continue
408-
401+
# Handle G84/G74 tapping cycles
402+
if command in ("G84", "G74") and "F" in c.Parameters:
403+
pitch_mm = float(c.Parameters["F"])
404+
c.Parameters.pop("F") # Remove F from output, we'll handle it
405+
406+
# Get spindle speed (from S param or last known value)
407+
spindle_speed = None
408+
if "S" in c.Parameters:
409+
spindle_speed = float(c.Parameters["S"])
410+
c.Parameters.pop("S")
411+
412+
# Convert pitch to inches if needed
413+
if UNITS == "G70": # imperial
414+
pitch = pitch_mm / 25.4
415+
else:
416+
pitch = pitch_mm
417+
418+
# Calculate feed rate
419+
if spindle_speed is not None:
420+
feed_rate = pitch * spindle_speed
421+
speed = Units.Quantity(feed_rate, UNIT_SPEED_FORMAT)
422+
outstring.append(
423+
"F" + format(float(speed.getValueAs(UNIT_SPEED_FORMAT)), precision_string)
424+
)
425+
else:
426+
# No spindle speed found, output pitch as F
427+
outstring.append("F" + format(pitch, precision_string))
409428
# Now add the remaining parameters in order
410429
for param in params:
411430
if param in c.Parameters:
@@ -425,7 +444,7 @@ def parse(pathobj):
425444
# This fixes an error thrown by Dynapath due to missing and
426445
# required XYZ move after Tool change.
427446
elif param == "Z" and (
428-
c.Parameters["Z"] == clearanceHeight and c.Parameters["Z"] != lastZ
447+
c.Parameters["Z"] == clearanceHeight and command in ["G0", "G00"]
429448
):
430449
x = 0
431450
y = 0
@@ -505,7 +524,7 @@ def parse(pathobj):
505524
) # First Reference plan (Safe Height)
506525
elif param == "P":
507526
outstring.append(
508-
"L" + format(c.Parameters[param], precision_string)
527+
"L" + format(c.Parameters[param], ".1f")
509528
) # Converts "P" to "L" for dynapath.
510529
else:
511530
if (

0 commit comments

Comments
 (0)