From 310f72145d2087dd9a28dcb3aa21bef184206e06 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Tue, 13 Aug 2019 22:07:09 -0700 Subject: [PATCH] Added thread milling radii calculation --- .../panels/PageOpThreadMillingEdit.ui | 6 ++ src/Mod/Path/PathScripts/PathThreadMilling.py | 73 ++++++++++++++++++- .../Path/PathTests/TestPathThreadMilling.py | 61 ++++++++++++++++ src/Mod/Path/TestPathApp.py | 2 + 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 src/Mod/Path/PathTests/TestPathThreadMilling.py diff --git a/src/Mod/Path/Gui/Resources/panels/PageOpThreadMillingEdit.ui b/src/Mod/Path/Gui/Resources/panels/PageOpThreadMillingEdit.ui index f1f1ae882b..2e98648175 100644 --- a/src/Mod/Path/Gui/Resources/panels/PageOpThreadMillingEdit.ui +++ b/src/Mod/Path/Gui/Resources/panels/PageOpThreadMillingEdit.ui @@ -153,6 +153,9 @@ + + false + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -160,6 +163,9 @@ + + false + Flat diff --git a/src/Mod/Path/PathScripts/PathThreadMilling.py b/src/Mod/Path/PathScripts/PathThreadMilling.py index 66d277648b..0feb748825 100644 --- a/src/Mod/Path/PathScripts/PathThreadMilling.py +++ b/src/Mod/Path/PathScripts/PathThreadMilling.py @@ -41,12 +41,26 @@ __doc__ = "Path thread milling operation." PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) PathLog.trackModule(PathLog.thisModule()) - # Qt translation handling def translate(context, text, disambig=None): return QtCore.QCoreApplication.translate(context, text, disambig) +def radiiMetricInternal(majorDia, minorDia, toolDia, toolCrest = None): + '''internlThreadRadius(majorDia, minorDia, toolDia, toolCrest) ... returns the maximum radius for thread.''' + if toolCrest is None: + toolCrest = 0.0 + # see https://www.amesweb.info/Screws/Internal-Metric-Thread-Dimensions-Chart.aspx + H = ((majorDia - minorDia) / 2.0 ) * 1.6 # (D - d)/2 = 5/8 * H + outerTip = majorDia / 2.0 + H / 8.0 + toolTip = outerTip - toolCrest * 0.8660254037844386 # math.sqrt(3)/2 ... 60deg triangle height + return ((minorDia - toolDia) / 2, toolTip - toolDia / 2) + +def threadPasses(count, radii, majorDia, minorDia, toolDia, toolCrest = None): + minor, major = radii(majorDia, minorDia, toolDia, toolCrest) + dr = (major - minor) / count + return [major - dr * (count - (i + 1)) for i in range(count)] + class ObjectThreadMilling(PathCircularHoleBase.ObjectOp): '''Proxy object for thread milling operation.''' @@ -77,13 +91,70 @@ class ObjectThreadMilling(PathCircularHoleBase.ObjectOp): obj.addProperty("App::PropertyEnumeration", "Direction", "Mill", QtCore.QT_TRANSLATE_NOOP("App::Property", "Direction of thread cutting operation")) obj.Direction = self.Directions + def threadStartDepth(self, obj): + if self.ThreadDirection == self.RightHand: + if self.Direction == self.DirectionClimb: + return self.FinalDepth + return self.StartDepth + if self.Direction == self.DirectionClimb: + return self.StartDepth + return self.FinalDepth + + def threadFinalDepth(self, obj): + if self.ThreadDirection == self.RightHand: + if self.Direction == self.DirectionClimb: + return self.StartDepth + return self.FinalDepth + if self.Direction == self.DirectionClimb: + return self.FinalDepth + return self.StartDepth + + def threadDirectionCmd(self, obj): + if self.ThreadDirection == self.RightHand: + if self.Direction == self.DirectionClimb: + return 'G2' + return 'G3' + if self.Direction == self.DirectionClimb: + return 'G3' + return 'G2' + + def threadPassRadii(self, obj): + rMajor = (obj.MajorDiameter.Value - self.tool.Diameter) / 2.0 + rMinor = (obj.MinorDiameter.Value - self.tool.Diameter) / 2.0 + if obj.Passes < 1: + obj.Passes = 1 + rPass = (rMajor - rMinor) / obj.Passes + passes = [rMajor] + for i in range(1, obj.Passes): + passes.append(rMajor - rPass * i) + return list(reversed(passes)) + + def executeThreadMill(self, obj, loc, cmd, zStart, zFinal, pitch): + hPitch = obj.Pitch.Value / 2.0 + if zStart > zFinal: + hPitch = -hPitch + + self.commandlist.append(Path.Command('G0', {'Z': zStart, 'F': self.vertRapid})) + for r in threadPasses(obj.Passes, radiiMetricInternal, obj.MajorDiameter, obj.MinorDiameter, self.tool.Diameter, 0): + pass def circularHoleExecute(self, obj, holes): PathLog.track() self.commandlist.append(Path.Command("(Begin Thread Milling)")) + cmd = self.threadDirectionCmd(obj) + zStart = self.threadStartDepth(obj).Value + zFinal = self.threadFinalDepth(obj).Value + pitch = obj.Pitch.Value + if pitch <= 0: + PathLog.error("Cannot create thread with pitch {}".format(pitch)) + return + # rapid to clearance height + for loc in holes: + self.executeThreadMill(obj, loc, cmd, zStart, zFinal, pitch) + self.commandlist.append(Path.Command('G0', {'Z': obj.ClearanceHeight.Value, 'F': self.vertRapid})) diff --git a/src/Mod/Path/PathTests/TestPathThreadMilling.py b/src/Mod/Path/PathTests/TestPathThreadMilling.py new file mode 100644 index 0000000000..8d62c1bf6f --- /dev/null +++ b/src/Mod/Path/PathTests/TestPathThreadMilling.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- + +# *************************************************************************** +# * * +# * Copyright (c) 2019 sliptonic * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +import PathScripts.PathGeom as PathGeom +import PathScripts.PathThreadMilling as PathThreadMilling +import math + +from PathTests.PathTestUtils import PathTestBase + +def radii(major, minor, toolDia, toolCrest): + '''test radii function for simple testing''' + return (minor, major) + +class TestPathThreadMilling(PathTestBase): + '''Test thread milling basics.''' + + def assertRadii(self, have, want): + self.assertRoughly(have[0], want[0]) + self.assertRoughly(have[1], want[1]) + + def assertList(self, have, want): + self.assertEqual(len(have), len(want)); + for i in range(len(have)): + self.assertRoughly(have[i], want[i]) + + def test00(self): + '''Verify metric internal radii.''' + self.assertRadii(PathThreadMilling.radiiMetricInternal(20, 18, 2, 0), (8, 9.2)) + self.assertRadii(PathThreadMilling.radiiMetricInternal(20, 19, 2, 0), (8.5, 9.1)) + + def test01(self): + '''Verify metric internal radii with tool crest.''' + self.assertRadii(PathThreadMilling.radiiMetricInternal(20, 18, 2, 0.1), (8, 9.113397)) + + def test10(self): + '''Verify thread passes.''' + self.assertList(PathThreadMilling.threadPasses(1, radii, 10, 9, 0, 0), [10]) + self.assertList(PathThreadMilling.threadPasses(2, radii, 10, 9, 0, 0), [9.5, 10]) + self.assertList(PathThreadMilling.threadPasses(5, radii, 10, 9, 0, 0), [9.2, 9.4, 9.6, 9.8, 10]) + diff --git a/src/Mod/Path/TestPathApp.py b/src/Mod/Path/TestPathApp.py index 1f4c0247fb..623bf180ee 100644 --- a/src/Mod/Path/TestPathApp.py +++ b/src/Mod/Path/TestPathApp.py @@ -41,6 +41,7 @@ from PathTests.TestPathSetupSheet import TestPathSetupSheet from PathTests.TestPathDeburr import TestPathDeburr from PathTests.TestPathHelix import TestPathHelix from PathTests.TestPathVoronoi import TestPathVoronoi +from PathTests.TestPathThreadMilling import TestPathThreadMilling # dummy usage to get flake8 and lgtm quiet False if TestApp.__name__ else True @@ -62,4 +63,5 @@ False if TestPathHelix.__name__ else True False if TestPathPreferences.__name__ else True False if TestPathToolBit.__name__ else True False if TestPathVoronoi.__name__ else True +False if TestPathThreadMilling.__name__ else True