forked from waynegramlich/ezcad3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROSBot.py
executable file
·2100 lines (1851 loc) · 68.2 KB
/
ROSBot.py
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
#!/usr/bin/env python
# Common metric screw lengths:
#
# http://www.bjg-design.com/designbook/mscrlng1.htm
#
#
# Excerpt from McMaster Carr.
# Class 12.9 Black Alloy Steel (Metric)- DIN 912.
# Screw
# Length Screw Size
# M1.6 M2 M3 M4 M5 M6 M8 M10 M12 M14 M16 M20 M24 M30
# 3 x - - - - - - - - - - - - -
# 4 x - - - - - - - - - - - - -
# 5 x x - - - - - - - - - - - -
# 6 x x x x - - - - - - - - - -
# 8 - x x x - - - - - - - - - -
# 10 - - x x x x x - - - - - - -
# 12 - x x x x x - - - - - - - -
# 14 - - x x x x - - - - - - - -
# 16 - - x x x x x x - - - - - -
# 18 - - - x x x x - - - - - - -
# 20 - - x x x x x x - - - - - -
# 22 - - - - x x x - - - - - - -
# 25 - - x x x x x x x - - - - -
# 30 - - x x x x x x x x x - - -
# 35 - - x x x x x x x x x - - -
# 40 - - - x x x x x x x x - - -
# 45 - - - - - x x x x - x - - -
# 50 - - - - x x x x x x x x - -
# 55 - - - - x x x x x - - - - -
# 60 - - - - x x x x x x x x x -
# 65 - - - - - x x x x x x x x -
# 70 - - - - - x x x x - - x x -
# 75 - - - - - - x - x - - - - -
# 80 - - - - - - x x x x - x x x
# 90 - - - - - - x x x x - x x x
# 100 - - - - - - x x x x - x x x
# 110 - - - - - - x x x x - x x x
# 120 - - - - - - x x x x - x x x
# 150 - - - - - - x x x x - x x x
import math
from EZCAD3 import *
class Base(Part):
def __init__(self, up):
""" *Base*: initialize. """
Part.__init__(self, up)
self.dx_l = L(inch=12)
self.dy_l = L(inch=12)
self.z0_l = L()
self.dz_l = L(mm=5.0)
def configure(self, dx = None, dy = None, z0 = None, dz = None):
""" *Base*: configure. """
# Check argument types:
none_type = type(None)
assert type(dx) == none_type or isinstance(dx, L)
assert type(dy) == none_type or isinstance(dx, L)
assert type(z0) == none_type or isinstance(z0, L)
assert type(dz) == none_type or isinstance(dz, L)
if isinstance(dx, L):
self.dx_l = dx
if isinstance(dy, L):
self.dy_l = dy
if isinstance(z0, L):
self.z0_l = z0
if isinstance(dz, L):
self.dz_l = dz
def construct(self):
""" *Base*: consturct. """
dx = self.dx_l
dy = self.dy_l
dz = self.dz_l
x0 = -(dx / 2.0)
x1 = dx / 2.0
y0 = -(dy / 2.0)
y1 = dy / 2.0
z0 = self.z0_l
z1 = z0 + dz / 2
z2 = z1 + dz / 2
#print("Base.construct(): x0={0} x1={1} y0={2} y1={3}". \
# format(x0, x1, y0, y1))
z = L()
outer_contour = Contour(name = "Base")
outer_contour.bend_append(P(x0, y0, z0), z)
outer_contour.bend_append(P(x0, y1, z0), z)
outer_contour.bend_append(P(x1, y1, z0), z)
outer_contour.bend_append(P(x1, y0, z0), z)
x_pitch = L(inch=1)
y_pitch = L(inch=1)
column_count = int(dx / x_pitch)
column_span = x_pitch * (column_count - 1)
x_start = -column_span / 2.0
row_count = int(dy / y_pitch)
row_span = y_pitch * (row_count - 1)
y_start = -row_span / 2.0
#print("x_start={0} column_span={1} column_count={2}".
# format(x_start, column_span, column_count))
#print("y_start={0} row_span={1} row_count={2}".
# format(y_start, row_span, row_count))
hole_dx = L(mm=3)
hole_dy = L(mm=3)
inner_contours = []
for row in range(row_count):
y = y_start + y_pitch * row
for column in range(column_count):
x = x_start + x_pitch * column
# Hole center is at (x, y):
x0 = x - hole_dx / 2
x1 = x + hole_dx / 2
y0 = y - hole_dy / 2
y1 = y + hole_dy / 2
# Construct the *hole_contour*:
hole_contour = Contour(
name = "Base Hole[{0},{1}]".format(row, column))
hole_contour.bend_append(P(x0, y0, z0), z)
hole_contour.bend_append(P(x0, y1, z0), z)
hole_contour.bend_append(P(x1, y1, z0), z)
hole_contour.bend_append(P(x1, y0, z0), z)
inner_contours.append(hole_contour)
self.extrude(comment = "Base",
material = Material("wood", "plywood"),
color = Color("beige"),
outer_contour = outer_contour,
inner_contours = inner_contours,
start = P(z, z, z0),
end = P(z, z, z0 + dz))
self.dxf_write(center = P(0, 0, z1))
class Castor_Assembly(Part):
def __init__(self, up):
""" *Castor_Assembly*: Initialization """
self.thin_l = L(mm=3)
self.thick_l = L(mm=5)
Part.__init__(self, up)
self.bottom_side_ = Castor_Bottom(self)
self.corner1_p = P()
self.corner2_p = P()
self.east_side_ = Castor_East_West(self)
self.north_side_ = Castor_North_South(self)
self.plate_ = Castor_Plate(self)
self.screw_bne_ = Fastener(self, "CA.side_bne")
self.screw_bnw_ = Fastener(self, "CA.side_bnw")
self.screw_bse_ = Fastener(self, "CA.side_bse")
self.screw_bsw_ = Fastener(self, "CA.side_bsw")
self.screw_tne_ = Fastener(self, "CA.side_tne")
self.screw_tnw_ = Fastener(self, "CA.side_tnw")
self.screw_tse_ = Fastener(self, "CA.side_tse")
self.screw_tsw_ = Fastener(self, "CA.side_tsw")
self.screw_bottom_ne_ = Fastener(self, "CA.bottom_ne")
self.screw_bottom_nw_ = Fastener(self, "CA.bottom_ne")
self.screw_bottom_se_ = Fastener(self, "CA.bottom_se")
self.screw_bottom_sw_ = Fastener(self, "CA.bottom_sw")
self.screw_top_e_ = Fastener(self, "CA.top_e")
self.screw_top_w_ = Fastener(self, "CA.top_w")
self.south_side_ = Castor_North_South(self)
self.west_side_ = Castor_East_West(self)
self.wheel_ = Castor_Wheel(self)
def configure(self, corner1 = P(), corner2 = P()):
""" Castor_Assembly: Configuration. """
# Do argument type checking:
assert isinstance(corner1, P)
assert isinstance(corner2, P)
# Verify that corners are ordered properly:
assert corner1.x < corner2.x
assert corner1.y < corner2.y
assert corner1.z < corner2.z
# Load up *corner1* and *corner2*:
self.corner1_p = corner1
self.corner2_p = corner2
def construct(self):
""" Castor_Assembly: Construction. """
# Grab some values from *castor* (== *self*):
bottom_side = self.bottom_side_
corner1 = self.corner1_p
corner2 = self.corner2_p
east_side = self.east_side_
north_side = self.north_side_
plate = self.plate_
screw_bottom_ne = self.screw_bottom_ne_
screw_bottom_nw = self.screw_bottom_nw_
screw_bottom_se = self.screw_bottom_se_
screw_bottom_sw = self.screw_bottom_sw_
screw_bne = self.screw_bne_
screw_bnw = self.screw_bnw_
screw_bse = self.screw_bse_
screw_bsw = self.screw_bsw_
screw_tne = self.screw_tne_
screw_tnw = self.screw_tnw_
screw_tse = self.screw_tse_
screw_tsw = self.screw_tsw_
screw_top_e = self.screw_top_e_
screw_top_w = self.screw_top_w_
south_side = self.south_side_
thick = self.thick_l
thin = self.thin_l
west_side = self.west_side_
wheel = self.wheel_
screw_length = L(mm=10)
# Compute some X locations:
## Start from east working towards X center:
self.x0_l = x0 = corner1.x # East surface of *east_side*
self.x1_l = x1 = x0 + thin # West surface of *east_side*
self.x2_l = x2 = x0 + screw_length # End of *east_side* screws
self.x3_l = x3 = x2 + 2 * thick # East tongue of *bottom_side*
## Now start from west woriking towards center:
self.x8_l = x8 = corner2.x # West surface of *west_side*
self.x7_l = x7 = x8 - thin # East surface of *west_side*
self.x6_l = x6 = x7 - screw_length # End of *west_side* screws
self.x5_l = x5 = x6 - 2 * thick # West tongue of *bottom_side*
self.x4_l = x4 = (x0 + x8)/2 # X Box center
# Compute some Y locations:
## Start from south working towards Y center:
self.y0_l = y0 = corner1.y # South surface of *east_side*
self.y1_l = y1 = y0 + thin # South surface of *south_side*
self.y2_l = y2 = y1 + thick/2 # Center of *south_side*
self.y3_l = y3 = y2 + thick/2 # North surface of *south_side*
self.y4_l = y4 = y3 + thick # South tongue of *bottom_side*
## Now start from north working towards Y center:
self.y10_l = y10 = corner2.y # North surface of *east_side*
self.y9_l = y9 = y10 - thin # North surface of *north_side*
self.y8_l = y8 = y9 - thick/2 # Center of *north_side*
self.y7_l = y7 = y8 - thick/2 # South surface of *north_side*
self.y6_l = y6 = y7 - thick # North tongue of *bottom_side*
self.y5_l = y5 = (y0 + y10)/2 # Y Box Center
# Compute some Z locations:
## Start from bottom working towards Z center:
self.z0_l = z0 = corner1.z # floor surface
self.z1_l = z1 = z0 + wheel.diameter_l/2 # Wheel axel
self.z2_l = z2 = z1 + wheel.diameter_l/2 # Bottom surface of *east_side*
self.z3_l = z3 = z2 + thin # Bottom of *bottom_side*
self.z4_l = z4 = z3 + thick/2 # Center of *bottom_side*
self.z5_l = z5 = z4 + thick/2 # Top surface of *bottom_side*
self.z6_l = z6 = z5 + thick # Bottom surface of *south_side*
## Now from top working towards Z center:
self.z10_l = z10 = corner2.z # Top surface of caster asm.
self.z9_l = z9 = z10 - screw_length + thick # End of top screws
self.z8_l = z8 = z9 - thick # Top tongue of *south_side*
self.z7_l = z7 = (z2 + z8)/2 # Z Box Center
# Configure everything:
bottom_side.configure("Bottom Side", z3, z5)
east_side.configure("West Side", x7, x8)
west_side.configure("East Side", x0, x1)
south_side.configure("South Side", y1, y3)
north_side.configure("North Side", y7, y9)
plate.configure(P(x4, y5, z3))
wheel.configure(P(x4, y5, z3 - wheel.diameter_l/2))
# Install the 8 screws that hold the castor sides together:
screw_flags = "#4-40"
screw_bne.configure(comment = "Castor BNE",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x8, y8, z4),
end = P(x6, y8, z4),
flags = screw_flags)
screw_bne.drill(part = east_side, select = "close")
screw_bne.nut_ledge(part = north_side, flags="N")
screw_bnw.configure(comment = "Castor BNW",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x0, y8, z4),
end = P(x2, y8, z4),
flags = screw_flags)
screw_bnw.drill(part = west_side, select = "close")
screw_bnw.nut_ledge(part = north_side, flags="N")
screw_bse.configure(comment = "Castor BSE",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x8, y2, z4),
end = P(x6, y2, z4),
flags = screw_flags)
screw_bse.drill(part = east_side, select = "close")
screw_bse.nut_ledge(part = south_side, flags="S")
screw_bsw.configure(comment = "Castor BSW",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x0, y2, z4),
end = P(x2, y2, z4),
flags = screw_flags)
screw_bsw.drill(part = west_side, select = "close")
screw_bsw.nut_ledge(part = south_side, flags="S")
screw_tne.configure(comment = "Castor TNE",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x8, y8, z9),
end = P(x6, y8, z9),
flags = screw_flags)
screw_tne.drill(part = east_side, select = "close")
screw_tne.nut_ledge(part = north_side, flags="N")
screw_tnw.configure(comment = "Castor TNW",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x0, y8, z9),
end = P(x2, y8, z9),
flags = screw_flags)
screw_tnw.drill(part = west_side, select = "close")
screw_tnw.nut_ledge(part = north_side, flags="N")
screw_tse.configure(comment = "Castor TSE",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x8, y2, z9),
end = P(x6, y2, z9),
flags = screw_flags)
screw_tse.drill(part = east_side, select = "close")
screw_tse.nut_ledge(part = south_side, flags="S")
screw_tsw.configure(comment = "Castor TSW",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x0, y2, z9),
end = P(x2, y2, z9),
flags = screw_flags)
screw_tsw.drill(part = west_side, select = "close")
screw_tsw.nut_ledge(part = south_side, flags="S")
# Drill 4 holes for the creeper castor:
pitch_dx = L(inch=1)
pitch_dy = L(inch="1-5/8")
screw_bottom_ne.configure(comment = "Caster Bottom NE Screw",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x4 + pitch_dx/2, y5 + pitch_dy/2, z5),
end = P(x4 + pitch_dx/2, y5 + pitch_dy/2, z2),
flags = screw_flags)
screw_bottom_ne.drill(part = bottom_side, select = "close")
screw_bottom_ne.drill(part = plate, select = "close")
screw_bottom_nw.configure(comment = "Caster Bottom NW Screw",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x4 - pitch_dx/2, y5 + pitch_dy/2, z5),
end = P(x4 - pitch_dx/2, y5 + pitch_dy/2, z2),
flags = screw_flags)
screw_bottom_nw.drill(part = bottom_side, select = "close")
screw_bottom_nw.drill(part = plate, select = "close")
screw_bottom_se.configure(comment = "Caster Bottom SE Screw",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x4 + pitch_dx/2, y5 - pitch_dy/2, z5),
end = P(x4 + pitch_dx/2, y5 - pitch_dy/2, z2),
flags = screw_flags)
screw_bottom_se.drill(part = bottom_side, select = "close")
screw_bottom_se.drill(part = plate, select = "close")
screw_bottom_sw.configure(comment = "Caster Bottom SW Screw",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P(x4 - pitch_dx/2, y5 - pitch_dy/2, z5),
end = P(x4 - pitch_dx/2, y5 - pitch_dy/2, z2),
flags = screw_flags)
screw_bottom_sw.drill(part = bottom_side, select = "close")
screw_bottom_sw.drill(part = plate, select = "close")
# Install the top mount screws:
screw_top_e.configure(comment = "Caster Top North Screw",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P((x7 + x8)/2, y5, z10 + thick * 3),
end = P((x7 + x8)/2, y5, z9),
flags = screw_flags)
screw_top_e.nut_ledge(part = east_side, flags="E")
screw_top_w.configure(comment = "Caster Top North Screw",
color = Color("black"),
material = Material("Steel", "Stainless"),
start = P((x0 + x1)/2, y5, z10 + thick * 3),
end = P((x0 + x1)/2, y5, z9),
flags = screw_flags)
screw_top_w.nut_ledge(part = west_side, flags="E")
#north_side.invisible_set()
class Castor_Bottom(Part):
def __init__(self, up):
""" *Castor_Bottom*: Initialization. """
Part.__init__(self, up)
self.name_s = "<no name>"
self.z2_l = L()
self.z3_l = L()
def configure(self, name, z2, z3):
""" *Castor_Bottom: Configuration. """
assert isinstance(name, str)
assert isinstance(z2, L)
assert isinstance(z3, L)
self.name_s = name
self.z2_l = z2
self.z3_l = z3
def construct(self):
""" *Castor_Bottom*: Construction. """
# Grab some values from *self*:
assembly = self.up
z2 = self.z2_l
z3 = self.z3_l
# Grab some valus from *assembly*:
x0 = assembly.x0_l
x1 = assembly.x1_l
x3 = assembly.x3_l
x4 = assembly.x4_l
x5 = assembly.x5_l
x7 = assembly.x7_l
x8 = assembly.x8_l
y1 = assembly.y1_l
y3 = assembly.y3_l
y4 = assembly.y4_l
y5 = assembly.y5_l
y6 = assembly.y6_l
y7 = assembly.y7_l
y9 = assembly.y9_l
# Do the initial block:
self.block(comment = "Bottom Side",
color = Color("green"),
material = Material("wood", "plywood"),
corner1 = P(x1, y3, z2),
corner2 = P(x7, y7, z3),
top = "t")
#print("bottom:c1={0} c2={1}".format(P(x1, y1, z2), P(x7, y7, z3)))
# Do the West tongue:
self.block(comment = "Bottom Side West Tongue",
corner1 = P(x0, y4, z2),
corner2 = P(x1, y6, z3),
welds = "e",
top = "t")
# Do the East tongue:
self.block(comment = "Bottom Side West Tongue",
corner1 = P(x7, y4, z2),
corner2 = P(x8, y6, z3),
welds = "w",
top = "t")
# Do the South tongue:
self.block(comment = "Bottom Side South Tongue",
corner1 = P(x3, y1, z2),
corner2 = P(x5, y3, z3),
welds = "n",
top = "t")
# Do the North tongue:
self.block(comment = "Bottom Side North Tongue",
corner1 = P(x3, y7, z2),
corner2 = P(x5, y9, z3),
welds = "s",
top = "t")
self.dxf_write(center = P(x4, y5, (z2 + z3)/2),
plane_normal = P(0, 0, L(mm=1)))
class Castor_East_West(Part):
def __init__(self, up):
""" *Castor_East_West*: Initialization. """
Part.__init__(self, up)
self.name_s = "<no name>"
self.x0_l = L()
self.x1_l = L()
def configure(self, name, x0, x1):
""" *Castor_East_West*: Initialization. """
assert isinstance(name, str)
assert isinstance(x0, L)
assert isinstance(x1, L)
self.name_s = name
self.x0_l = x0
self.x1_l = x1
def construct(self):
""" *Castor_East_West*: Construction. """
assembly = self.up
name = self.name_s
x0 = self.x0_l
x1 = self.x1_l
y0 = assembly.y0_l
y1 = assembly.y1_l
y3 = assembly.y3_l
y4 = assembly.y4_l
y5 = assembly.y5_l
y6 = assembly.y6_l
y7 = assembly.y7_l
y9 = assembly.y9_l
y10 = assembly.y10_l
z2 = assembly.z2_l
z3 = assembly.z3_l
z5 = assembly.z5_l
z6 = assembly.z6_l
z7 = assembly.z7_l
z8 = assembly.z8_l
z10 = assembly.z10_l
self.block(comment = name,
color = Color("red"),
material = Material("wood", "plywood"),
corner1 = P(x0, y0, z2),
corner2 = P(x1, y10, z10),
top = "e")
# Open bottom tongue slot:
self.simple_pocket(comment = "Bottom Tongue Slot",
bottom_corner = P(x0, y4, z3),
top_corner = P(x1, y6, z5),
pocket_top = "e")
# Remove the south tongue slot:
self.simple_pocket(comment = "{0} South Tongue Slot".format(name),
bottom_corner = P(x0, y1, z6),
top_corner = P(x1, y3, z8),
pocket_top = "e")
# Remvoe the north tongue:
self.simple_pocket(comment = "{0} North Tongue Slot".format(name),
bottom_corner = P(x0, y7, z6),
top_corner = P(x1, y9, z8),
pocket_top = "e")
self.dxf_write(center = P((x0 + x1)/2, y4, z7),
plane_normal=P(L(mm=1), 0, 0))
class Castor_North_South(Part):
def __init__(self, up):
""" *Castor_North_South*: Initialization. """
Part.__init__(self, up)
self.name = "<no name>"
self.y0_l = L()
self.y1_l = L()
def configure(self, name, y0, y1):
""" *Castor_North_South*: Initialization. """
assert isinstance(name, str)
assert isinstance(y0, L)
assert isinstance(y1, L)
self.name_s = name
self.y0_l = y0
self.y1_l = y1
def construct(self):
""" *Castor_North_South*: Construction. """
# Grab some values from *self*:
name = self.name_s
y0 = self.y0_l
y1 = self.y1_l
assembly = self.up
# Grab some values from *assembly*:
x0 = assembly.x0_l
x1 = assembly.x1_l
x3 = assembly.x3_l
x4 = assembly.x4_l
x5 = assembly.x5_l
x7 = assembly.x7_l
x8 = assembly.x8_l
z2 = assembly.z2_l
z3 = assembly.z3_l
z5 = assembly.z5_l
z6 = assembly.z6_l
z7 = assembly.z7_l
z8 = assembly.z8_l
z10 = assembly.z10_l
# The initial chunk of plywood fits between the east and west sides:
self.block(comment = name,
color = Color("blue"),
material = Material("wood", "plywood"),
corner1 = P(x1, y0, z2),
corner2 = P(x7, y1, z10),
top = "n")
# Cut open bottom tongue slot:
self.simple_pocket(comment = "Bottom Tongue Slot",
bottom_corner = P(x3, y0, z3),
top_corner = P(x5, y1, z5),
pocket_top = "n")
# Add in an west tongue:
self.block(comment = "{0} West Tongue",
corner1 = P(x0, y0, z6),
corner2 = P(x1, y1, z8),
welds = "e",
top = "n")
# Add in an east tongue:
self.block(comment = "{0} East Tongue",
corner1 = P(x7, y0, z6),
corner2 = P(x8, y1, z8),
welds = "w",
top = "n")
self.dxf_write(center = P(x4, (y0+y1)/2, z7),
plane_normal = P(0, L(mm=1), 0))
class Castor_Plate(Part):
def __init__(self, up):
""" *Castor_Plate*: Initalization. """
Part.__init__(self, up)
self.center_p = P()
def configure(self, center = P()):
""" *Castor_Plate*: Configuration. """
assert isinstance(center, P)
self.center_p = center
def construct(self):
""" *Castor_Plate*: Construction. """
center = self.center_p
x = center.x
y = center.y
z = center.z
plate_dx = L(inch="1-9/16")
plate_dy = L(inch="2-1/4")
plate_dz = L(inch="5/32")
self.block(comment = "Castor Plate",
color = Color("yellow"),
material = Material("plastic", "unknown"),
corner1 = P(x - plate_dx/2, y - plate_dy/2, z - plate_dz),
corner2 = P(x + plate_dx/2, y + plate_dy/2, z),
top = "t")
class Castor_Wheel(Part):
def __init__(self, up):
""" *Castor_Wheel*: Initialization. """
Part.__init__(self, up)
self.center_p = P()
def configure(self, center = P()):
""" *Castor_Wheel*: Configuration. """
assert isinstance(center, P)
self.center_p = center
def construct(self):
""" *Castor_Wheel*: Construction. """
center = self.center_p
self.diameter_l = diameter = L(inch="2-3/4")
dy = L(inch=.5)
self.cylinder(comment = "Castor Wheel",
color = Color("orange"),
material = Material("Plastic", "Nylon"),
diameter = diameter,
start = P(center.x, center.y - dy/2, center.z),
end = P(center.x, center.y + dy/2, center.z))
class Dual_Slot_Encoder(Part):
def __init__(self, up):
""" Dual Slot Encoder: initialize """
Part.__init__(self, up)
self.dual_slot_encoder_pcb_ = Dual_Slot_Encoder_PCB(self)
self.slot_interrupter1_ = slot_interrupter1 = Slot_Interrupter(self)
self.slot_interrupter2_ = slot_interrupter2 = Slot_Interrupter(self)
self.disk_offset_dy_l = L(mm=3)
self.center_p = P()
def configure(self, center = None):
""" Dual Slot Encoder: configure """
assert isinstance(center, P)
self.center_p = center
def construct(self):
""" Dual Slot Encoder: construct """
disk_offset_dy = self.disk_offset_dy_l
dual_slot_encoder_pcb = self.dual_slot_encoder_pcb_
motor_assembly = self.up
slot_interrupter1 = self.slot_interrupter1_
slot_interrupter2 = self.slot_interrupter2_
center = self.center_p
x = center.x
y = center.y
z = center.z
dual_slot_encoder_pcb.configure(
center = P(center.x, center.y, center.z))
slot_interrupter1.configure(center =
P(x + slot_interrupter1.dx_l/2, y + disk_offset_dy, z))
slot_interrupter2.configure(center =
P(x - slot_interrupter2.dx_l/2, y + disk_offset_dy, z))
#dual_slot_encoder_pcb.invisible_set()
class Dual_Slot_Encoder_PCB(Part):
""" Dual_Slot_Encoder_PCB: initialize """
def __init__(self, up):
Part.__init__(self, up)
self.diameter_l = L(mm=3.175)
self.dx_l = L(mm=50)
self.dy_l = L(mm=25)
self.dz_l = L(mm=1)
self.holes_pitch_dx_l = L(mm=40)
self.holes_pitch_dy_l = L(mm=15)
self.center_p = P()
def configure(self, center = None):
""" Dual_Slot_Encoder_PCB: configure """
assert isinstance(center, P)
self.center_p = center
def construct(self):
""" Dual_Slot_Encoder_PCB: construct """
diameter = self.diameter_l
dx = self.dx_l
dy = self.dy_l
dz = self.dz_l
center = self.center_p
x0 = center.x - dx/2
x1 = center.x + dx/2
y0 = center.y - dy/2
y1 = center.y + dy/2
z0 = center.z
z1 = center.z + dz
# Create the PCB:
z = L()
self.block(comment = "Dual_Slot_Encoders_PCB",
material = Material("fiberglass", "FR4"),
color = Color("green"),
corner1 = P(center.x - dx/2, y0, z0),
corner2 = P(center.x + dx/2, y1, z1),
top = "t")
# Drill the mounting holes:
hx0 = x0 + L(mm=5)
hx1 = x1 - L(mm=5)
hy0 = y0 + L(mm=5)
hy1 = y1 - L(mm=5)
holes = [(hx0, hy0, "SW"),
(hx0, hy1, "NW"),
(hx1, hy0, "SE"),
(hx1, hy1, "NE")]
for hole in holes:
x = hole[0]
y = hole[1]
text = hole[2]
#print("[{0}]: x={1} y={2}".format(text, x, y))
self.hole(comment = "{0} Mounting Hole".format(text),
diameter = diameter,
start = P(x, y, z1),
end = P(x, y, z0),
flags = "t")
class Encoder_Disk(Part):
def __init__(self, up):
""" *Encoder_Disk*: Initialization. """
Part.__init__(self, up)
self.diameter_l = diameter = L(mm=47) #L(mm=50)
radius = diameter / 2
self.actual_radius_l = actual_radius = radius - L(mm=0.75)
self.slot_inner_radius_l = actual_radius - L(mm=5.00)
self.slot_outer_radius_l = actual_radius - L(mm=0.50)
self.slots_count_i = 36
self.dy_l = L(mm=1.00)
self.y_center_l = L(0)
def configure(self, center = P()):
""" *Encoder_Disk*: Configuration. """
assert isinstance(center, P)
self.center_p = center
def construct(self):
""" *Encoder_Disk*: Construction. """
# Grab some values from *self*:
center = self.center_p
diameter = self.diameter_l
dy = self.dy_l
actual_radius = self.actual_radius_l
slots_count = self.slots_count_i
slot_inner_radius = self.slot_inner_radius_l
slot_outer_radius = self.slot_outer_radius_l
pi = Angle.PI
slot_length = slot_outer_radius - slot_inner_radius
slot_median_radius = slot_inner_radius + .75 * slot_length
slot_median_circumference = 2 * pi * slot_median_radius
# Basic concept behind an encoder disk is that it consists of a
# bunch of beam interrupter teeth interspersed with gaps between
# the teeth. The gaps are called slots and the non-gaps are
# called teeth. Ideally, the slot width is the same as the
# no tooth width. The way we think about the disk is that it
# has 4 places of interest
#
# * Slot center
# * Slot to tooth edge
# * Tooth center
# * Tooth to Slot edge.
#
# Ideally these locations are equidistant apart.
#
# The encoder consists of 2 IR (Infrared) slot interrupters
# with a rather narrow IR beam (.3mm) that can be occluded
# by an encoder disk tooth. What we want to ensure is that
# one IR beam is pointing at an edge and the other beam
# is pointing at either a tooth or a slot center. This will
# ensure that we get a nice quadrature signal out.
#
# Now we can go through the math. Let R be the radius from the disk
# center to the IR beam. The circumference of the IR beam circle
# is 2*PI*R. Let S be the number of slots (which happens to equal
# the number of teeth.) 2*PI*R/S is the approximate slot center
# to slot center distance. We divide this by 4 to get a slot
# center to edge distance. D = 2*PI*R/(4*S) = PI*R/(2*S). Let
# B be the distance between the beams. We need the following
# to be true:
#
# N*D ~= B, where N is odd (= 1, 3, 5, 7, 9, ...)
#
# In our particular case, R and B are fixed, so we can only
# adjust N and S. This means:
#
# N*D = B (1)
# N*PI*R/(2*S) = B (2)
# N*PI*R = 2*S*B (3)
# (N*PI*R)/(2*B) = S (4)
r = slot_median_radius = slot_inner_radius + .75 * slot_length
b = distance_between_slot_interrupter_beams = L(mm=3.50)
# = 3 # s = 30
n = 5 # s = 50
#n = 7 # s = ??
pi = math.pi
fractional_slots = (n * pi * r) / (2 * b)
self.slot_count_i = slots_count = int(round(fractional_slots))
print("b={0} r={1} n={2} frac_slots={3} slots_count={4}".
format(b, r, n, fractional_slots, slots_count))
# Grab *x*, *y*, and *z* from *center*
x = center.x
y = center.y
z = center.z
# Compute some y coordinates:
y0 = y - dy/2
y1 = y
y2 = y + dy/2
zero = L()
two_pi = Angle.TWO_PI
slot_angle = Angle(rad=two_pi) / slots_count
half_slot_angle = slot_angle / 2
#print("slot_angle={0} half_slot_angle={1}".
# format(slot_angle, half_slot_angle))
slot_contours = []
outer_contour = Contour(name = "Encoder Disk")
for slot_index in range(slots_count):
# Compute the angles for this iteration:
angle0 = slot_angle * slot_index
angle1 = angle0 + half_slot_angle
# Compute X/Y coordinates for the slot corners:
x0 = x + actual_radius.cosine(angle0)
z0 = z + actual_radius.sine(angle0)
x3 = x + actual_radius.cosine(angle1)
z3 = z + actual_radius.sine(angle1)
# Append (x,y) for the outer contour:
outer_contour.bend_append(P(x0, y0, z0), zero,
name="[{0}].xz0".format(slot_index))
outer_contour.bend_append(P(x3, y0, z3), zero,
name="[{0}].xz3".format(slot_index))
x0 = x + slot_outer_radius.cosine(angle0)
z0 = z + slot_outer_radius.sine(angle0)
x1 = x + slot_inner_radius.cosine(angle0)
z1 = z + slot_inner_radius.sine(angle0)
x2 = x + slot_inner_radius.cosine(angle1)
z2 = z + slot_inner_radius.sine(angle1)
x3 = x + slot_outer_radius.cosine(angle1)
z3 = z + slot_outer_radius.sine(angle1)
#print("[{0}]:angle0={1} angle1={2}".
# format(slot_index, angle0, angle1))
#print("[{0}]:x0={1} z0={2}".format(slot_index, x0, z0))
#print("[{0}]:x1={1} z1={2}".format(slot_index, x1, z1))
#print("[{0}]:x2={1} z2={2}".format(slot_index, x2, z2))
#print("[{0}]:x3={1} z3={2}".format(slot_index, x3, z3))
# Append a *slot_contour* to *slot_contours*:
slot_contour = Contour(name = "Encoder_Disk_Slot[{0}]".
format(slot_index))
slot_contour.bend_append(P(x0, y0, z0), zero,
name="[{0}].0".format(slot_index))
slot_contour.bend_append(P(x1, y0, z1), zero,
name="[{0}].1".format(slot_index))
slot_contour.bend_append(P(x2, y0, z2), zero,
name="[{0}].2".format(slot_index))
slot_contour.bend_append(P(x3, y0, z3), zero,
name="[{0}].2".format(slot_index))
slot_contours.append(slot_contour)
self.extrude(comment = "Encoder Disk",
material = Material("Plastic", "Derlin"),
color = Color("yellow"),
outer_contour = outer_contour,
inner_contours = slot_contours,
start = P(x, y0, z),
end = P(x, y2, z))
#diameter = L(inch=0.0890), # #2-56 close fit
self.hole(comment = "Screw_Hole",
diameter = L(mm=1.75), # Much tighter fit
start = P(x, y2, z),
end = P(x, y0, z),
flags = "t")
self.dxf_write(center = P(x, y1, z), plane_normal = P(0, L(mm=1), 0))
class Encoder_Mount(Part):
def __init__(self, up):
""" Encoder_Mount: initialize """
self.thick_l = up.thick_l
self.thin_l = up.thin_l
Part.__init__(self, up)
self.dx_l = L(mm=60)
self.dy_l = L(mm=35)
self.dz_l = self.thick_l
self.tongue_dx_l = L(mm=50)
self.center_p = P()
def configure(self, dx = None, dy = None, dz = None,
tongue_dx = None, center = None):
""" Encoder_Mount: configure """
none_type = type(None)
assert type(dx) == none_type or isinstance(dx, L)
assert type(dy) == none_type or isinstance(dy, L)
assert type(dz) == none_type or isinstance(dz, L)
assert type(tongue_dx) == none_type or isinstance(tongue_dx, L)
assert isinstance(center, P)
if isinstance(dx, L):
self.dx_l = dx
if isinstance(dy, L):
self.dy_l = dy
if isinstance(dz, L):
self.dz_l = dz
if isinstance(tongue_dx, L):
self.tongue_dx_l = tongue_dx
self.center_p = center
def construct(self):
""" Encoder_Mount: construct """
dx = self.dx_l
dy = self.dy_l
dz = self.dz_l
tongue_dx = self.tongue_dx_l
center = self.center_p
thick = self.thick_l
thin = self.thin_l
# Go get some related *Part*'s:
motor_assembly = self.up
dual_slot_encoder = motor_assembly.dual_slot_encoder_
dual_slot_encoder_pcb = dual_slot_encoder.dual_slot_encoder_pcb_