-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathlaser-cut-case.ps
2129 lines (1810 loc) · 58.8 KB
/
laser-cut-case.ps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%!PS-Adobe-3.0
%%BoundingBox: 0 0 800 3100
% Bounding box widths for comparison with real-world acrylic
% 850 for 30 cm wide material
% 867 for 12" wide material
%
% (c) 2017 Henner Zeller <[email protected]>
%
% This file is part of LDGraphy http://github.com/hzeller/ldgraphy
%
% LDGraphy is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% LDGraphy is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with LDGraphy. If not, see <http://www.gnu.org/licenses/>.
% Choices what to selectively cut. From bottom up.
% Use black or dark red transparent for all of these except the sled.
/print-bottom true def % Bottom pane, holding drive-train
/print-bottom-drivetrain true def % motor holder and bearing
/print-slide-rail-bottom true def % The rails the sled is riding on.
/print-sled true def % The sled moving the PCB along.
/print-slide-rail-top true def % The rails the sled is riding under.
/print-sidepanels true def % Side panels framing of the outer case.
/print-front-back true def % Front and back parts of the case.
/print-toppanel true def % The laser and rotating mirror mounted here.
/print-lid true def % Lid covering everything.
/print-pcbframe true def % frame around sled.
% Show measurement lines and descriptions. Switch these off before generating
% the DXF to save acrylic material (there are more gaps for the measurements)
/print-measures false def
% For testing while tweaking finger/slot output on your laser cutter.
% Typical tweak parameters are /acrylic-t, /do-reliefs, /relief-r, /slot-thick
/print-TEST-finger-slot false def
/print-TEST-x-spring false def
/mm { 72 25.4 div mul } bind def
% some basic functions
/max { 1 index 1 index lt { exch pop } { pop } ifelse } bind def
/tan { dup sin exch cos div } bind def
% User modifiable parameters.
/acrylic-t 3 mm def % Material thickness.
/pcb-w-mm 100 def % Size of PCB
/pcb-h-mm 160 def
% The scan angle we are covering. One one hand, we want to have this
% pretty small to minimize the focus lenght difference. But we also don't
% want to have it too small, as this means we have lower on-time hence longer
% exposure time. Maximum: 120. Typical near 40 degree.
/scan-angle 40 def % Something < 120, better less than 60
/scan-redirect-mirror-distance 60 mm def % Mirror distance
/scan-redirect-mirror-base 30 mm def % Width of the mirror foot.
/scan-redirect-mirror-width 15 mm def % Width redirect mirror itself.
% temporary while hacking on prototype to see influence of different angles.
/do-angle-test false def
% reliefs on inner edges for finger/slots.
/do-reliefs true def
/relief-r 0.18 mm def
/slot-thick acrylic-t def % slot thickness for snug fit.
/screw-r 3.1 mm 2 div def
/rod-r 4.7 mm 2 div def
/finger-len 20 mm def
/connect-screw-len 4.5 mm def
/pcb-w pcb-w-mm mm 2 mm add def
/pcb-h pcb-h-mm mm 2 mm add def
/bed-w pcb-w acrylic-t 2 mul add 10 mm add def % rail + 5 mm extra on each edge
/bed-h pcb-h 10 mm add def
% derived from above.
/bed-pcb-off-w bed-w pcb-w sub 2 div def
/bed-pcb-off-h bed-h pcb-h sub 2 div def
/bed-slide-high-bottom 29 mm def
/bed-slide-high-top 8 mm def
/slide-hole-count 4 def
% how high the front part should be. Essentially it should end shy below
% where the bed tray emerges.
/front-cover-high bed-slide-high-bottom 1 mm sub def
/drive-train-fingers 11 mm def % finger distance for drive train on sled
/stepper-len 36 mm def
/stepper-height 28.2 mm def % nema11
/stepper-mount-screw 11.5 mm def % screw distance measured from center
/stepper-screw-dia 2.5 mm def % M2.5 for nema11
/stepper-center-plate-dia 22.5 mm def
/acme-dia 5 mm def % acme screw diameter
/drive-mount-pos stepper-len def % stepper mount position seen from back
/drive-screw-start 35 mm 10 mm max def % axle to where acme screw starts. Coupler
/bearing-mount-pos
stepper-len drive-screw-start add % starting from here
pcb-h add % .. the amount we need to move
acrylic-t 1.5 mul add % space for drive-train holder
8 mm add % Provide a little more room
def % acme bearing
% the corresponding assembly on the sled
/bed-drive-screw-w acrylic-t def % distance between driving holders
% outer radius of hex-nut driving the thing. Since it is easier to measure, we
% base it on the distance between two oppsing flat ends.
/bed-drive-screw-r 9.33 mm 0.866 div 2 div def
/bed-drive-wobble 0.5 mm def % amount of 'wobble' we should give the drive screw
% TODO: the following foremost needs to also take into account where the board
% hits the slot.
/bed-drive-pos stepper-len drive-screw-start add def % where the drive position relative from back.
/bed-drive-screw-top
bed-slide-high-bottom stepper-height sub % amount hovering about stepper
stepper-height 2 div add
def
/bed-drive-w bed-w 2 div def
/bed-drive-h bed-drive-screw-top bed-drive-screw-r add 2 mm add def
% we are placing the switches as close as possible to the center of the
% drive train to not have too much axial force (the microswitches in question
% use a little force). Otherwise the corner would of course be nice.
/end-switch-offset 0.30 bed-w mul def % from center
/end-switch-thick 8 mm def % thickness of switch
/end-switch-from-back-of-sled drive-mount-pos end-switch-thick add acrylic-t add def
/end-switch-trigger-len % plastic trigger on sled
bed-drive-pos acrylic-t add end-switch-thick sub
drive-mount-pos end-switch-thick add
sub def
% Laser slot distance as constrained by the sled.
/laser-slot-distance pcb-h bed-h pcb-h sub 2 div add 3 mm add def
/laser-slot-h 10 mm def
/laser-slot-w pcb-w 2 mm add def
% Hsync diffusor
/hsync-len laser-slot-h def
/hsync-w 2 mm def
% The UV laser case
/laser-width 33 mm def % Typical width.
/laser-length 55 mm def % Typical length of the laser box
/laser-edge-mount-distance 18 mm def % distance center of laser from edge.
/polygon-mirror-high laser-width 2 div def % == center of the laser
/polygon-mirror-w 44 mm def
/polygon-mirror-h 60 mm def
/polygon-mirror-r 35 mm 2 div def
% When things are tight on the toppanel, we might need to shift the polygon
% mirror a little up to not conflict with the laser. Otherwise, 0 mm is best.
% (TODO: this is not angle corrected yet for anything non-zero).
/polygon-mirror-offset-y 0 mm def
% As well, if there is not enough space on the toppanel, we might need to rotate
% the assembly (e.g. for 70mmx100mm PCBs, a 90 degree change is in order)
/polygon-mirror-rotation 0 def
% The down mirror is elevated above the top plate, so we need the acrylic
% thickness to be on the same level as the rot mirror that is mounted on
% the top plate. TODO: adding acrylic-t here is confusing.
/down-mirror-high polygon-mirror-high acrylic-t add def
/down-mirror-w 10 mm def
/down-mirror-t 4.3 mm def
/down-mirror-slot false def % if we want a slot for an overlong mirror
/down-mirror-backing-width 15.5 mm def % might be calculated from curvature.
/down-mirror-backing-glue-thick 0 mm def
% Given that we cover 60 degrees, we cover 2 * sin(30) times radius in
% horizontal direction, i.e. radius == pcb-w. We want to use a little less of
% the range to have space for synchronization.
/arc-radius pcb-w 20 mm add def
% We want to be at least half pcb sled longer so that we are supported
% at center of gravity. However, the mechanics might require to be longer.
/inner-device-len
laser-slot-distance bed-h 2 div add
bearing-mount-pos acrylic-t add 5 mm add
max
def
/inner-device-high bed-slide-high-bottom bed-slide-high-top add acrylic-t add def
/mirror-holder-width 20 mm def % width of the 45 degree down mirror holder
/mirror-holder-r mirror-holder-width 2 div def
/mirror-holder-high down-mirror-high mirror-holder-r add def
% Apron above the toppanel. derived value
/top-apron-high
mirror-holder-high
acrylic-t sub % Want to embed down again around the top angle
laser-width % Whatever is higher. Laser needs to fit as well.
max
def
% -- variables to place properly between cuts
% distance between different cuts
/cut-dist print-measures { 6 mm } { 1 mm } ifelse def
/side-cut-distance inner-device-high acrylic-t 2 mul add top-apron-high add
2 mul cut-dist add def
% Linewidth doesn't do anything to the DXF output, it just makes it easier
% to manually inspect in the PostScript viewer.
1 setlinewidth
% Like currentpoint but returns a boolean to describe if there was a point.
% Apparantly, PostScript does not have a predicate to ask for a current path,
% so we have to tap into the error message.
% currentpoint? x y true % if there is a current point
% currentpoint? false % if there isn't
/currentpoint? {
2 dict begin
/has-currentpoint true def
/old-handler errordict /nocurrentpoint get def
errordict /nocurrentpoint { pop /has-currentpoint false def} put
currentpoint
has-currentpoint
errordict /nocurrentpoint currentdict /old-handler get put
end
} def
/-gsave /gsave load def
/gsave {
currentpoint? {
% Ideally, we never reach this, but all paths are properly stroke'd
% when gsave is called. But it is hard to find mis-uses in the
% stack-trace gs provides. So just do the right thing and stroke
% here to repair the situation.
% (also, perfectly benign to have something with no path just a point)
% The following will help debug it
%-gsave /Helvetica findfont 10 scalefont setfont (<- Here not properly stroked) show grestore
stroke
-gsave
moveto
} {
-gsave
} ifelse
} def
%%-- measureline.ps
% Measure-line features. It is a little hard to get things PostScript files
% included depending on context. So we include it here manually.
/measure-fontsize 5 mm def
/measure-font /Helvetica-Bold findfont measure-fontsize scalefont def
/measure-desc-font /Helvetica findfont 4 mm scalefont def
/measure-dict << >> def
/measure-col { 0.7 0.7 0.7 setrgbcolor } def
% (desc) measure-offset dx dy
/measure-to {
2 copy atan rotate
5 dict begin
dup mul exch dup mul add sqrt /len exch def
/offset exch def
/desc-text exch def
/display-len len 72 div 25.4 mul 100 mul round 100 div def
/arrow-len 3 mm def
/arrow-w 1 mm def
/measure-unit () def % mm took too much space
%0 offset moveto len offset lineto
% Without offset, add at least a little measurement stub.
offset 0 eq {
0 offset -0.5 mm add moveto 0 offset 0.5 mm add lineto
len offset -0.5 mm add moveto len offset 0.5 mm add lineto
} if
% Arrow between lines
0 offset moveto arrow-len offset arrow-w add lineto
0 offset moveto arrow-len offset arrow-w neg add lineto
len offset moveto len arrow-len sub offset arrow-w add lineto
len offset moveto len arrow-len sub offset arrow-w neg add lineto
0 0 moveto 0 offset lineto
len 0 moveto len offset lineto
display-len ( ) cvs
dup stringwidth pop measure-unit stringwidth pop add 2 div /text-w-half exch def
0 offset moveto len 2 div text-w-half sub 0.5 mm sub offset lineto
len 2 div text-w-half sub % x
offset measure-fontsize 3 div sub moveto show measure-unit show
len 2 div text-w-half add 0.5 mm add offset moveto
len offset lineto
measure-desc-font setfont
len 2 div desc-text stringwidth pop 2 div sub offset measure-fontsize sub moveto
desc-text show
end
stroke
} def
% (desc) measure-offset x1 y1 x2 y2
/measure-line {
4 2 roll
2 copy translate
% 2=20 20 1=20 10
3 -1 roll exch % 20 20 10 20
sub % 20 20 dx
3 1 roll sub % dx dy
measure-to
} def
% pos-x pos-y
/measure-A {
% array stores [(desc) line-offset x1 y1 x2 y2]
userdict /current-measure [() 0 0 0 0 0] put
current-measure 2 3 index put % x
current-measure 3 2 index put % y
} def
/current-measure-A {
currentpoint measure-A pop pop
} def
% pos-x pos-y [optional-array-with-offset]
/measure-B {
dup type (arraytype) eq {
dup 0 get % get offset
current-measure 1 3 -1 roll put
dup length 1 gt { % get description string if available
dup 1 get
current-measure 0 3 -1 roll put
} if
pop
} if
current-measure 4 3 index put % x
current-measure 5 2 index put % y
measure-dict measure-dict length current-measure put % now append at end.
} def
/current-measure-B {
count 0 gt {
dup type (arraytype) eq {
dup 0 get % get offset
current-measure 1 3 -1 roll put
dup length 1 gt { % get description string if available
dup 1 get
current-measure 0 3 -1 roll put
} if
pop
} if
} if
currentpoint measure-B pop pop
} def
/clear-measures {
userdict /measure-dict << >> put
} def
/flush-measures {
stroke % Flush whatever is to be drawn, otherwise ghostscript does it twice
print-measures {
gsave
0.5 setlinewidth
measure-col
measure-font setfont
measure-dict {
aload pop % put array content on stack. Get rid of array
gsave measure-line grestore
pop % get rid of dict key.
} forall
grestore
} if
clear-measures
} def
%%-- measureline.ps
% width clip-min-x clip-max-x x y
/wave-bend {
gsave
6 dict begin
/y exch def
/x exch def
x sub /clip-max-x exch def % substracting x as we are going to translate
x sub /clip-min-x exch def
/total-len exch def
/relief-radius 0.2 mm def
x y translate
0 clip-min-x gt { 0 0 relief-radius 0 360 arc } if
0 0 moveto
0 1 40 {
40 div /fraction exch def
/angle fraction total-len mul len-x div 360 mul 2 mul def
/xpos total-len fraction mul def
xpos angle sin 0.5 mm mul
xpos clip-min-x lt xpos clip-max-x gt or { moveto } { lineto } ifelse
} for
currentpoint pop clip-max-x lt { currentpoint relief-radius 0 360 arc } if
end
stroke
grestore
} def
/kerf-bend-steps 2 def
/lh-spacing-x 2 mm def
/lh-spacing-y 1.9 mm def
% width height fun
/kerf-bend {
gsave
currentpoint translate
1 dict begin
/line-fun exch def
/lh-h exch def
/lh-w exch def
/len-x lh-w lh-spacing-x sub kerf-bend-steps div def
% this clipping doesn't really seem to work with pstoedit.
%0 0 moveto
%lh-w 0 rlineto
%0 lh-h rlineto
%lh-w neg 0 rlineto
%0 lh-h neg rlineto
%closepath
%clip
newpath
lh-spacing-y 2 mul lh-spacing-y 2 mul lh-h {
/y exch def
0 1 kerf-bend-steps 1 sub {
/i exch def
/x i len-x mul lh-spacing-x add def
len-x lh-spacing-x sub % width
-1 mm lh-w 2 mm add % x-min/ x-max
x y line-fun
} for
} for
stroke
lh-spacing-y lh-spacing-y 2 mul lh-h lh-spacing-y sub {
/y exch def
0 1 kerf-bend-steps {
/i exch def
/x i len-x mul len-x 2 div sub lh-spacing-x add def
len-x lh-spacing-x sub % width
-1 mm lh-w 2 mm add % x-min/ x-max
x y line-fun
} for
} for
stroke
end
grestore
} def
/inner-cut { 1 0 0 setrgbcolor } def
/outer-cut { 0 0 0 setrgbcolor } def
/simple-cut { 1 1 0 setrgbcolor } def
/scan-engraving-cut { 0 1 0 setrgbcolor } def
/vector-engraving-cut { 0 0 1 setrgbcolor } def
% (description) x y
/describe {
print-measures {
-gsave
/Helvetica findfont 8 mm scalefont setfont
measure-col
moveto
show
grestore
} if
} def
% r
/currentpoint-circle {
1 dict begin
/crr exch def
currentpoint
crr 0 rmoveto
crr 0 360 arc
crr neg 0 rmoveto
end
} def
% x y r
/circle {
3 1 roll moveto currentpoint-circle
} def
% Given a direction in delta coordinats and a length, return the new
% coordinates where that vector points to.
% dir_x dir_y length -> dx dy (relative position)
/colinear {
5 dict begin
/thick exch def
/dy exch def
/dx exch def
/len dx dx mul dy dy mul add sqrt def
/fraction thick len div def % fraction of amount that is perpendicular
dx fraction mul dy fraction mul
end
} def
% Similar to colinear, but yields the coordinates of the normal of the given
% length, so perpendicular to the original coordinates in delta.
% dir_x dir_y length -> dx dy (relative position)
/perpendicular {
5 dict begin
/thick exch def
/dy exch def
/dx exch def
/len dx dx mul dy dy mul add sqrt def
/fraction thick len div def % fraction of amount that is perpendicular
dy fraction mul neg dx fraction mul
end
} def
% dx dy thick
/orth-segment {
4 dict begin
/thick exch def
/is-outer thick 0 gt def
/dy exch def
/dx exch def
dx dy thick perpendicular rlineto is-outer { relief-here } if
dx dy rlineto is-outer { relief-here } if
dx dy thick neg perpendicular rlineto
end
} def
% dx dy % create a hole half way down the dx dy
/connect-hole {
2 dict begin
/sdy exch def
/sdx exch def
sdx 2 div sdy 2 div rmoveto
sdx sdy thick 2 div perpendicular rmoveto
currentpoint 1 mm circle
sdx sdy thick 2 div neg perpendicular rmoveto
sdx 2 div neg sdy 2 div neg rmoveto
end
} def
% dx dy % create a tslot half way down the dx dy
/connect-t-slot {
3 dict begin
/sdy exch def
/sdx exch def
/ff finger-len 2 mm sub finger-len div 2 div def
sdx ff mul sdy ff mul rmoveto
sdx sdy -0.5 mm perpendicular rmoveto
sdx sdy connect-screw-len perpendicular rlineto
sdx sdy -1 mm colinear rlineto
relief-here
sdx sdy 1.6 mm perpendicular rlineto
sdx sdy 1 mm colinear rlineto
sdx sdy connect-screw-len 2 div perpendicular rlineto
sdx sdy 2 mm colinear rlineto
sdx sdy connect-screw-len 2 div neg perpendicular rlineto
sdx sdy 1 mm colinear rlineto
sdx sdy -1.6 mm perpendicular rlineto
currentpoint stroke moveto
relief-here
sdx sdy -1 mm colinear rlineto
sdx sdy connect-screw-len neg perpendicular rlineto
currentpoint stroke moveto
% go back
sdx sdy 0.5 mm perpendicular rmoveto
sdx sdy 2 mm neg colinear rmoveto
sdx ff mul neg sdy ff mul neg rmoveto
end
} def
% x y thick
/finger-groove-rlineto {
12 dict begin
/thick exch def
/is-inner thick 0 lt def
/dy exch def
/dx exch def
/len dx dx mul dy dy mul add sqrt def
/factor acrylic-t len div def % perpendicular thing.
/segments
len finger-len sub % we want one finger len at the end
finger-len 2 mul % number of low and up segments
div floor cvi def
/extra-fraction len finger-len sub
segments finger-len 2 mul mul sub len div 2 div def
dx extra-fraction mul dy extra-fraction mul rlineto
/sdx dx finger-len len div mul def
/sdy dy finger-len len div mul def
1 1 segments {
pop
sdx sdy rlineto is-inner { relief-here } if
sdx sdy thick orth-segment is-inner { relief-here } if
} for
sdx sdy rlineto % one extra bottom segment.
dx extra-fraction mul dy extra-fraction mul rlineto
end
} def
% x y thick do_hole { 0, 1, 2 }
/hole-slot-rlineto {
12 dict begin
/do-hole exch def
/thick exch def
/dy exch def
/dx exch def
/len dx dx mul dy dy mul add sqrt def
/factor acrylic-t len div def % perpendicular thing.
/segments
len finger-len sub % we want one finger len at the end
finger-len 2 mul % number of low and up segments
div floor cvi def
/extra-fraction len finger-len sub
segments finger-len 2 mul mul sub len div 2 div def
dx extra-fraction mul dy extra-fraction mul rmoveto
/sdx dx finger-len len div mul def
/sdy dy finger-len len div mul def
1 1 segments {
pop
do-hole 1 eq { % hole
sdx sdy connect-hole
} if
do-hole 2 eq { % t-slot
sdx sdy connect-t-slot
} if
sdx sdy rmoveto
sdx sdy rmoveto
} for
do-hole 1 eq { % hole
sdx sdy connect-hole
} if
do-hole 2 eq { % t-slot
sdx sdy connect-t-slot
} if
sdx sdy rmoveto
dx extra-fraction mul dy extra-fraction mul rmoveto
end
} def
% dx dy
/t-slot-rlineto {
acrylic-t neg 2 hole-slot-rlineto
} def
/hole-rlineto {
acrylic-t neg 1 hole-slot-rlineto
} def
% dx dy
/finger-rlineto {
2 copy t-slot-rlineto 2 copy neg exch neg exch rmoveto
acrylic-t neg finger-groove-rlineto
} def
/groove-rlineto {
2 dict begin
/dy exch def
/dx exch def
dx dy hole-rlineto dx neg dy neg rmoveto
dx dy acrylic-t neg perpendicular rlineto
dx dy acrylic-t finger-groove-rlineto
dx dy acrylic-t perpendicular rlineto
end
} def
/finger-rlineto-noscrew {
acrylic-t neg finger-groove-rlineto
} def
/groove-rlineto-noscrew {
2 dict begin
/dy exch def
/dx exch def
dx dy acrylic-t neg perpendicular rlineto
dx dy acrylic-t finger-groove-rlineto
dx dy acrylic-t perpendicular rlineto
end
} def
% Given an absolute target coordinate, converts that to a relative call.
% xt yt proc
/lineto-to-rlineto-proc { % need: (xt - x) (yt - y)
3 1 roll
currentpoint % xt yt x y
3 -1 roll exch sub % xt yt x y -> xt x y yt -> xt x yt y -> xt x (yt - y)
3 1 roll sub % dy dx
exch
3 -1 roll exec
} def
% Same finger/groove commands as above, but with lineto
/finger-lineto { { finger-rlineto } lineto-to-rlineto-proc } def
/groove-lineto { { groove-rlineto } lineto-to-rlineto-proc } def
/finger-lineto-noscrew { { finger-rlineto-noscrew } lineto-to-rlineto-proc } def
/groove-lineto-noscrew { { groove-rlineto-noscrew } lineto-to-rlineto-proc } def
% dx dy
/slot-rlineto {
gsave
inner-cut % inside kerf correction.
9 dict begin
/dy exch def
/dx exch def
/len dx dx mul dy dy mul add sqrt def
/segments
len finger-len sub % we want one finger len at the end
finger-len 2 mul % number of low and up segments
div floor cvi def
/extra-fraction len finger-len sub
segments finger-len 2 mul mul sub len div 2 div def
currentpoint translate dy dx atan rotate
/dx len def
/dy 0 def
dx extra-fraction mul dy extra-fraction mul rmoveto
/sdx dx finger-len len div mul def
/sdy dy finger-len len div mul def
1 1 segments {
pop
sdx sdy rmoveto
currentpoint
sdx slot-thick relief-box
moveto sdx 0 rmoveto
} for
stroke
print-measures {
measure-col
0 0 moveto len 0 lineto stroke
[3] 0 setdash
0 0 moveto 0 acrylic-t lineto len acrylic-t lineto len 0 lineto stroke
} if
end
grestore
} def
/slot-lineto { % need: (xt - x) (yt - y)
currentpoint % xt yt x y
3 -1 roll exch sub % xt yt x y -> xt x y yt -> xt x yt y -> xt x (yt - y)
3 1 roll sub % dy dx
exch
slot-rlineto
} def
% Spring edge of a part. Really only works in x-direction right now
% x y len
/x-spring {
7 dict begin
/line-len exch def % total length of line
2 copy % so that we later can move to the end of the line
% Some hardcodes, probably would be good as
/arc-x 5 mm def % curve up and down part
/arc-y 0.7 mm def % thickness of the 'hump'
/spring-thick 2 mm def % thickness of the bendable part
/spring-short 2 mm def % how much shorter the bendable part should be to length
/bend-radius 1.2 mm def
/overcut arc-y def % cut starting outside edge
gsave
outer-cut
translate 0 0 moveto
line-len arc-x 2 mul sub 0 mm lineto % start of hump
arc-x 2 div 0 % hump up
arc-x 2 div arc-y
arc-x arc-y rcurveto
arc-x 2 div 0 % hump down
arc-x 2 div arc-y neg
arc-x arc-y neg rcurveto
stroke
% Now, cut out the area that will provide the springiness
simple-cut
line-len overcut moveto
line-len spring-thick neg lineto % down; should be arc
% line backwards to form spring span; might be better with bezier ?
line-len spring-short sub bend-radius sub neg 0 rlineto
currentpoint bend-radius sub bend-radius 90 270 arc
% at the end of the travel, we bend down by this amount. Since the 'hump' of
% height arc-y is a little bit inwards of the lever, the travel at the end is
% more than arc-y
/down-bend line-len line-len arc-x sub div arc-y mul 0.2 mm add def
line-len 0.5 mm add
spring-thick neg down-bend sub lineto
0 spring-thick down-bend add overcut add rlineto
stroke
grestore
% Go to the end of the spring, so that this just behaves as a line segment
exch line-len add exch moveto
end
} def
% r is the outer radius.
% n r
/n-polygon {
gsave
currentpoint translate
3 dict begin
/r exch def
/n exch def
/angle 360 n div def
r 0 moveto
1 1 n {
dup
angle mul cos r mul
exch
angle mul sin r mul
lineto
} for
closepath stroke
end
grestore
} def
/end-switch {
currentpoint
0 0 1 mul rmoveto 0.6 mm currentpoint-circle
0 5.02 mm rmoveto 0.6 mm currentpoint-circle
0 5.02 mm rmoveto 0.6 mm currentpoint-circle stroke
%moveto currentpoint
%engraving-cut -2.6 mm -2.6 mm rmoveto 5.2 mm 2.54 mm 6 mul box stroke
%outer-cut
moveto
} def
/hsync-slot {
0 hsync-w 2 div neg rmoveto
hsync-len hsync-w box
} def
% x y
/photo-diode-cutout {
inner-cut
moveto
0 2.5 mm rlineto
-3.7 mm 0 rlineto
0 0.5 mm rlineto
-1.1 mm 0 rlineto
0 -1.4 mm rlineto % lead cutout
-4 mm 0 rlineto
0 -3.2 mm rlineto
4 mm 0 rlineto
0 -1.4 mm rlineto
1.1 mm 0 rlineto
0 0.5 mm rlineto
3.7 mm 0 rlineto
closepath
currentpoint
stroke
moveto hsync-slot stroke
outer-cut
} def
/screw {
screw-r circle
} def
% To leave a little more space. Only in X direction currently.
/oval-screw {
3 dict begin
2 div /half-extend exch def
/y exch def
/x exch def
x half-extend add y screw-r add moveto
x half-extend sub y screw-r add lineto
x half-extend sub y screw-r 90 270 arc
x half-extend add y screw-r sub lineto
x half-extend add y screw-r -90 90 arc
end
} def
% Initially, we had rods through the hole width, now just simple
% screws.
/rod {
screw-r circle
} def
/relief-here {
do-reliefs { relief-r currentpoint-circle } if
} def
% make a box at current position with given width/height
% w h -> -
/box {
2 dict begin
/h exch def
/w exch def
w 0 rlineto
0 h rlineto
w neg 0 rlineto
0 h neg rlineto
closepath stroke
end
} def
% Like box, but just take the measurements from the stack without drawing
% the box.
% w h -> w h
/measure-box {
2 dict begin
/h 1 index def
/w 2 index def
current-measure-A currentpoint exch w add exch [-3 mm] measure-B pop pop
current-measure-A currentpoint h add [3 mm] measure-B pop pop
end
} def
% like box, but with corner reliefs.
/relief-box {
2 dict begin
/h exch def
/w exch def
w 0 rlineto relief-here
0 h rlineto relief-here
w neg 0 rlineto relief-here
0 h neg rlineto relief-here
closepath stroke
end
} def
% w h radius
/rounded-corner-box {
3 dict begin
/radius exch def
/height exch def
/width exch def
currentpoint
stroke % need to flush state before gsave/grestore
gsave
translate
0 radius add 0 moveto
width radius sub 0 lineto
width radius sub 0 radius add radius -90 0 arc
width height radius sub lineto
width radius sub height radius sub radius 0 90 arc
0 radius add height lineto
0 radius add height radius sub radius 90 180 arc
0 0 radius add lineto
0 radius add 0 radius add radius 180 270 arc
closepath stroke
grestore
end
} def
% Origin is rotation axis
% Boolean if outline should be printed
% bool x y
/polygon-mirror-footprint {
stroke
gsave
translate
0 0 moveto
currentpoint 7 mm circle
41.6 mm 2 div 40 mm screw
41.6 mm 2 div neg 40 mm screw
41.6 mm 2 div -18.5 mm screw
41.6 mm 2 div neg -18.5 mm screw
stroke
% Some hinting lines.
print-measures {
measure-col
-24 mm -24 mm moveto 48 mm 68 mm box
0 0 polygon-mirror-r circle stroke
} if
outer-cut
48 mm 2 div neg -24 mm translate
% should we print the outline ?
{