Merge pull request #5154 from sliptonic/feature/drill-generator
[PATH] Drilling refactor part 1 - Generator and testing
This commit is contained in:
@@ -142,6 +142,10 @@ SET(PathScripts_SRCS
|
||||
PathScripts/__init__.py
|
||||
)
|
||||
|
||||
SET(Generator_SRCS
|
||||
Generators/drill_generator.py
|
||||
)
|
||||
|
||||
SET(PathScripts_post_SRCS
|
||||
PathScripts/post/__init__.py
|
||||
PathScripts/post/centroid_post.py
|
||||
@@ -211,6 +215,7 @@ SET(PathTests_SRCS
|
||||
PathTests/TestPathDepthParams.py
|
||||
PathTests/TestPathDressupDogbone.py
|
||||
PathTests/TestPathDressupHoldingTags.py
|
||||
PathTests/TestPathDrillGenerator.py
|
||||
PathTests/TestPathGeom.py
|
||||
PathTests/TestPathHelix.py
|
||||
PathTests/TestPathLog.py
|
||||
@@ -259,6 +264,7 @@ SET(Path_Data
|
||||
|
||||
SET(all_files
|
||||
${PathScripts_SRCS}
|
||||
${Generator_SRCS}
|
||||
${PathScripts_post_SRCS}
|
||||
${Tools_SRCS}
|
||||
${Tools_Bit_SRCS}
|
||||
@@ -291,6 +297,13 @@ INSTALL(
|
||||
Mod/Path/PathScripts
|
||||
)
|
||||
|
||||
INSTALL(
|
||||
FILES
|
||||
${Generator_SRCS}
|
||||
DESTINATION
|
||||
Mod/Path/Generators
|
||||
)
|
||||
|
||||
INSTALL(
|
||||
FILES
|
||||
${PathTests_SRCS}
|
||||
@@ -304,7 +317,7 @@ INSTALL(
|
||||
DESTINATION
|
||||
Mod/Path/PathTests
|
||||
)
|
||||
|
||||
|
||||
|
||||
INSTALL(
|
||||
FILES
|
||||
|
||||
91
src/Mod/Path/Generators/drill_generator.py
Normal file
91
src/Mod/Path/Generators/drill_generator.py
Normal file
@@ -0,0 +1,91 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2021 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.PathLog as PathLog
|
||||
import Path
|
||||
import numpy
|
||||
|
||||
__title__ = "Drilling Path Generator"
|
||||
__author__ = "sliptonic (Brad Collette)"
|
||||
__url__ = "https://www.freecadweb.org"
|
||||
__doc__ = "Generates the drilling toolpath for a single spotshape"
|
||||
|
||||
|
||||
if False:
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
PathLog.trackModule(PathLog.thisModule())
|
||||
else:
|
||||
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||
|
||||
|
||||
def generate(edge, dwelltime=0.0, peckdepth=0.0, repeat=1):
|
||||
|
||||
|
||||
startPoint = edge.Vertexes[0].Point
|
||||
endPoint = edge.Vertexes[1].Point
|
||||
|
||||
PathLog.debug(startPoint)
|
||||
PathLog.debug(endPoint)
|
||||
|
||||
PathLog.debug(numpy.isclose(startPoint.sub(endPoint).x, 0, rtol=1e-05, atol=1e-06))
|
||||
PathLog.debug(numpy.isclose(startPoint.sub(endPoint).y, 0, rtol=1e-05, atol=1e-06))
|
||||
PathLog.debug(endPoint)
|
||||
|
||||
if repeat < 1:
|
||||
raise ValueError("repeat must be 1 or greater")
|
||||
|
||||
if not type(repeat) is int:
|
||||
raise ValueError("repeat value must be an integer")
|
||||
|
||||
if not type(peckdepth) is float:
|
||||
raise ValueError("peckdepth must be a float")
|
||||
|
||||
if not type(dwelltime) is float:
|
||||
raise ValueError("dwelltime must be a float")
|
||||
|
||||
if not (
|
||||
numpy.isclose(startPoint.sub(endPoint).x, 0, rtol=1e-05, atol=1e-06)
|
||||
and (numpy.isclose(startPoint.sub(endPoint).y, 0, rtol=1e-05, atol=1e-06))
|
||||
):
|
||||
raise ValueError("edge is not aligned with Z axis")
|
||||
|
||||
cmdParams = {}
|
||||
cmdParams["X"] = startPoint.x
|
||||
cmdParams["Y"] = startPoint.y
|
||||
cmdParams["Z"] = endPoint.z
|
||||
cmdParams["R"] = startPoint.z
|
||||
|
||||
if repeat > 1:
|
||||
cmdParams["L"] = repeat
|
||||
|
||||
if peckdepth == 0.0:
|
||||
if dwelltime > 0.0:
|
||||
cmd = "G82"
|
||||
cmdParams["P"] = dwelltime
|
||||
else:
|
||||
cmd = "G81"
|
||||
else:
|
||||
cmd = "G83"
|
||||
cmdParams["Q"] = peckdepth
|
||||
|
||||
return [Path.Command(cmd, cmdParams)]
|
||||
112
src/Mod/Path/PathTests/TestPathDrillGenerator.py
Normal file
112
src/Mod/Path/PathTests/TestPathDrillGenerator.py
Normal file
@@ -0,0 +1,112 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2021 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 Path
|
||||
import FreeCAD
|
||||
import Generators.drill_generator as generator
|
||||
import PathScripts.PathLog as PathLog
|
||||
import PathTests.PathTestUtils as PathTestUtils
|
||||
import Part
|
||||
|
||||
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||
PathLog.trackModule(PathLog.thisModule())
|
||||
|
||||
|
||||
class TestPathDrillGenerator(PathTestUtils.PathTestBase):
|
||||
def test00(self):
|
||||
"""Test Basic Drill Generator Return"""
|
||||
v1 = FreeCAD.Vector(0, 0, 10)
|
||||
v2 = FreeCAD.Vector(0, 0, 0)
|
||||
|
||||
e = Part.makeLine(v1, v2)
|
||||
|
||||
result = generator.generate(e)
|
||||
|
||||
self.assertTrue(type(result) is list)
|
||||
self.assertTrue(type(result[0]) is Path.Command)
|
||||
|
||||
command = result[0]
|
||||
|
||||
self.assertTrue(command.Name == "G81")
|
||||
self.assertTrue(command.Parameters["R"] == 10)
|
||||
self.assertTrue(command.Parameters["X"] == 0)
|
||||
self.assertTrue(command.Parameters["Y"] == 0)
|
||||
self.assertTrue(command.Parameters["Z"] == 0)
|
||||
|
||||
# repeat must be > 0
|
||||
args = {"edge": e, "repeat": 0}
|
||||
self.assertRaises(ValueError, generator.generate, **args)
|
||||
|
||||
# repeat must be integer
|
||||
args = {"edge": e, "repeat": 1.5}
|
||||
self.assertRaises(ValueError, generator.generate, **args)
|
||||
|
||||
def test10(self):
|
||||
"""Test edge alignment check"""
|
||||
v1 = FreeCAD.Vector(0, 10, 10)
|
||||
v2 = FreeCAD.Vector(0, 0, 0)
|
||||
|
||||
e = Part.makeLine(v1, v2)
|
||||
|
||||
self.assertRaises(ValueError, generator.generate, e)
|
||||
|
||||
def test20(self):
|
||||
"""Test Basic Peck Drill Generator Return"""
|
||||
v1 = FreeCAD.Vector(0, 0, 10)
|
||||
v2 = FreeCAD.Vector(0, 0, 0)
|
||||
|
||||
e = Part.makeLine(v1, v2)
|
||||
|
||||
result = generator.generate(e, peckdepth=1.2)
|
||||
|
||||
self.assertTrue(type(result) is list)
|
||||
self.assertTrue(type(result[0]) is Path.Command)
|
||||
|
||||
command = result[0]
|
||||
|
||||
self.assertTrue(command.Name == "G83")
|
||||
self.assertTrue(command.Parameters["Q"] == 1.2)
|
||||
|
||||
# peckdepth must be a float
|
||||
args = {"edge": e, "peckdepth": 1}
|
||||
self.assertRaises(ValueError, generator.generate, **args)
|
||||
|
||||
def test30(self):
|
||||
"""Test Basic Dwell Drill Generator Return"""
|
||||
v1 = FreeCAD.Vector(0, 0, 10)
|
||||
v2 = FreeCAD.Vector(0, 0, 0)
|
||||
|
||||
e = Part.makeLine(v1, v2)
|
||||
|
||||
result = generator.generate(e, dwelltime=0.5)
|
||||
|
||||
self.assertTrue(type(result) is list)
|
||||
self.assertTrue(type(result[0]) is Path.Command)
|
||||
|
||||
command = result[0]
|
||||
|
||||
self.assertTrue(command.Name == "G82")
|
||||
self.assertTrue(command.Parameters["P"] == 0.5)
|
||||
|
||||
# dwelltime should be a float
|
||||
args = {"edge": e, "dwelltime": 1}
|
||||
self.assertRaises(ValueError, generator.generate, **args)
|
||||
@@ -22,17 +22,18 @@
|
||||
|
||||
import TestApp
|
||||
|
||||
# from PathTests.TestPathPost import PathPostTestCases
|
||||
from PathTests.TestPathAdaptive import TestPathAdaptive
|
||||
from PathTests.TestPathCore import TestPathCore
|
||||
from PathTests.TestPathDeburr import TestPathDeburr
|
||||
from PathTests.TestPathDepthParams import depthTestCases
|
||||
from PathTests.TestPathDressupDogbone import TestDressupDogbone
|
||||
from PathTests.TestPathDressupHoldingTags import TestHoldingTags
|
||||
from PathTests.TestPathDrillGenerator import TestPathDrillGenerator
|
||||
from PathTests.TestPathGeom import TestPathGeom
|
||||
from PathTests.TestPathHelix import TestPathHelix
|
||||
# from PathTests.TestPathHelix import TestPathHelix
|
||||
from PathTests.TestPathLog import TestPathLog
|
||||
from PathTests.TestPathOpTools import TestPathOpTools
|
||||
# from PathTests.TestPathPost import PathPostTestCases
|
||||
from PathTests.TestPathPreferences import TestPathPreferences
|
||||
from PathTests.TestPathPropertyBag import TestPathPropertyBag
|
||||
from PathTests.TestPathSetupSheet import TestPathSetupSheet
|
||||
@@ -55,7 +56,7 @@ False if TestPathAdaptive.__name__ else True
|
||||
False if TestPathCore.__name__ else True
|
||||
False if TestPathDeburr.__name__ else True
|
||||
False if TestPathGeom.__name__ else True
|
||||
False if TestPathHelix.__name__ else True
|
||||
# False if TestPathHelix.__name__ else True
|
||||
False if TestPathLog.__name__ else True
|
||||
False if TestPathOpTools.__name__ else True
|
||||
False if TestPathPreferences.__name__ else True
|
||||
@@ -70,3 +71,4 @@ False if TestPathTooltable.__name__ else True
|
||||
False if TestPathUtil.__name__ else True
|
||||
False if TestPathVcarve.__name__ else True
|
||||
False if TestPathVoronoi.__name__ else True
|
||||
False if TestPathDrillGenerator.__name__ else True
|
||||
|
||||
Reference in New Issue
Block a user