Merge pull request #9200 from J-Dunn/master

Path: make drilling paths G99 aware and NIST compliant (tidy up)
Please make sure to update the wiki.  It would be nice to include a reference to the NIST spec that the title refers to. That way, if there's a regression or complaint, we have some basis to continue the conversation.
Thank you for the PR.
This commit is contained in:
sliptonic
2023-04-07 08:04:27 -05:00
committed by GitHub
6 changed files with 85 additions and 22 deletions

View File

@@ -327,7 +327,12 @@ void PathSegmentWalker::walk(PathSegmentVisitor &cb, const Base::Vector3d &start
}
Base::Vector3d p3(next);
p3.*pz = last.*pz;
if (retract_mode == 99) // G81,G83 need to account for G99 and retract to R only
p3.*pz = p2.*pz;
else
p3.*pz = last.*pz;
Base::Vector3d p3r = compensateRotation(p3, nrot, rotCenter);
plist.push_back(p1r);
@@ -353,6 +358,10 @@ void PathSegmentWalker::walk(PathSegmentVisitor &cb, const Base::Vector3d &start
pz = &Base::Vector3d::y;
} else if(name=="G19") {
pz = &Base::Vector3d::x;
} else if(name=="G98") {
retract_mode = 98;
} else if(name=="G99") {
retract_mode = 99;
}
}
}

View File

@@ -52,7 +52,7 @@ class PathExport PathSegmentVisitor
};
/**
* PathSegmentWalker processes a path a splits all movement commands into straight segments and calls the
* PathSegmentWalker processes a path and splits all movement commands into straight segments and calls the
* appropriate member of the provided PathSegmentVisitor.
* All non-movement commands are processed accordingly if they affect the movement commands.
*/
@@ -66,6 +66,7 @@ public:
private:
const Toolpath &tp;
int retract_mode;
};

View File

@@ -56,6 +56,16 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The tool and its settings to be used for this operation.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="KeepToolDownEnabled">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Don't retract after every hole&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Keep Tool Down</string>
</property>
</widget>
</item>
</layout>
</widget>

View File

