Pages

Friday, January 4, 2013

Mcmaster springs and computer programming

Hi everyone,

I wanted to transfer over a post I made on Nerfhaven over to this blog because I thought it would be invaluable in designing spring-powered blasters around Mcmaster springs. Warning: things are about to get nerdy up in this bitch. This post deals with 4 of the most popular cut-to-length compression springs off of Mcmaster.com. If you are unfamiliar with Mcmaster.com, it is an American website that sells every part on the planet. I buy a ton of materials off of their website, including springs, PETG, pneumatic parts, adhesives, and more. Their spring collection is enormous, and there are many to choose from in many different styles--it can be a very large and daunting place at first The most common section for Nerf springs is the cut-to-length compression springs section. There are many attributes to springs, not limited to their free length, wire diameter, coils per inch, and rate constant. Many people don't have the intelligence or patience to try and understand completely the theory behind springs, so I have used my computer programming skills to put together a "cheat sheet" to be used in designing springers. I've always wondered how I could figure out an exact spring length to get me a desired spring load, and I've finally done it. Enjoy!

Here is some sample output for the K26 spring:

[ K26 ]
========================================
Deflection rate = 0.7528
Max load = 32.13 lbs (14.58 kg)
--------------------
length = 1 in
spring constant = 42.69 lbs/in
max draw = 0.75 in
--------------------
length = 2 in
spring constant = 21.34 lbs/in
max draw = 1.51 in
1 inch draw produces 21.34 lbs (9.68 kg) of force
--------------------
length = 3 in
spring constant = 14.23 lbs/in
max draw = 2.26 in
1 inch draw produces 14.23 lbs (6.45 kg) of force
2 inch draw produces 28.46 lbs (12.91 kg) of force
--------------------
length = 4 in
spring constant = 10.67 lbs/in
max draw = 3.01 in
1 inch draw produces 10.67 lbs (4.84 kg) of force
2 inch draw produces 21.34 lbs (9.68 kg) of force
3 inch draw produces 32.01 lbs (14.52 kg) of force
--------------------
length = 5 in
spring constant = 8.54 lbs/in
max draw = 3.76 in
1 inch draw produces 8.54 lbs (3.87 kg) of force
2 inch draw produces 17.07 lbs (7.74 kg) of force
3 inch draw produces 25.61 lbs (11.62 kg) of force
--------------------
length = 6 in
spring constant = 7.11 lbs/in
max draw = 4.52 in
1 inch draw produces 7.11 lbs (3.23 kg) of force
2 inch draw produces 14.23 lbs (6.45 kg) of force
3 inch draw produces 21.34 lbs (9.68 kg) of force
4 inch draw produces 28.46 lbs (12.91 kg) of force
--------------------
length = 7 in
spring constant = 6.10 lbs/in
max draw = 5.27 in
1 inch draw produces 6.10 lbs (2.77 kg) of force
2 inch draw produces 12.20 lbs (5.53 kg) of force
3 inch draw produces 18.29 lbs (8.30 kg) of force
4 inch draw produces 24.39 lbs (11.06 kg) of force
5 inch draw produces 30.49 lbs (13.83 kg) of force
--------------------
length = 8 in
spring constant = 5.34 lbs/in
max draw = 6.02 in
1 inch draw produces 5.34 lbs (2.42 kg) of force
2 inch draw produces 10.67 lbs (4.84 kg) of force
3 inch draw produces 16.01 lbs (7.26 kg) of force
4 inch draw produces 21.34 lbs (9.68 kg) of force
5 inch draw produces 26.68 lbs (12.10 kg) of force
6 inch draw produces 32.01 lbs (14.52 kg) of force
--------------------
length = 9 in
spring constant = 4.74 lbs/in
max draw = 6.78 in
1 inch draw produces 4.74 lbs (2.15 kg) of force
2 inch draw produces 9.49 lbs (4.30 kg) of force
3 inch draw produces 14.23 lbs (6.45 kg) of force
4 inch draw produces 18.97 lbs (8.61 kg) of force
5 inch draw produces 23.71 lbs (10.76 kg) of force
6 inch draw produces 28.46 lbs (12.91 kg) of force
--------------------
length = 10 in
spring constant = 4.27 lbs/in
max draw = 7.53 in
1 inch draw produces 4.27 lbs (1.94 kg) of force
2 inch draw produces 8.54 lbs (3.87 kg) of force
3 inch draw produces 12.81 lbs (5.81 kg) of force
4 inch draw produces 17.07 lbs (7.74 kg) of force
5 inch draw produces 21.34 lbs (9.68 kg) of force
6 inch draw produces 25.61 lbs (11.62 kg) of force
7 inch draw produces 29.88 lbs (13.55 kg) of force
--------------------
length = 11 in
spring constant = 3.88 lbs/in
max draw = 8.28 in
1 inch draw produces 3.88 lbs (1.76 kg) of force
2 inch draw produces 7.76 lbs (3.52 kg) of force
3 inch draw produces 11.64 lbs (5.28 kg) of force
4 inch draw produces 15.52 lbs (7.04 kg) of force
5 inch draw produces 19.40 lbs (8.80 kg) of force
6 inch draw produces 23.28 lbs (10.56 kg) of force
7 inch draw produces 27.16 lbs (12.32 kg) of force
8 inch draw produces 31.04 lbs (14.08 kg) of force
--------------------
30.00 lbs of force with a 3.00 inch draw requires a 4.27 inch spring

