Date:2010-08-05 02:57:03 (13 years 7 months ago)
Author:Werner Almesberger
Commit:23b8aa0618e67514648aa715bd0b4be5ded99c85
Message:Initial commit. Just the HeeksPython script to generate the solids for now.

Files: cw.py (1 diff)

Change Details

cw.py
1#!/usr/bin/python
2
3import sys, math
4
5
6group = None
7g = 9.81 # gravitational acceleration, m/s2
8
9# density, g/cm3
10
11density = 11.34 # pure lead (Pb)
12density = 9.31 # Pb50Sn50
13density = 10.00 # Pb67Sn33
14#density = 7.28 # pure tin (Sn)
15
16#
17# The z coordinate of the plane limiting the top of the counterweight. This is
18# the altitude of the board surface minus the board clearance.
19#
20z_ceiling = 5.0 # mm
21
22#
23# The y coordinate of the axis around which our system rotates, i.e., the
24# position of the center of the rear feet
25#
26y_axis = 16.0
27
28total_mass = 0
29total_torque = 0
30
31
32#
33# solve a quadratic equation of the form a*x^2+b*x+c = 0
34#
35
36def qeq(a, b, c):
37    d = math.sqrt(b*b-4*a*c)
38    return ((-b-d)/2/a, (-b+d)/2/a)
39
40
41#
42# find the x-coordinate of the center of mass of a trapezoid/trapezium with the
43# four corners (0, 0), (x, 0), (0, y0), and (x, y0)
44# we assume the mass distribution to be uniform
45#
46
47def cm_trap_a(x, y0, y1):
48    if y0 == y1:
49    return x/2.0
50    f = float(y1-y0)/x/2
51    return qeq(2*f, 2.0*y0, -x*(y0+y1)/2.0)[1]
52
53
54#
55# calculate a rectangle's contribution to mass and torque
56#
57
58def rect_calc(x0, y0, z0, x1, y1, z1):
59    global total_mass, total_torque
60
61    # mass, in g
62    m = (x1-x0)*(y1-y0)*(z_ceiling-(z0+z1)/2.0)*density/1e3;
63
64    # center of mass on y axis, in y coordinates (mm)
65    y_center = y0+cm_trap_a(y1-y0, z_ceiling-z0, z_ceiling-z1)
66
67    # weight, in N
68    w = m*g/1000.0
69
70    # torque, in Nm
71    t = w*(y_center-y_axis)/1000.0
72
73    total_mass += m
74    total_torque += t
75
76#
77# gnuplot a rectangle
78#
79
80def rect_gnuplot(x0, y0, z0, x1, y1, z1):
81    print x0, y0, z0
82    print x1, y0, z0
83    print x1, y1, z1
84    print x0, y1, z1
85    print x0, y0, z0
86    print
87    print
88
89
90#
91# add a rectangle to the CAD model
92#
93
94def do_rect_cad(x0, y0, z0, x1, y1, z1):
95    cad.sketch()
96    sk = cad.getlastobj()
97
98    cad.line3d(x0, y0, z0, x1, y0, z0)
99    line = cad.getlastobj()
100    cad.add(sk, line)
101
102    cad.line3d(x1, y0, z0, x1, y1, z1)
103    line = cad.getlastobj()
104    cad.add(sk, line)
105
106    cad.line3d(x1, y1, z1, x0, y1, z1)
107    line = cad.getlastobj()
108    cad.add(sk, line)
109
110    cad.line3d(x0, y1, z1, x0, y0, z0)
111    line = cad.getlastobj()
112    cad.add(sk, line)
113
114    cad.reorder(sk)
115
116    return sk
117
118
119def rect_cad(x0, y0, z0, x1, y1, z1):
120    global group
121
122    sk = do_rect_cad(x0, y0, z0, x1, y1, z1)
123
124    cad.extrude(sk, 3)
125
126    if group is None:
127    group = cad.getlastobj()
128    else:
129    cad.fuse(group, cad.getlastobj())
130    group = cad.getlastobj()
131
132
133#
134# add a rectangle with the following corners:
135# (x0, y0, z0)
136# (x1, y0, z0)
137# (x0, y1, z1)
138# (x1, y1, z1)
139#
140
141def rect(x0, y0, z0, x1, y1, z1):
142    rect_calc(x0, y0, z0, x1, y1, z1)
143    do(x0, y0, z0, x1, y1, z1)
144
145
146#
147# make the base
148#
149
150def make_base():
151    rect(16, 46.0, 2.6, 22, 55, 2.6) # left lateral, bottom
152    rect(22, 46.0, 3.7, 24, 55, 3.7) # on pedestal
153    rect(89.5, 46.0, 2.6, 99.5, 55, 2.6) # right lateral, bottom
154    rect(88, 46.0, 3.7, 89.5, 55, 3.7) # on pedestal
155
156    rect(29.5, 50.5, 3.7, 36, 55, 3.7) # left podium, to beam
157    rect(38.5, 50.5, 3.7, 41, 55, 3.7) # after beam
158    rect(71, 50.5, 3.7, 82, 55, 3.7) # right podium
159
160    rect(16, 55, 2.6, 36, 59.5, 3.9) # middle bar, to 1st beam
161    rect(38.5, 55, 2.6, 46, 59.5, 3.9) # between beams
162    rect(48, 55, 2.6, 99.5, 59.5, 3.9) # right of 2nd beam
163
164    rect(36, 56, 3.9, 38.5, 59.5, 3.9) # cover the beams
165    rect(46, 56, 3.9, 48, 59.5, 3.9)
166
167    rect(15, 59.5, 3.9, 60.5, 64, 3.9) # end bar, left of beam
168    rect(62.5, 59.5, 3.9, 100, 64, 3.9) # right of beam
169
170    rect(15, 64, 3.9, 34, 69, 3.9) # left "ear"
171    rect(89.5, 64, 3.9, 100, 69, 3.9) # right "ear"
172
173    rect(34, 64, 3.9, 60.5, 65, 3.9) # extend inner area to sponge
174    rect(62.5, 64, 3.9, 82.5, 65, 3.9)
175
176
177if __name__ == "__main__":
178    do = rect_gnuplot
179else:
180    import HeeksPython as cad
181    do = rect_cad
182
183make_base()
184
185#if __name__ != "__main__":
186# sk = do_rect_cad(10, 40, z_ceiling, 110, 70, z_ceiling)
187# cad.extrude(sk, 3)
188# sk = cad.getlastobj()
189# cad.cut(group, sk)
190# group = cad.getlastobj()
191# cad.translate(group, -15, -69, -5)
192# cad.rotate(group, 0, 0, 0, 1, 0, 0, math.pi)
193
194#
195# add rectangular block for mold, then subtract the counterweight
196#
197
198if __name__ != "__main__":
199    cad.translate(group, -15, -46, -5)
200    cad.translate(group, 18, 5, 0)
201    sk = do_rect_cad(0, 0, 0, 120, 45, 0)
202    cad.extrude(sk, -10)
203    sk = cad.getlastobj()
204    cad.cut(sk, group)
205
206print >>sys.stderr, "total mass =", total_mass, "g"
207print >>sys.stderr, "total torque =", total_torque*1000.0, "mNm"

Archive Download the corresponding diff file

Branches:
master



interactive