FreeCAD

Форк
0
/
TestPathThreadMillingGenerator.py 
245 строк · 8.3 Кб
1
# -*- coding: utf-8 -*-
2
# ***************************************************************************
3
# *   Copyright (c) 2019 sliptonic <shopinthewoods@gmail.com>               *
4
# *                                                                         *
5
# *   This program is free software; you can redistribute it and/or modify  *
6
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
7
# *   as published by the Free Software Foundation; either version 2 of     *
8
# *   the License, or (at your option) any later version.                   *
9
# *   for detail see the LICENCE text file.                                 *
10
# *                                                                         *
11
# *   This program is distributed in the hope that it will be useful,       *
12
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
# *   GNU Library General Public License for more details.                  *
15
# *                                                                         *
16
# *   You should have received a copy of the GNU Library General Public     *
17
# *   License along with this program; if not, write to the Free Software   *
18
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
19
# *   USA                                                                   *
20
# *                                                                         *
21
# ***************************************************************************
22

23
import FreeCAD
24
import Path.Base.Generator.threadmilling as threadmilling
25
import math
26

27
from Tests.PathTestUtils import PathTestBase
28

29

30
def radii(internal, major, minor, toolDia, toolCrest):
31
    """test radii function for simple testing"""
32
    return (minor, major)
33

34

35
class TestPathThreadMillingGenerator(PathTestBase):
36
    """Test thread milling generator."""
37

38
    def test00(self):
39
        """Verify thread commands for a single thread"""
40

41
        center = FreeCAD.Vector()
42
        cmd = "G2"
43
        zStart = 0
44
        zFinal = 1
45
        pitch = 1
46
        radius = 3
47
        leadInOut = False
48
        elevator = 2
49

50
        path, start = threadmilling.generate(
51
            center, cmd, zStart, zFinal, pitch, radius, leadInOut, elevator, None
52
        )
53

54
        gcode = [
55
            "G0 X0.000000 Y2.000000",
56
            "G0 Z0.000000",
57
            "G1 Y3.000000",
58
            "G2 J-3.000000 Y-3.000000 Z0.500000",
59
            "G2 J3.000000 Y3.000000 Z1.000000",
60
            "G1 X0.000000 Y2.000000",
61
        ]
62
        self.assertEqual([p.toGCode() for p in path], gcode)
63
        self.assertCoincide(start, FreeCAD.Vector(0, 2, zFinal))
64

65
    def test01(self):
66
        """Verify thread commands for a thwo threads"""
67

68
        center = FreeCAD.Vector()
69
        cmd = "G2"
70
        zStart = 0
71
        zFinal = 2
72
        pitch = 1
73
        radius = 3
74
        leadInOut = False
75
        elevator = 2
76

77
        path, start = threadmilling.generate(
78
            center, cmd, zStart, zFinal, pitch, radius, leadInOut, elevator, None
79
        )
80

81
        gcode = [
82
            "G0 X0.000000 Y2.000000",
83
            "G0 Z0.000000",
84
            "G1 Y3.000000",
85
            "G2 J-3.000000 Y-3.000000 Z0.500000",
86
            "G2 J3.000000 Y3.000000 Z1.000000",
87
            "G2 J-3.000000 Y-3.000000 Z1.500000",
88
            "G2 J3.000000 Y3.000000 Z2.000000",
89
            "G1 X0.000000 Y2.000000",
90
        ]
91
        self.assertEqual([p.toGCode() for p in path], gcode)
92
        self.assertCoincide(start, FreeCAD.Vector(0, 2, zFinal))
93

94
    def test02(self):
95
        """Verify thread commands for a one and a half threads"""
96

97
        center = FreeCAD.Vector()
98
        cmd = "G2"
99
        zStart = 0
100
        zFinal = 1.5
101
        pitch = 1
102
        radius = 3
103
        leadInOut = False
104
        elevator = 2
105

106
        path, start = threadmilling.generate(
107
            center, cmd, zStart, zFinal, pitch, radius, leadInOut, elevator, None
108
        )
109

110
        gcode = [
111
            "G0 X0.000000 Y2.000000",
112
            "G0 Z0.000000",
113
            "G1 Y3.000000",
114
            "G2 J-3.000000 Y-3.000000 Z0.500000",
115
            "G2 J3.000000 Y3.000000 Z1.000000",
116
            "G2 J-3.000000 Y-3.000000 Z1.500000",
117
            "G1 X0.000000 Y-2.000000",
118
        ]
119
        self.assertEqual([p.toGCode() for p in path], gcode)
120
        self.assertCoincide(start, FreeCAD.Vector(0, -2, zFinal))
121

122
    def test03(self):
123
        """Verify thread commands for a one and 3 quarter threads"""
124

125
        center = FreeCAD.Vector()
126
        cmd = "G2"
127
        zStart = 0
128
        zFinal = 1.75
