Date:2010-11-28 00:17:25 (7 years 2 months ago)
Author:Werner Almesberger
Commit:1d72af733eb0e1505a0dcc5755a438c5a30d28f5
Message:vialtray: make a tray for vials containing 0402/0603 components (in progress)

This doesn't work yet. In particular, going through "cameo" doesn't seem
the most convenient choice, since "cameo" requires paths to be closed,
which is something the paths we use here aren't. (Conceptually, thet are
closed, but the implementation skips some small segments.)

This commit is just a snapshot before I experiment with changing the
algorithm.
Files: vialtray/README (1 diff)
vialtray/doit (1 diff)
vialtray/tray.pl (1 diff)

Change Details

vialtray/README
1vial tray: small lab vials are an excellent place to store 0402 and 0603
2components. The problem is how to store a large number of vials efficiently
3and in some order. This project is about milling openings for vials into a
4piece of wood.
vialtray/doit
1#!/bin/sh
2DIR=/home/moko/svn.openmoko.org/developers/werner/cncmap
3RECT=$DIR/rect/rect
4ALIGN=$DIR/align/align
5ZMAP=$DIR/zmap/zmap
6GP2RML=$DIR/gp2rml/gp2rml
7CAMEO=../../../cae-tools/cameo/cameo
8
9GEN=${1:-./pcb.pl}
10
11# manual tool positioning !!
12rdate="0 0 0 150 0 0 0 100 0"
13# lower Z by 0.5 mm relative to highest point (-56.8)
14Z=0
15
16rect=`$RECT $rdata | awk '{$3 = ""; print}'`
17
18# cameo: we inline the tool diameter with the data
19
20$GEN |
21  awk '{ if ($3 != "") $3 += '$Z'; print $0; }' |
22  $CAMEO -d 0 |
23  $ALIGN 0 1 $rect |
24        # angle, reference (lower left corner), rect
25  $GP2RML 20 2 2
26        # clearance, xy speed, z speed
27# since everything is in the same plane, z clearance must be thickness plus
28# real clearance !
vialtray/tray.pl
1#!/usr/bin/perl
2
3use POSIX;
4
5
6$PI = atan2(1, 1)*4;
7$epsilon = 0.02;
8
9$d = 25.4/8; # 1/8"
10$r = $d/2;
11
12
13sub orig
14{
15    $x0 = $_[0];
16    $y0 = $_[1];
17}
18
19
20sub mil
21{
22    return $_[0]/1000*25.4;
23}
24
25
26sub cut
27{
28    if (defined $x) {
29    if ($x == $_[0]+$x0 && $y == $_[1]+$y0) {
30        shift @_;
31        shift @_;
32    } else {
33        print "\n";
34    }
35    }
36    while (@_) {
37    $x = shift @_;
38    $y = shift @_;
39    $x += $x0;
40    $y += $y0;
41    print "$x $y $z\n";
42    }
43}
44
45
46sub mm
47{
48    local ($x, $y, @m) = @_;
49
50    return ($x*$m[0]+$y*$m[1], $x*$m[2]+$y*$m[3]);
51}
52
53
54sub a2m
55{
56    local ($a) = $_[0]/180*$PI;
57
58    return (cos($a), sin($a), -sin($a), cos($a));
59}
60
61
62sub yarc
63{
64    local ($x, $y, $dx, $dy0, $dy1, $r, @m) = @_;
65    local ($dy);
66
67    $dx = ($dx > 0 ? 1 : -1)*sqrt($r*$r-$dy0*$dy0+$epsilon);
68    $dy = $dy0;
69
70    while (1) {
71        if ($dy0 < $dy1) {
72            last if $dy >= $dy1-$epsilon;
73        } else {
74            last if $dy <= $dy1+$epsilon;
75        }
76        print $x+$dx, " ", $y+$dy, " ", $z, "\n";
77        ($dx, $dy) = &mm($dx, $dy, @m);
78    }
79}
80
81
82sub circ
83{
84    local ($x, $y, $r, $n) = @_;
85    local ($a, $dx, $dy);
86
87    for ($a = 0; $a <= 2*$PI+$epsilon; $a += 2*$PI/$n) {
88        $dx = $r*sin($a);
89        $dy = $r*cos($a);
90        print $x+$dx, " ", $y+$dy, " ", $z, "\n";
91    }
92}
93
94
95#
96# general shape:
97#
98# <------ 150 ------>
99# +-------------------+
100# | | ^
101# | () () () () () () | |
102# | () () () () () () | | 90
103# | () () () () () () | |
104# | () () () () () () | |
105# | | v
106# +-------------------+
107#
108
109
110# start depth
111$z0 = -0.5;
112
113# floor depth
114$zf = -15;
115
116# maximum depth step
117$zs = 2;
118
119# distance between columns
120$xs = 24;
121
122# distance between vial centers within columns
123$ys = 20;
124
125# vial diameter
126$vd = 18.6;
127
128# minimum wall thickness
129$mw = 2;
130
131$nc = 6;
132$nr = 4;
133
134
135@m_cw = &a2m(1);
136@m_ccw = &a2m(-1);
137
138# vial hole radius
139$vr = $vd/2;
140
141# circle radii: first, last, increment
142$r0 = $r/2;
143$r1 = $vr-$r*0.75;
144$rs = $r*0.75;
145
146#
147# x offset at which the vial bay stops
148#
149
150$t = $ys/2-$mw/2;
151$xo = sqrt($vr*$vr-$t*$t);
152
153#
154# radius of the arcs connecting vial bays
155#
156$br = $vr*($mw/2)/$t;
157
158# x offset of the center of the arcs connecting vial bays
159#
160#$bx = $xo+sqrt($br*$br-($mw/2)*($mw/2));
161$bx = $xo+$xo*($mw/2)/$vr;
162
163print STDERR "t = $t\n";
164print STDERR "xo = $xo\n";
165print STDERR "br = $br\n";
166print STDERR "bx = $bx\n";
167
168# adjust the z step
169
170$nz = POSIX::ceil(($z0-$zf)/$zs);
171$zs = ($z0-$zf)/$nz;
172
173print STDERR "nz = $nz\n";
174print STDERR "zs = $zs\n";
175
176print STDERR "r0 = $r0\n";
177print STDERR "r1 = $r1\n";
178print STDERR "rs = $rs\n";
179
180
181sub do_col
182{
183    local ($x0) = @_;
184    local ($rw, $end);
185
186    for ($rw = 0; $rw != $nr; $rw++) {
187        if ($rw) {
188            $end = $rw == $nr-1 ? $vr : ($ys-$mw)/2;
189            &yarc($x0-$bx, $y0-$ys/2,
190                1, -$mw/2, $mw/2, $br, @m_ccw);
191            &yarc($x0, $y0,
192                -1, -($ys-$mw)/2, $end, $vr, @m_cw);
193        } else {
194            &yarc($x0, $y0,
195                1, -$vr, ($ys-$mw)/2, $vr, @m_cw);
196        }
197        $y0 += $ys;
198    }
199    for ($rw = 0; $rw != $nr; $rw++) {
200        $y0 -= $ys;
201        if ($rw) {
202            $end = $rw == $nr-1 ? $vr : ($ys-$mw)/2;
203            &yarc($x0+$bx, $y0+$ys/2,
204                -1, $mw/2, -$mw/2, $br, @m_ccw);
205            &yarc($x0, $y0,
206                1, ($ys-$mw)/2, -$end, $vr, @m_cw);
207        } else {
208            &yarc($x0, $y0,
209                1, $vr, -($ys-$mw)/2, $vr, @m_cw);
210        }
211    }
212}
213
214
215sub do_cols
216{
217    local ($c, $x);
218
219    $x = $x0;
220    for ($c = 0; $c != $nc; $c++) {
221        &do_col($x);
222        $x += $xs;
223        print "\n";
224    }
225}
226
227
228sub do_circles
229{
230    local ($c, $rw, $x, $y);
231    local ($rr);
232
233    $x = $x0;
234    for ($c = 0; $c != $nc; $c++) {
235        $y = $y0;
236        for ($rw = 0; $rw != $nr; $rw++) {
237            for ($rr = $r0; $rr <= $r1; $rr += $rs) {
238                &circ($x, $y, $rr, 180);
239            }
240            $y += $ys;
241        }
242        $x += $xs;
243        print "\n";
244    }
245}
246
247
248($x0, $y0) = (5+$ys/2, 5+$ys/2);
249
250$z = $z0;
251for ($i = 0; $i != $nz; $i++) {
252    print "#%%r_tool=", $r, "\n";
253    &do_cols;
254
255    print "#%%r_tool=0\n";
256    &do_circles;
257    $z -= $zs;
258}

Archive Download the corresponding diff file

Branches:
master



interactive