Pretty, ain't she? I wrote the program in Python (great language!) and I have included the source code below:


#!/usr/bin/env python
"""
spring.py

A simple spring class that shines light on the properties of
Mcmaster cut-to-length compression springs.
"""

__author__ = "Thomas Megantz a.k.a. T da B"

class Spring(object):
    def __init__(self, name, rate_constant, coils_per_inch,
                 max_length, wire_diameter):
        self.name = name
        self.rate_constant = rate_constant
        self.coils_per_inch = coils_per_inch
        self.max_length = max_length
        self.wire_diameter = wire_diameter
        self.deflection_rate = 1 - (self.coils_per_inch * self.wire_diameter)
        self.k = self.rate_constant / self.max_length
        self.max_load = self.deflection_rate * self.rate_constant

    def print_stats(self):
        print '[ {0} ]'.format(self.name)
        print '='*40
        print 'Deflection rate = ' + str(self.deflection_rate)
        print 'Max load = {0:.2f} lbs ({1:.2f} kg)'.format(self.max_load, self.max_load/2.20462)
        print '-'*20
        for length in range(self.max_length):
            print 'length = ' + str(length+1) + ' in'
            spring_constant = self.rate_constant/(length+1)
            print 'spring constant = {0:.2f} lbs/in'.format(spring_constant)
            max_draw = (length+1)*self.deflection_rate
            print 'max draw = {0:.2f} in'.format(max_draw)
            for draw in range(1, int(max_draw)+2):
                if draw <= max_draw:
                    print ('{0} inch draw produces {1:.2f} lbs ({2:.2f} kg) of '
                           'force').format(draw, draw*spring_constant, draw*spring_constant/2.20462)
            print "-" * 20

    def get_length_for_load(self, draw, desired_load):
        spring_constant = desired_load / draw
        length = self.rate_constant / spring_constant
        print ("{0:.2f} lbs of force with a {1:.2f} inch draw requires a "
               "{2:.2f} inch spring").format(desired_load, draw, length)

def print_spring_data():
    # Add any springs here
    k26 = Spring(name='K26', rate_constant=42.69, coils_per_inch=3.09, max_length=11, wire_diameter=.08)
    k25 = Spring(name='K25', rate_constant=38.53, coils_per_inch=2.18, max_length=11, wire_diameter=.08)
    k18 = Spring(name='K18', rate_constant=32.92, coils_per_inch=2.09, max_length=11, wire_diameter=.091)
    k15 = Spring(name='K15', rate_constant=67.98, coils_per_inch=4, max_length=11, wire_diameter=.105)
    k14 = Spring(name='K14', rate_constant=73.96, coils_per_inch=2.45, max_length=11, wire_diameter=.105)

    # Make sure to add any new springs into the list below
    springs = [k26, k25, k18, k15, k14]

    for spring in springs:
        spring.print_stats()
        spring.get_length_for_load(3, 30)
        print "=" * 40

if __name__ == '__main__':
    print_spring_data()


I have included output for 4 other springs as well. Adding new springs is as easy as creating a new 'Spring' object, adding it to the 'springs' list, and running the program. Enjoy!

[ K25 ]
========================================
Deflection rate = 0.8256
Max load = 31.81 lbs (14.43 kg)
--------------------
length = 1 in
spring constant = 38.53 lbs/in
max draw = 0.83 in
--------------------
length = 2 in
spring constant = 19.27 lbs/in
max draw = 1.65 in
1 inch draw produces 19.27 lbs (8.74 kg) of force
--------------------
length = 3 in
spring constant = 12.84 lbs/in
max draw = 2.48 in
1 inch draw produces 12.84 lbs (5.83 kg) of force
2 inch draw produces 25.69 lbs (11.65 kg) of force
--------------------
length = 4 in
spring constant = 9.63 lbs/in
max draw = 3.30 in
1 inch draw produces 9.63 lbs (4.37 kg) of force
2 inch draw produces 19.27 lbs (8.74 kg) of force
3 inch draw produces 28.90 lbs (13.11 kg) of force
--------------------
length = 5 in
spring constant = 7.71 lbs/in
max draw = 4.13 in
1 inch draw produces 7.71 lbs (3.50 kg) of force
2 inch draw produces 15.41 lbs (6.99 kg) of force
3 inch draw produces 23.12 lbs (10.49 kg) of force
4 inch draw produces 30.83 lbs (13.98 kg) of force
--------------------
length = 6 in
spring constant = 6.42 lbs/in
max draw = 4.95 in
1 inch draw produces 6.42 lbs (2.91 kg) of force
2 inch draw produces 12.84 lbs (5.83 kg) of force
3 inch draw produces 19.27 lbs (8.74 kg) of force
4 inch draw produces 25.69 lbs (11.65 kg) of force
--------------------
length = 7 in
spring constant = 5.50 lbs/in
max draw = 5.78 in
1 inch draw produces 5.50 lbs (2.50 kg) of force
2 inch draw produces 11.01 lbs (4.99 kg) of force
3 inch draw produces 16.51 lbs (7.49 kg) of force
4 inch draw produces 22.02 lbs (9.99 kg) of force
5 inch draw produces 27.52 lbs (12.48 kg) of force
--------------------
length = 8 in
spring constant = 4.82 lbs/in
max draw = 6.60 in
1 inch draw produces 4.82 lbs (2.18 kg) of force
2 inch draw produces 9.63 lbs (4.37 kg) of force
3 inch draw produces 14.45 lbs (6.55 kg) of force
4 inch draw produces 19.27 lbs (8.74 kg) of force
5 inch draw produces 24.08 lbs (10.92 kg) of force
6 inch draw produces 28.90 lbs (13.11 kg) of force
--------------------
length = 9 in
spring constant = 4.28 lbs/in
max draw = 7.43 in
1 inch draw produces 4.28 lbs (1.94 kg) of force
2 inch draw produces 8.56 lbs (3.88 kg) of force
3 inch draw produces 12.84 lbs (5.83 kg) of force
4 inch draw produces 17.13 lbs (7.77 kg) of force
5 inch draw produces 21.41 lbs (9.71 kg) of force
6 inch draw produces 25.69 lbs (11.65 kg) of force
7 inch draw produces 29.97 lbs (13.59 kg) of force
--------------------
length = 10 in
spring constant = 3.85 lbs/in
max draw = 8.26 in
1 inch draw produces 3.85 lbs (1.75 kg) of force
2 inch draw produces 7.71 lbs (3.50 kg) of force
3 inch draw produces 11.56 lbs (5.24 kg) of force
4 inch draw produces 15.41 lbs (6.99 kg) of force
5 inch draw produces 19.27 lbs (8.74 kg) of force
6 inch draw produces 23.12 lbs (10.49 kg) of force
7 inch draw produces 26.97 lbs (12.23 kg) of force
8 inch draw produces 30.83 lbs (13.98 kg) of force
--------------------
length = 11 in
spring constant = 3.50 lbs/in
max draw = 9.08 in
1 inch draw produces 3.50 lbs (1.59 kg) of force
2 inch draw produces 7.01 lbs (3.18 kg) of force
3 inch draw produces 10.51 lbs (4.77 kg) of force
4 inch draw produces 14.01 lbs (6.36 kg) of force
5 inch draw produces 17.51 lbs (7.94 kg) of force
6 inch draw produces 21.02 lbs (9.53 kg) of force
7 inch draw produces 24.52 lbs (11.12 kg) of force
8 inch draw produces 28.02 lbs (12.71 kg) of force
9 inch draw produces 31.53 lbs (14.30 kg) of force
--------------------
30.00 lbs of force with a 3.00 inch draw requires a 3.85 inch spring
========================================
[ K18 ]
========================================
Deflection rate = 0.80981
Max load = 26.66 lbs (12.09 kg)
--------------------
length = 1 in
spring constant = 32.92 lbs/in
max draw = 0.81 in
--------------------
length = 2 in
spring constant = 16.46 lbs/in
max draw = 1.62 in
1 inch draw produces 16.46 lbs (7.47 kg) of force
--------------------
length = 3 in
spring constant = 10.97 lbs/in
max draw = 2.43 in
1 inch draw produces 10.97 lbs (4.98 kg) of force
2 inch draw produces 21.95 lbs (9.95 kg) of force
--------------------
length = 4 in
spring constant = 8.23 lbs/in
max draw = 3.24 in
1 inch draw produces 8.23 lbs (3.73 kg) of force
2 inch draw produces 16.46 lbs (7.47 kg) of force
3 inch draw produces 24.69 lbs (11.20 kg) of force
--------------------
length = 5 in
spring constant = 6.58 lbs/in
max draw = 4.05 in
1 inch draw produces 6.58 lbs (2.99 kg) of force
2 inch draw produces 13.17 lbs (5.97 kg) of force
3 inch draw produces 19.75 lbs (8.96 kg) of force
4 inch draw produces 26.33 lbs (11.95 kg) of force
--------------------
length = 6 in
spring constant = 5.49 lbs/in
max draw = 4.86 in
1 inch draw produces 5.49 lbs (2.49 kg) of force
2 inch draw produces 10.97 lbs (4.98 kg) of force
3 inch draw produces 16.46 lbs (7.47 kg) of force
4 inch draw produces 21.95 lbs (9.95 kg) of force
--------------------
length = 7 in
spring constant = 4.70 lbs/in
max draw = 5.67 in
1 inch draw produces 4.70 lbs (2.13 kg) of force
2 inch draw produces 9.41 lbs (4.27 kg) of force
3 inch draw produces 14.11 lbs (6.40 kg) of force
4 inch draw produces 18.81 lbs (8.53 kg) of force
5 inch draw produces 23.51 lbs (10.67 kg) of force
--------------------
length = 8 in
spring constant = 4.11 lbs/in
max draw = 6.48 in
1 inch draw produces 4.11 lbs (1.87 kg) of force
2 inch draw produces 8.23 lbs (3.73 kg) of force
3 inch draw produces 12.34 lbs (5.60 kg) of force
4 inch draw produces 16.46 lbs (7.47 kg) of force
5 inch draw produces 20.57 lbs (9.33 kg) of force
6 inch draw produces 24.69 lbs (11.20 kg) of force
--------------------
length = 9 in
spring constant = 3.66 lbs/in
max draw = 7.29 in
1 inch draw produces 3.66 lbs (1.66 kg) of force
2 inch draw produces 7.32 lbs (3.32 kg) of force
3 inch draw produces 10.97 lbs (4.98 kg) of force
4 inch draw produces 14.63 lbs (6.64 kg) of force
5 inch draw produces 18.29 lbs (8.30 kg) of force
6 inch draw produces 21.95 lbs (9.95 kg) of force
7 inch draw produces 25.60 lbs (11.61 kg) of force
--------------------
length = 10 in
spring constant = 3.29 lbs/in
max draw = 8.10 in
1 inch draw produces 3.29 lbs (1.49 kg) of force
2 inch draw produces 6.58 lbs (2.99 kg) of force
3 inch draw produces 9.88 lbs (4.48 kg) of force
4 inch draw produces 13.17 lbs (5.97 kg) of force
5 inch draw produces 16.46 lbs (7.47 kg) of force
6 inch draw produces 19.75 lbs (8.96 kg) of force
7 inch draw produces 23.04 lbs (10.45 kg) of force
8 inch draw produces 26.33 lbs (11.95 kg) of force
--------------------
length = 11 in
spring constant = 2.99 lbs/in
max draw = 8.91 in
1 inch draw produces 2.99 lbs (1.36 kg) of force
2 inch draw produces 5.99 lbs (2.71 kg) of force
3 inch draw produces 8.98 lbs (4.07 kg) of force
4 inch draw produces 11.97 lbs (5.43 kg) of force
5 inch draw produces 14.96 lbs (6.79 kg) of force
6 inch draw produces 17.96 lbs (8.14 kg) of force
7 inch draw produces 20.95 lbs (9.50 kg) of force
8 inch draw produces 23.94 lbs (10.86 kg) of force
--------------------
30.00 lbs of force with a 3.00 inch draw requires a 3.29 inch spring
========================================
[ K15 ]
========================================
Deflection rate = 0.58
Max load = 39.43 lbs (17.88 kg)
--------------------
length = 1 in
spring constant = 67.97 lbs/in
max draw = 0.58 in
--------------------
length = 2 in
spring constant = 33.99 lbs/in
max draw = 1.16 in
1 inch draw produces 33.99 lbs (15.42 kg) of force
--------------------
length = 3 in
spring constant = 22.66 lbs/in
max draw = 1.74 in
1 inch draw produces 22.66 lbs (10.28 kg) of force
--------------------
length = 4 in
spring constant = 16.99 lbs/in
max draw = 2.32 in
1 inch draw produces 16.99 lbs (7.71 kg) of force
2 inch draw produces 33.99 lbs (15.42 kg) of force
--------------------
length = 5 in
spring constant = 13.59 lbs/in
max draw = 2.90 in
1 inch draw produces 13.59 lbs (6.17 kg) of force
2 inch draw produces 27.19 lbs (12.33 kg) of force
--------------------
length = 6 in
spring constant = 11.33 lbs/in
max draw = 3.48 in
1 inch draw produces 11.33 lbs (5.14 kg) of force
2 inch draw produces 22.66 lbs (10.28 kg) of force
3 inch draw produces 33.99 lbs (15.42 kg) of force
--------------------
length = 7 in
spring constant = 9.71 lbs/in
max draw = 4.06 in
1 inch draw produces 9.71 lbs (4.40 kg) of force
2 inch draw produces 19.42 lbs (8.81 kg) of force
3 inch draw produces 29.13 lbs (13.21 kg) of force
4 inch draw produces 38.84 lbs (17.62 kg) of force
--------------------
length = 8 in
spring constant = 8.50 lbs/in
max draw = 4.64 in
1 inch draw produces 8.50 lbs (3.85 kg) of force
2 inch draw produces 16.99 lbs (7.71 kg) of force
3 inch draw produces 25.49 lbs (11.56 kg) of force
4 inch draw produces 33.99 lbs (15.42 kg) of force
--------------------
length = 9 in
spring constant = 7.55 lbs/in
max draw = 5.22 in
1 inch draw produces 7.55 lbs (3.43 kg) of force
2 inch draw produces 15.11 lbs (6.85 kg) of force
3 inch draw produces 22.66 lbs (10.28 kg) of force
4 inch draw produces 30.21 lbs (13.70 kg) of force
5 inch draw produces 37.76 lbs (17.13 kg) of force
--------------------
length = 10 in
spring constant = 6.80 lbs/in
max draw = 5.80 in
1 inch draw produces 6.80 lbs (3.08 kg) of force
2 inch draw produces 13.59 lbs (6.17 kg) of force
3 inch draw produces 20.39 lbs (9.25 kg) of force
4 inch draw produces 27.19 lbs (12.33 kg) of force
5 inch draw produces 33.99 lbs (15.42 kg) of force
--------------------
length = 11 in
spring constant = 6.18 lbs/in
max draw = 6.38 in
1 inch draw produces 6.18 lbs (2.80 kg) of force
2 inch draw produces 12.36 lbs (5.61 kg) of force
3 inch draw produces 18.54 lbs (8.41 kg) of force
4 inch draw produces 24.72 lbs (11.21 kg) of force
5 inch draw produces 30.90 lbs (14.01 kg) of force
6 inch draw produces 37.08 lbs (16.82 kg) of force
--------------------
30.00 lbs of force with a 3.00 inch draw requires a 6.80 inch spring
========================================
[ K14 ]
========================================
Deflection rate = 0.74275
Max load = 54.93 lbs (24.92 kg)
--------------------
length = 1 in
spring constant = 73.96 lbs/in
max draw = 0.74 in
--------------------
length = 2 in
spring constant = 36.98 lbs/in
max draw = 1.49 in
1 inch draw produces 36.98 lbs (16.77 kg) of force
--------------------
length = 3 in
spring constant = 24.65 lbs/in
max draw = 2.23 in
1 inch draw produces 24.65 lbs (11.18 kg) of force
2 inch draw produces 49.31 lbs (22.36 kg) of force
--------------------
length = 4 in
spring constant = 18.49 lbs/in
max draw = 2.97 in
1 inch draw produces 18.49 lbs (8.39 kg) of force
2 inch draw produces 36.98 lbs (16.77 kg) of force
--------------------
length = 5 in
spring constant = 14.79 lbs/in
max draw = 3.71 in
1 inch draw produces 14.79 lbs (6.71 kg) of force
2 inch draw produces 29.58 lbs (13.42 kg) of force
3 inch draw produces 44.38 lbs (20.13 kg) of force
--------------------
length = 6 in
spring constant = 12.33 lbs/in
max draw = 4.46 in
1 inch draw produces 12.33 lbs (5.59 kg) of force
2 inch draw produces 24.65 lbs (11.18 kg) of force
3 inch draw produces 36.98 lbs (16.77 kg) of force
4 inch draw produces 49.31 lbs (22.36 kg) of force
--------------------
length = 7 in
spring constant = 10.57 lbs/in
max draw = 5.20 in
1 inch draw produces 10.57 lbs (4.79 kg) of force
2 inch draw produces 21.13 lbs (9.58 kg) of force
3 inch draw produces 31.70 lbs (14.38 kg) of force
4 inch draw produces 42.26 lbs (19.17 kg) of force
5 inch draw produces 52.83 lbs (23.96 kg) of force
--------------------
length = 8 in
spring constant = 9.24 lbs/in
max draw = 5.94 in
1 inch draw produces 9.24 lbs (4.19 kg) of force
2 inch draw produces 18.49 lbs (8.39 kg) of force
3 inch draw produces 27.73 lbs (12.58 kg) of force
4 inch draw produces 36.98 lbs (16.77 kg) of force
5 inch draw produces 46.22 lbs (20.97 kg) of force
--------------------
length = 9 in
spring constant = 8.22 lbs/in
max draw = 6.68 in
1 inch draw produces 8.22 lbs (3.73 kg) of force
2 inch draw produces 16.44 lbs (7.45 kg) of force
3 inch draw produces 24.65 lbs (11.18 kg) of force
4 inch draw produces 32.87 lbs (14.91 kg) of force
5 inch draw produces 41.09 lbs (18.64 kg) of force
6 inch draw produces 49.31 lbs (22.36 kg) of force
--------------------
length = 10 in
spring constant = 7.40 lbs/in
max draw = 7.43 in
1 inch draw produces 7.40 lbs (3.35 kg) of force
2 inch draw produces 14.79 lbs (6.71 kg) of force
3 inch draw produces 22.19 lbs (10.06 kg) of force
4 inch draw produces 29.58 lbs (13.42 kg) of force
5 inch draw produces 36.98 lbs (16.77 kg) of force
6 inch draw produces 44.38 lbs (20.13 kg) of force
7 inch draw produces 51.77 lbs (23.48 kg) of force
--------------------
length = 11 in
spring constant = 6.72 lbs/in
max draw = 8.17 in
1 inch draw produces 6.72 lbs (3.05 kg) of force
2 inch draw produces 13.45 lbs (6.10 kg) of force
3 inch draw produces 20.17 lbs (9.15 kg) of force
4 inch draw produces 26.89 lbs (12.20 kg) of force
5 inch draw produces 33.62 lbs (15.25 kg) of force
6 inch draw produces 40.34 lbs (18.30 kg) of force
7 inch draw produces 47.06 lbs (21.35 kg) of force
8 inch draw produces 53.79 lbs (24.40 kg) of force
--------------------
30.00 lbs of force with a 3.00 inch draw requires a 7.40 inch spring
========================================

Cheers,
~T da B

No comments:

Post a Comment