129
        pitch = 1
130
        radius = 3
131
        leadInOut = False
132
        elevator = 2
133

134
        path, start = threadmilling.generate(
135
            center, cmd, zStart, zFinal, pitch, radius, leadInOut, elevator, None
136
        )
137

138
        gcode = [
139
            "G0 X0.000000 Y2.000000",
140
            "G0 Z0.000000",
141
            "G1 Y3.000000",
142
            "G2 J-3.000000 Y-3.000000 Z0.500000",
143
            "G2 J3.000000 Y3.000000 Z1.000000",
144
            "G2 J-3.000000 Y-3.000000 Z1.500000",
145
            #'(------- finish-thread -------)',
146
            "G2 J3.000000 X-3.000000 Y0.000000 Z1.750000",
147
            #'(------- finish-thread -------)',
148
            "G1 X-2.000000 Y0.000000",
149
        ]
150
        self.assertEqual([p.toGCode() for p in path], gcode)
151
        self.assertCoincide(start, FreeCAD.Vector(-2, 0, zFinal))
152

153
    def test04(self):
154
        """Verify thread commands for a one and 3 quarter threads - CCW"""
155

156
        center = FreeCAD.Vector()
157
        cmd = "G3"
158
        zStart = 0
159
        zFinal = 1.75
160
        pitch = 1
161
        radius = 3
162
        leadInOut = False
163
        elevator = 2
164

165
        path, start = threadmilling.generate(
166
            center, cmd, zStart, zFinal, pitch, radius, leadInOut, elevator, None
167
        )
168

169
        gcode = [
170
            "G0 X0.000000 Y2.000000",
171
            "G0 Z0.000000",
172
            "G1 Y3.000000",
173
            "G3 J-3.000000 Y-3.000000 Z0.500000",
174
            "G3 J3.000000 Y3.000000 Z1.000000",
175
            "G3 J-3.000000 Y-3.000000 Z1.500000",
176
            #'(------- finish-thread -------)',
177
            "G3 J3.000000 X3.000000 Y0.000000 Z1.750000",
178
            #'(------- finish-thread -------)',
179
            "G1 X2.000000 Y0.000000",
180
        ]
181
        self.assertEqual([p.toGCode() for p in path], gcode)
182
        self.assertCoincide(start, FreeCAD.Vector(2, 0, zFinal))
183

184
    def test10(self):
185
        """Verify lead in/out commands for a single thread"""
186

187
        center = FreeCAD.Vector()
188
        cmd = "G2"
189
        zStart = 0
190
        zFinal = 1
191
        pitch = 1
192
        radius = 3
193
        leadInOut = True
194
        elevator = 2
195

196
        path, start = threadmilling.generate(
197
            center, cmd, zStart, zFinal, pitch, radius, leadInOut, elevator, None
198
        )
199

200
        gcode = [
201
            "G0 X0.000000 Y2.000000",
202
            "G0 Z0.000000",
203
            #'(------- lead-in -------)',
204
            "G2 J0.500000 Y3.000000",
205
            #'(------- lead-in -------)',
206
            "G2 J-3.000000 Y-3.000000 Z0.500000",
207
            "G2 J3.000000 Y3.000000 Z1.000000",
208
            #'(------- lead-out -------)',
209
            "G2 I0.000000 J-0.500000 X0.000000 Y2.000000",
210
            #'(------- lead-out -------)',
211
        ]
212
        self.assertEqual([p.toGCode() for p in path], gcode)
213
        self.assertCoincide(start, FreeCAD.Vector(0, 2, zFinal))
214

215
    def test11(self):
216
        """Verify lead in/out commands for one and a half threads"""
217

218
        center = FreeCAD.Vector()
219
        cmd = "G2"
220
        zStart = 0
221
        zFinal = 1.5
222
        pitch = 1
223
        radius = 3
224
        leadInOut = True
225
        elevator = 2
226

227
        path, start = threadmilling.generate(
228
            center, cmd, zStart, zFinal, pitch, radius, leadInOut, elevator, None
229
        )
230

231
        gcode = [
232
            "G0 X0.000000 Y2.000000",
233
            "G0 Z0.000000",
234
            #'(------- lead-in -------)',
235
            "G2 J0.500000 Y3.000000",
236
            #'(------- lead-in -------)',
237
            "G2 J-3.000000 Y-3.000000 Z0.500000",
238
            "G2 J3.000000 Y3.000000 Z1.000000",
239
            "G2 J-3.000000 Y-3.000000 Z1.500000",
240
            #'(------- lead-out -------)',
241
            "G2 I0.000000 J0.500000 X0.000000 Y-2.000000",
242
            #'(------- lead-out -------)',
243
        ]
244
        self.assertEqual([p.toGCode() for p in path], gcode)
245
        self.assertCoincide(start, FreeCAD.Vector(0, -2, zFinal))
246

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.