summaryrefslogtreecommitdiff
path: root/screw.py
blob: cc39d1a3abb60f2b963a1d163ee0528c70a5f9b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import skdb
from skdb import Part, Interface, Unit, UnitError
from string import Template

threads = skdb.load_package('threads')
Thread = threads.Thread

__author__ = "ben lipkowitz, bryan bishop"
__license__ = "GPL"
__version__ = "0.0.1"
__maintainer__ = "ben lipkowitz"
__email__ = 'no thank you, sir'
__status__ = "Development"

class Screw(Part):
    yaml_tag = "!screw"
    '''a screw by itself isn't a fastener, it needs a nut of some sort'''
    ##i suppose this stuff should go in a screws.yaml file or something, along with standard diameters
    proof_load = {#grade:load
        '1':'33ksi',
        '2':'55ksi',
        '3':'85ksi',
        '5':'85ksi',
        '7':'105ksi',
        '8':'120ksi',
        }
    tensile_strength = {#grade:load
        '1':'60ksi',
        '2':'74ksi',
        '3':'110ksi',
        '5':'120ksi',
        '7':'133ksi',
        '8':'150ksi',
        }
    def __init__(self, thread=None, length=None, grade="2", name=None):
        '''length is defined as the distance from bottom of the head for all screws but 
        flat head and set screws which use the top of the head instead'''
        #thread.__init__()
        self.thread, self.length, self.grade, self.name = thread, length, grade, name
        if self.thread and self.length:
            if self.thread.length is None: self.thread.length = self.length
            assert self.length.compatible('m')  #this sort of thing should go in a generic unit-checker function
        #is it right to define these interfaces here, instead of in the thread object?
        thread_loosen = Interface("thread-loosen", part=self)
        thread_tighten = Interface("thread-tighten", part=self)
        compression_face = Interface("compression-face", part=self)
        torque_spline = Interface("torque-spline", part=self)
        if thread == None: raise ValueError
        #the following if should be commented out when skdb/core/threads.py Thread interfaces is fixed
        #if thread.interfaces == None or len(thread.interfaces) == 0:
        thread.interfaces = [thread_loosen, thread_tighten]
        if len(thread.interfaces) > 0:
            #if the thread already has interfaces with name "thread_loosen"/"thread_tighten", use them.
            thread_loosen = thread.interfaces[0] #FIXME: this is very, very wrong
            thread_tigthen = thread.interfaces[1] #FIXME too.
        self.interfaces = [thread_loosen, thread_tighten, compression_face, torque_spline]
        self.check_compatibility()

    def check_compatibility(self):
        #shouldnt this function be in thread.py?
        for (k,v) in {'pitch': 'rev/in', 'diameter': 'in', 'tensile_area': 'in^2'}.items():
            parameter = getattr(self.thread, k)
            try:
                Unit(parameter)
                assert (getattr(self.thread, k)).compatible(v)
            except UnitError, e:
                #ok it's not a Unit object
                #and instead a method in the Thread class
                res = parameter()
                assert res.compatible(v)
        #note these tables vary from source to source; might want to check if it really matters to you
        
    def max_force(self):
        '''load screw can withstand without permanent set, in lbf'''
        s = Template('$area*$strength')
        string = s.safe_substitute(area=self.thread.tensile_area(), strength=Screw.proof_load[self.grade])
        return skdb.Unit(string).to('lbf') 
  
    def breaking_force(self):
        '''load screw can withstand without breaking, in lbf'''
        s = Template('$area*$strength')
        string = s.safe_substitute(area=self.thread.tensile_area(), strength=Screw.tensile_strength[self.grade])
        return skdb.Unit(string).to('lbf')