From 1702234db636c72b812e5519a683de1e28998f07 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 31 Oct 2010 23:59:35 -0300 Subject: [PATCH] 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 --- cntr/cam/Makefile | 9 ++++ cntr/cam/doit | 24 ++++++++++ cntr/cam/pcb.pl | 120 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 cntr/cam/Makefile create mode 100755 cntr/cam/doit create mode 100755 cntr/cam/pcb.pl diff --git a/cntr/cam/Makefile b/cntr/cam/Makefile new file mode 100644 index 0000000..6e3863f --- /dev/null +++ b/cntr/cam/Makefile @@ -0,0 +1,9 @@ +DIR=/home/moko/svn.openmoko.org/developers/werner/cncmap + +.PHONY: pcb spool + +pcb: + ./doit >job + +spool: + PORT=/dev/ttyUSB0 $(DIR)/spool/spool job diff --git a/cntr/cam/doit b/cntr/cam/doit new file mode 100755 index 0000000..1db4700 --- /dev/null +++ b/cntr/cam/doit @@ -0,0 +1,24 @@ +#!/bin/sh -e +DIR=/home/moko/svn.openmoko.org/developers/werner/cncmap +RECT=$DIR/rect/rect +ALIGN=$DIR/align/align +ZMAP=$DIR/zmap/zmap +GP2RML=$DIR/gp2rml/gp2rml + +GEN=${1:-./pcb.pl} + +rdata="19.6 13.0 -56.2 19.6 53.1 -56.1 110.7 14.1 -56.2" +rdate="15.9 13.1 -57.2 15.9 77.4 -57.1 120.8 15.1 -57.0" +# lower Z by 0.5 mm relative to highest point +Z=-57.5 + +rect=`$RECT $rdata | awk '{$3 = ""; print}'` + +$GEN | + awk '{ if ($3 != "") $3 += '$Z'; print $0; }' | + $ALIGN 0 1 $rect | + # angle, reference (lower left corner), rect + $GP2RML 2 0.5 0.5 + # clearance, xy speed, z speed +# since everything is in the same plane, z clearance must be thickness plus +# real clearance ! diff --git a/cntr/cam/pcb.pl b/cntr/cam/pcb.pl new file mode 100755 index 0000000..a0745bc --- /dev/null +++ b/cntr/cam/pcb.pl @@ -0,0 +1,120 @@ +#!/usr/bin/perl + +$d = 25.4/1000*35; +$r = $d/2-0.1; # compensate deflection of board +$steps = 24; + + +sub orig +{ + $x0 = $_[0]; + $y0 = $_[1]; +} + + +sub mil +{ + return $_[0]/1000*25.4; +} + + +sub cut +{ + if (defined $x) { + if ($x == $_[0]+$x0 && $y == $_[1]+$y0) { + shift @_; + shift @_; + } else { + print "\n"; + } + } + while (@_) { + $x = shift @_; + $y = shift @_; +# ($x, $y) = (-$y, $x); + $x += $x0; + $y += $y0; + print "$x $y $z\n"; + } +} + + +# 0 is at "noon", rotating counter-clockwise + +sub arc +{ + local ($xc, $yc, $d, $a0, $a1) = @_; + local ($rr) = $d/2-$r; + local $n = int(abs($a1-$a0)/360*$steps+0.5); + + $rr = 0 if $rr < 0; + for ($i = 0; $i <= $n; $i++) { + my $a = ($a0+($a1-$a0)/$n*$i)*3.1415926/180; + $x = $x0+$xc-$rr*sin($a); + $y = $y0+$yc+$rr*cos($a); + print "$x $y $z\n"; + } +} + + +sub circ +{ + local ($xc, $yc, $d) = @_; + + print "\n"; + &arc($xc, $yc, $d, 0, 360); + &circ($xc, $yc, $d-$r*2) if $d > $r*2; +} + + +sub hhole +{ + local ($xc0, $xc1, $yc, $d) = @_; + local ($rr) = $d/2-$r; + + &cut($xc0, $yc+$rr, $xc1, $yc+$rr); + &arc($xc1, $yc, $d, 0, -180); + &cut($xc1, $yc-$rr, $xc0, $yc-$rr); + &arc($xc0, $yc, $d, 180, 0); +} + + +sub pcb +{ + &cut( + &mil( 0)-$r, &mil( 0)-$r, + &mil(1180)+$r, &mil( 0)-$r, + &mil(1180)+$r, &mil( 240)+$r, + &mil(1000)+$r, &mil( 240)+$r, + &mil(1000)+$r, &mil( 380)-$r, + &mil(1180)+$r, &mil( 380)-$r, + &mil(1180)+$r, &mil( 620)+$r, + &mil( 0)-$r, &mil( 620)+$r, + &mil( 0)-$r, &mil( 0)-$r); +} + + +sub holes +{ + # x-x0, y0-y, diameter + &circ(&mil(3130-3020), &mil(3520-3122), &mil(43)); + &circ(&mil(3130-3020), &mil(3520-3298), &mil(43)); + + &hhole(&mil(3100-3020), &mil(3159-3020), &mil(3520-2986), &mil(39)); + &hhole(&mil(3100-3020), &mil(3159-3020), &mil(3520-3434), &mil(39)); +} + + + + +$z = -0.8; # full thickness of board +# x: corner offset, compensation for rotation, array position +# y: corner offet + +&orig(35*0, 45); + +$r = $d/2; # no compensation. don't wanna risk making holes too big. +&holes; + +$r = $d/2-0.1; # compensate deflection of board +&pcb;