1
0
mirror of git://projects.qi-hardware.com/ben-counterweight.git synced 2024-11-28 09:03:09 +02:00
ben-counterweight/cvr.py
2010-08-05 23:42:08 -03:00

137 lines
2.9 KiB
Python
Executable File

#!/usr/bin/python
#
# gnuplot the outline
#
def outline_gnuplot(points):
while len(points):
print points.pop(0), points.pop(0)
print
#
# make a HeeksCAD sketch of the outline
#
def cad_line(sk, x0, y0, x1, y1):
cad.line(x0, y0, x1, y1)
cad.add(sk, cad.getlastobj())
def outline_cad(points):
cad.sketch()
sk = cad.getlastobj()
last_x = points.pop(0)
last_y = points.pop(0)
while len(points):
x = points.pop(0)
y = points.pop(0)
cad_line(sk, last_x, last_y, x, y)
last_x = x
last_y = y
cad.reorder(sk)
return sk
def closed_outline(*args):
l = list(args)
l.append(args[0])
l.append(args[1])
do(l)
def open_outline(*args):
do(list(args))
#
# Make the cover sheet 2 mm larger than the counterweight on all sides. We need
# the following exceptions to avoid mechanical interference:
#
# - at the power connector, keep the ymin edge flush with the counterweight
# - follow the counterweight's J-shaped space for the reset button, with the
# border reduced from 2 mm to 0.5 mm
# - next to the long side of the battery, follow the counterweight's edge
# - also follow the counterweight's bay for the battery cover's tongue and
# make it even 0.5 mm larger, anticipating imperfect registration
#
# Also, as a simplification, we don't follow steps and recesses in these cases:
#
# - 1 mm steps on the left and right side. Just use the larger size.
# - the whole sponge area. Just put the cover on top of the sponge.
# - all recesses near the batter, except the one for the lid's central tongue
#
# The above simplifications are possible, because, being on top of the
# counterweight, we've already cleared the obstacles these steps and recesses
# are designed to avoid.
#
#
# Note: to visualize the shape defined below, plot the counterweight in 2D with
# gnuplot and follow the shape it the mouse.
#
# To visualize the result, do this:
#
# ./cw.py >cw.gnuplot
# ./cvr.py >cvr.gnuplot
# gnuplot
# gnuplot> set style data lines
# gnuplot> plot "cw.gnuplot", "cvr.gnuplot"
#
def outline():
closed_outline(
# counterweight corners: (16, 46) and (15, 60)
13, 46,
# (15, 69.5)
13, 71.5,
# (82.5, 65), (82.5, 64), (89.5, 64), (89.5, 69)
83, 71.5,
83, 64.5, 89, 64.5, 89, 71,
# (100, 69)
102, 71,
# (99.5, 46)
102, 44,
# (88, 46)
86, 44,
# (88, 55), (82, 50)
86, 50,
# (59.5, 55), (59.5, 56.5), (52.5, 56.5), (52.5, 55)
60, 50,
60, 57, 52, 57, 52, 50,
# (24, 55)
26, 50,
# (24, 46)
26, 46)
def label():
# C
open_outline(
25+5, 55+10,
25, 55+10,
25, 55,
25+5, 55)
# W
open_outline(
33, 55+10,
33, 55,
33+2.5, 55+5,
33+5, 55,
33+5, 55+10)
if __name__ == "__main__":
do = outline_gnuplot
else:
import HeeksPython as cad
do = outline_cad
outline()
label()