Date:2010-11-01 03:59:35 (8 years 10 months ago)
Author:Werner Almesberger
Commit:1702234db636c72b812e5519a683de1e28998f07
Message:cntr/cam/: added PCB-cutting process

- cam/Makefile (pcb, spool): generate the job and spool it to the mill
- cam/doit: coordinate transform and format conversions
- cam/pcb.pl: PCB outline and holes
Files: cntr/cam/Makefile (1 diff)
cntr/cam/doit (1 diff)
cntr/cam/pcb.pl (1 diff)

Change Details

cntr/cam/Makefile
1DIR=/home/moko/svn.openmoko.org/developers/werner/cncmap
2
3.PHONY: pcb spool
4
5pcb:
6        ./doit >job
7
8spool:
9        PORT=/dev/ttyUSB0 $(DIR)/spool/spool job
cntr/cam/doit
1#!/bin/sh -e
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
7
8GEN=${1:-./pcb.pl}
9
10rdata="19.6 13.0 -56.2 19.6 53.1 -56.1 110.7 14.1 -56.2"
11rdate="15.9 13.1 -57.2 15.9 77.4 -57.1 120.8 15.1 -57.0"
12# lower Z by 0.5 mm relative to highest point
13Z=-57.5
14
15rect=`$RECT $rdata | awk '{$3 = ""; print}'`
16
17$GEN |
18  awk '{ if ($3 != "") $3 += '$Z'; print $0; }' |
19  $ALIGN 0 1 $rect |
20    # angle, reference (lower left corner), rect
21  $GP2RML 2 0.5 0.5
22    # clearance, xy speed, z speed
23# since everything is in the same plane, z clearance must be thickness plus
24# real clearance !
cntr/cam/pcb.pl
1#!/usr/bin/perl
2
3$d = 25.4/1000*35;
4$r = $d/2-0.1; # compensate deflection of board
5$steps = 24;
6
7
8sub orig
9{
10    $x0 = $_[0];
11    $y0 = $_[1];
12}
13
14
15sub mil
16{
17    return $_[0]/1000*25.4;
18}
19
20
21sub cut
22{
23    if (defined $x) {
24    if ($x == $_[0]+$x0 && $y == $_[1]+$y0) {
25        shift @_;
26        shift @_;
27    } else {
28        print "\n";
29    }
30    }
31    while (@_) {
32    $x = shift @_;
33    $y = shift @_;
34# ($x, $y) = (-$y, $x);
35    $x += $x0;
36    $y += $y0;
37    print "$x $y $z\n";
38    }
39}
40
41
42# 0 is at "noon", rotating counter-clockwise
43
44sub arc
45{
46    local ($xc, $yc, $d, $a0, $a1) = @_;
47    local ($rr) = $d/2-$r;
48    local $n = int(abs($a1-$a0)/360*$steps+0.5);
49
50    $rr = 0 if $rr < 0;
51    for ($i = 0; $i <= $n; $i++) {
52    my $a = ($a0+($a1-$a0)/$n*$i)*3.1415926/180;
53    $x = $x0+$xc-$rr*sin($a);
54    $y = $y0+$yc+$rr*cos($a);
55    print "$x $y $z\n";
56    }
57}
58
59
60sub circ
61{
62    local ($xc, $yc, $d) = @_;
63
64    print "\n";
65    &arc($xc, $yc, $d, 0, 360);
66    &circ($xc, $yc, $d-$r*2) if $d > $r*2;
67}
68
69
70sub hhole
71{
72    local ($xc0, $xc1, $yc, $d) = @_;
73    local ($rr) = $d/2-$r;
74
75    &cut($xc0, $yc+$rr, $xc1, $yc+$rr);
76    &arc($xc1, $yc, $d, 0, -180);
77    &cut($xc1, $yc-$rr, $xc0, $yc-$rr);
78    &arc($xc0, $yc, $d, 180, 0);
79}
80
81
82sub pcb
83{
84    &cut(
85      &mil( 0)-$r, &mil( 0)-$r,
86      &mil(1180)+$r, &mil( 0)-$r,
87      &mil(1180)+$r, &mil( 240)+$r,
88      &mil(1000)+$r, &mil( 240)+$r,
89      &mil(1000)+$r, &mil( 380)-$r,
90      &mil(1180)+$r, &mil( 380)-$r,
91      &mil(1180)+$r, &mil( 620)+$r,
92      &mil( 0)-$r, &mil( 620)+$r,
93      &mil( 0)-$r, &mil( 0)-$r);
94}
95
96
97sub holes
98{
99    # x-x0, y0-y, diameter
100    &circ(&mil(3130-3020), &mil(3520-3122), &mil(43));
101    &circ(&mil(3130-3020), &mil(3520-3298), &mil(43));
102
103    &hhole(&mil(3100-3020), &mil(3159-3020), &mil(3520-2986), &mil(39));
104    &hhole(&mil(3100-3020), &mil(3159-3020), &mil(3520-3434), &mil(39));
105}
106
107
108
109
110$z = -0.8; # full thickness of board
111# x: corner offset, compensation for rotation, array position
112# y: corner offet
113
114&orig(35*0, 45);
115
116$r = $d/2; # no compensation. don't wanna risk making holes too big.
117&holes;
118
119$r = $d/2-0.1; # compensate deflection of board
120&pcb;

Archive Download the corresponding diff file



interactive