@@ -65,7 +65,7 @@ class ObjectDrilling(PathCircularHoleBase.ObjectOp):
# Enumeration lists for App::PropertyEnumeration properties
enums = {
"ReturnLevel": [
"RetractMode": [
(translate("Path_Drilling", "G98"), "G98"),
(translate("Path_Drilling", "G99"), "G99"),
], # How high to retract after a drilling move
@@ -151,10 +151,10 @@ class ObjectDrilling(PathCircularHoleBase.ObjectOp):
)
obj.addProperty(
"App::PropertyEnumeration",
"ReturnLevel",
"RetractMode",
"Drill",
QT_TRANSLATE_NOOP(
"App::Property", "Controls how tool retracts Default=G98"
"App::Property", "Controls tool retract height between holes in same op, Default=G98: safety height"
),
)
obj.addProperty(
@@ -163,15 +163,17 @@ class ObjectDrilling(PathCircularHoleBase.ObjectOp):
"Drill",
QT_TRANSLATE_NOOP(
"App::Property",
"The height where feed starts and height during retract tool when path is finished while in a peck operation",
"The height where cutting feed rate starts and retract height for peck operation",
),
)
obj.addProperty(
"App::PropertyEnumeration",
"ExtraOffset",
"Drill",
QT_TRANSLATE_NOOP("App::Property", "How far the drill depth is extended"),
QT_TRANSLATE_NOOP("App::Property", "How far the drilling depth is extended"),
)
obj.addProperty("App::PropertyBool", "KeepToolDown", "Drill",
QT_TRANSLATE_NOOP("App::Property", "Apply G99 retraction: only retract to RetractHeight between holes in this operation"))
for n in self.propertyEnumerations():
setattr(obj, n[0], n[1])
@@ -197,8 +199,29 @@ class ObjectDrilling(PathCircularHoleBase.ObjectOp):
elif obj.ExtraOffset == "2x Drill Tip":
endoffset = PathUtils.drillTipLength(self.tool) * 2
if not hasattr(obj,"KeepToolDown"):
obj.addProperty("App::PropertyBool", "KeepToolDown", "Drill",
QT_TRANSLATE_NOOP("App::Property", "Apply G99 retraction: only retract to RetractHeight between holes in this operation"))
if not hasattr(obj,"RetractMode"):
obj.addProperty(
"App::PropertyEnumeration",
"RetractMode",
"Drill",
QT_TRANSLATE_NOOP(
"App::Property",
"Controls tool retract height between holes in same op, Default=G98: safety height"
),
)
# ensure new enums exist in old class
for n in self.propertyEnumerations():
setattr(obj, n[0], n[1])
# http://linuxcnc.org/docs/html/gcode/g-code.html#gcode:g98-g99
self.commandlist.append(Path.Command(obj.ReturnLevel))
if obj.KeepToolDown : obj.RetractMode = "G99"
else : obj.RetractMode = "G98"
self.commandlist.append(Path.Command(obj.RetractMode))
holes = PathUtils.sort_locations(holes, ["x", "y"])
@@ -224,13 +247,13 @@ class ObjectDrilling(PathCircularHoleBase.ObjectOp):
startPoint = edge.Vertexes[0].Point
command = Path.Command("G0", {"X": startPoint.x, "Y": startPoint.y})
self.commandlist.append(command)
machine.addCommand(command)
# command = Path.Command("G0", {"X": startPoint.x, "Y": startPoint.y})
# self.commandlist.append(command)
# machine.addCommand(command)
command = Path.Command("G0", {"Z": startHeight})
self.commandlist.append(command)
machine.addCommand(command)
# command = Path.Command("G0", {"Z": startHeight})
# self.commandlist.append(command)
# machine.addCommand(command)
# command = Path.Command("G1", {"Z": obj.StartDepth.Value})
# self.commandlist.append(command)
@@ -276,7 +299,8 @@ class ObjectDrilling(PathCircularHoleBase.ObjectOp):
def opSetDefaultValues(self, obj, job):
"""opSetDefaultValues(obj, job) ... set default value for RetractHeight"""
obj.ExtraOffset = "None"
obj.KeepToolDown = False # default to safest option: G98
if hasattr(job.SetupSheet, "RetractHeight"):
obj.RetractHeight = job.SetupSheet.RetractHeight
elif self.applyExpression(
@@ -305,9 +329,10 @@ def SetupProperties():
setup.append("DwellTime")
setup.append("DwellEnabled")
setup.append("AddTipLength")
setup.append("ReturnLevel")
setup.append("RetractMode")
setup.append("ExtraOffset")
setup.append("RetractHeight")
setup.append("KeepToolDown")
return setup

View File

@@ -110,6 +110,8 @@ class TaskPanelOpPage(PathCircularHoleBaseGui.TaskPanelOpPage):
self.peckRetractSpinBox.updateProperty()
self.dwellTimeSpinBox.updateProperty()
if obj.KeepToolDown != self.form.KeepToolDownEnabled.isChecked():
obj.KeepToolDown = self.form.KeepToolDownEnabled.isChecked()
if obj.DwellEnabled != self.form.dwellEnabled.isChecked():
obj.DwellEnabled = self.form.dwellEnabled.isChecked()
if obj.PeckEnabled != self.form.peckEnabled.isChecked():
@@ -127,6 +129,15 @@ class TaskPanelOpPage(PathCircularHoleBaseGui.TaskPanelOpPage):
Path.Log.track()
self.updateQuantitySpinBoxes()
if not hasattr(obj,"KeepToolDown"):
obj.addProperty("App::PropertyBool", "KeepToolDown", "Drill",
QtCore.QT_TRANSLATE_NOOP("App::Property", "Apply G99 retraction: only retract to RetractHeight between holes in this operation"))
if obj.KeepToolDown:
self.form.KeepToolDownEnabled.setCheckState(QtCore.Qt.Checked)
else:
self.form.KeepToolDownEnabled.setCheckState(QtCore.Qt.Unchecked)
if obj.DwellEnabled:
self.form.dwellEnabled.setCheckState(QtCore.Qt.Checked)
else:
@@ -161,7 +172,8 @@ class TaskPanelOpPage(PathCircularHoleBaseGui.TaskPanelOpPage):
signals.append(self.form.toolController.currentIndexChanged)
signals.append(self.form.coolantController.currentIndexChanged)
signals.append(self.form.ExtraOffset.currentIndexChanged)
signals.append(self.form.KeepToolDownEnabled.stateChanged)
return signals
def updateData(self, obj, prop):

View File

@@ -602,8 +602,10 @@ def drill_translate(outstring, cmd, params):
global UNITS
global UNIT_FORMAT
global UNIT_SPEED_FORMAT
strFormat = "." + str(PRECISION) + "f"
strG0_Initial_Z=("G0 Z" + format(float(CURRENT_Z.getValueAs(UNIT_FORMAT)), strFormat) + "\n")
trBuff = ""
@@ -630,8 +632,8 @@ def drill_translate(outstring, cmd, params):
drill_Z += CURRENT_Z
RETRACT_Z += CURRENT_Z
if DRILL_RETRACT_MODE == "G98" and CURRENT_Z >= RETRACT_Z:
RETRACT_Z = CURRENT_Z
# if DRILL_RETRACT_MODE == "G98" and CURRENT_Z >= RETRACT_Z:
# RETRACT_Z = CURRENT_Z
# get the other parameters
drill_feedrate = Units.Quantity(params["F"], FreeCAD.Units.Velocity)
@@ -670,10 +672,10 @@ def drill_translate(outstring, cmd, params):
+ "\n"
)
if CURRENT_Z > RETRACT_Z:
# NIST GCODE 3.5.16.1 Preliminary and In-Between Motion says G0 to RETRACT_Z. Here use G1 since retract height may be below surface !
# NIST GCODE 3.5.16.1 Preliminary and In-Between Motion says G0 to RETRACT_Z.
trBuff += (
linenumber()
+ "G1 Z"
+ "G0 Z"
+ format(float(RETRACT_Z.getValueAs(UNIT_FORMAT)), strFormat)
+ strF_Feedrate
)
@@ -726,7 +728,11 @@ def drill_translate(outstring, cmd, params):
+ format(float(drill_Z.getValueAs(UNIT_FORMAT)), strFormat)
+ strF_Feedrate
)
trBuff += linenumber() + strG0_RETRACT_Z
if DRILL_RETRACT_MODE == "G98" :
trBuff += (linenumber() + strG0_Initial_Z)
else:
trBuff += (linenumber() + strG0_RETRACT_Z)
break
except Exception as e: