Added thread milling radii calculation

This commit is contained in:
Markus Lampert
2019-08-13 22:07:09 -07:00
parent ab9bf8c222
commit 310f72145d
4 changed files with 141 additions and 1 deletions

View File

@@ -153,6 +153,9 @@
</item>
<item row="1" column="1">
<widget class="Gui::QuantitySpinBox" name="toolFlat">
<property name="enabled">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
@@ -160,6 +163,9 @@
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Flat</string>
</property>

View File

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

View File

@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2019 sliptonic <shopinthewoods@gmail.com> *
# * *
# * 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])

View File

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