FreeCAD

Форк
0
/
TestPathThreadMilling.py 
156 строк · 6.2 Кб
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
25
import Path.Op.ThreadMilling as PathThreadMilling
26
import math
27

28
from Tests.PathTestUtils import PathTestBase
29

30

31
class TestObject(object):
32
    def __init__(self, orientation, direction, zTop, zBottom):
33
        self.ThreadOrientation = orientation
34
        self.Direction = direction
35
        self.StartDepth = FreeCAD.Units.Quantity(zTop, FreeCAD.Units.Length)
36
        self.FinalDepth = FreeCAD.Units.Quantity(zBottom, FreeCAD.Units.Length)
37

38

39
def radii(internal, major, minor, toolDia, toolCrest):
40
    """test radii function for simple testing"""
41
    if internal:
42
        return (minor, major)
43
    return (major, minor)
44

45

46
class TestPathThreadMilling(PathTestBase):
47
    """Test thread milling basics."""
48

49
    def assertRadii(self, have, want):
50
        self.assertRoughly(have[0], want[0])
51
        self.assertRoughly(have[1], want[1])
52

53
    def assertList(self, have, want):
54
        self.assertEqual(len(have), len(want))
55
        for i in range(len(have)):
56
            self.assertRoughly(have[i], want[i])
57

58
    def assertSetupInternal(self, obj, c, begin, end):
59
        cmd, zBegin, zEnd = PathThreadMilling.threadSetupInternal(
60
            obj, obj.StartDepth.Value, obj.FinalDepth.Value
61
        )
62
        self.assertEqual(cmd, c)
63
        self.assertEqual(zBegin, begin)
64
        self.assertEqual(zEnd, end)
65

66
    def assertSetupExternal(self, obj, c, begin, end):
67
        cmd, zBegin, zEnd = PathThreadMilling.threadSetupExternal(
68
            obj, obj.StartDepth.Value, obj.FinalDepth.Value
69
        )
70
        self.assertEqual(cmd, c)
71
        self.assertEqual(zBegin, begin)
72
        self.assertEqual(zEnd, end)
73

74
    def test00(self):
75
        """Verify internal radii."""
76
        self.assertRadii(PathThreadMilling.threadRadii(True, 20, 18, 2, 0), (8, 9.2))
77
        self.assertRadii(PathThreadMilling.threadRadii(True, 20, 19, 2, 0), (8.5, 9.1))
78

79
    def test01(self):
80
        """Verify internal radii with tool crest."""
81
        self.assertRadii(PathThreadMilling.threadRadii(True, 20, 18, 2, 0.1), (8, 9.113397))
82

83
    def test10(self):
84
        """Verify internal thread passes."""
85
        self.assertList(PathThreadMilling.threadPasses(1, radii, True, 10, 9, 0, 0), [10])
86
        self.assertList(PathThreadMilling.threadPasses(2, radii, True, 10, 9, 0, 0), [9.707107, 10])
87
        self.assertList(
88
            PathThreadMilling.threadPasses(5, radii, True, 10, 9, 0, 0),
89
            [9.447214, 9.632456, 9.774597, 9.894427, 10],
90
        )
91

92
    def test20(self):
93
        """Verify external radii."""
94
        self.assertRadii(PathThreadMilling.threadRadii(False, 20, 18, 2, 0), (11, 9.6))
95
        self.assertRadii(PathThreadMilling.threadRadii(False, 20, 19, 2, 0), (11, 10.3))
96

97
    def test21(self):
98
        """Verify external radii with tool crest."""
99
        self.assertRadii(PathThreadMilling.threadRadii(False, 20, 18, 2, 0.1), (11, 9.513397))
100

101
    def test30(self):
102
        """Verify external thread passes."""
103
        self.assertList(PathThreadMilling.threadPasses(1, radii, False, 10, 9, 0, 0), [9])
104
        self.assertList(PathThreadMilling.threadPasses(2, radii, False, 10, 9, 0, 0), [9.292893, 9])
105
        self.assertList(
106
            PathThreadMilling.threadPasses(5, radii, False, 10, 9, 0, 0),
107
            [9.552786, 9.367544, 9.225403, 9.105573, 9],
108
        )
109

110
    def test40(self):
111
        """Verify internal right hand thread setup."""
112

113
        hand = PathThreadMilling.RightHand
114

115
        self.assertSetupInternal(
116
            TestObject(hand, PathThreadMilling.DirectionConventional, 1, 0), "G2", 1, 0
117
        )
118
        self.assertSetupInternal(
119
            TestObject(hand, PathThreadMilling.DirectionClimb, 1, 0), "G3", 0, 1
120
        )
121

122
    def test41(self):
123
        """Verify internal left hand thread setup."""
124

125
        hand = PathThreadMilling.LeftHand
126

127
        self.assertSetupInternal(
128
            TestObject(hand, PathThreadMilling.DirectionConventional, 1, 0), "G2", 0, 1
129
        )
130
        self.assertSetupInternal(
131
            TestObject(hand, PathThreadMilling.DirectionClimb, 1, 0), "G3", 1, 0
132
        )
133

134
    def test50(self):
135
        """Verify exteranl right hand thread setup."""
136

137
        hand = PathThreadMilling.RightHand
138

139
        self.assertSetupExternal(
140
            TestObject(hand, PathThreadMilling.DirectionClimb, 1, 0), "G2", 1, 0
141
        )
142
        self.assertSetupExternal(
143
            TestObject(hand, PathThreadMilling.DirectionConventional, 1, 0), "G3", 0, 1
144
        )
145

146
    def test51(self):
147
        """Verify exteranl left hand thread setup."""
148

149
        hand = PathThreadMilling.LeftHand
150

151
        self.assertSetupExternal(
152
            TestObject(hand, PathThreadMilling.DirectionClimb, 1, 0), "G2", 0, 1
153
        )
154
        self.assertSetupExternal(
155
            TestObject(hand, PathThreadMilling.DirectionConventional, 1, 0), "G3", 1, 0
156
        )
157

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

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

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

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