-
Notifications
You must be signed in to change notification settings - Fork 11
/
partset.py
1476 lines (1309 loc) · 55.5 KB
/
partset.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
# ----------------------------------------------------------------------------
# -- Components
# -- parts_set library
# -- Python classes that creates useful sets of parts for FreeCAD
# ----------------------------------------------------------------------------
# -- (c) Felipe Machado
# -- Area of Electronic Technology. Rey Juan Carlos University (urjc.es)
# -- July-2018
# ----------------------------------------------------------------------------
# --- LGPL Licence
# ----------------------------------------------------------------------------
import FreeCAD
import Part
import logging
import os
import inspect
import Draft
import DraftGeomUtils
import DraftVecUtils
import math
# import copy;
# import Mesh;
# ---------------------- can be taken away after debugging
# directory this file is
filepath = os.getcwd()
import sys
# to get the components
# In FreeCAD can be added: Preferences->General->Macro->Macro path
sys.path.append(filepath)
# ---------------------- can be taken away after debugging
import kcomp # before, it was called mat_cte
import fcfun
import comps
import shp_clss
import fc_clss
import parts
from fcfun import V0, VX, VY, VZ
from fcfun import VXN, VYN, VZN
logging.basicConfig(level=logging.DEBUG,
format='%(%(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
class BearWashSet(fc_clss.PartsSet):
""" A set of bearings and washers, usually to make idle pulleys
Parameters:
-----------
metric : int
Metric (diameter) of the bolt that holds the set
axis_h : FreeCAD.Vector
vector along the cylinder height
pos_h : int
location of pos along axis_h (0,1,2,3)
0: pos is centered along its height
1: pos is at the base of the bearing
2: pos is at the base of the regular washer
3: pos is at the base of the large washer (this is the bottom)
axis_d : FreeCAD.Vector
vector perpendicular to the axis_h, along the radius
pos_d : int
location of pos along axis_d (0,1,2,3)
0: pos is centered at the cylinder axis
1: pos is at the bearing internal radius (defined by netric)
2: pos is at the bearing external radius
3: pos is at the large washer external radius
axis_w : FreeCAD.Vector
vector perpendicular to the axis_h and axis_d, along the radius
pos_w : int
location of pos along axis_w (0,1,2,3)
0: pos is centered at the cylinder axis
1: pos is at the bearing internal radius (defined by netric)
2: pos is at the bearing external radius
3: pos is at the large washer external radius
group : int
1: make a group
0: leave as individual components
pos : FreeCAD.Vector
Position of the cylinder, taking into account where the center is
Attributes:
-----------
metric : int or float (in case of M2.5) or even str for inches ?
Metric of the washer
pos_o : FreeCAD.Vector
Position of the origin of the shape
h_o : dictionary of FreeCAD.Vector
vectors from the origin to the different points along axis_h
d_o : dictionary of FreeCAD.Vector
vectors from the origin to the different points along axis_d
w_o : dictionary of FreeCAD.Vector
vectors from the origin to the different points along axis_w
h0_cen : int
d0_cen : int
w0_cen : int
indicates if pos_h = 0 (pos_d, pos_w) is at the center along
axis_h, axis_d, axis_w, or if it is at the end.
1 : at the center (symmetrical, or almost symmetrical)
0 : at the end
tot_h : float
Total height of the set: idler pulley
r_in : float
inner radius, the radius of the bearing
r_ext : float
external radius, the radius of the large washer
idler pulley without the washer for the bolt because it is between a holder,
The holder is in dots, not in the group
pos_o is at the center of symmetry: see o in the drawing
axis_h
: pos_h
...:...
: : bolt head
..........:.....:........
: Holder for the pulley group
....._________________...:
|_________________| 3 large washer
|_________| 2 regular washer
| | 1
| o | 0 bearing
|_________| -1
___|_________|___ -2 regular washer
....|_________________|.. -3 large washer
:
.........................: Holder for the pulley group
:.....: nut
:.: bolt shank
01 2 3 pos_d, pos_w
"""
# large washer (din9021) metric
lwash_m_dict = {3: 4, 4: 6}
# regular washer (din125) has the same metric as the pulley
# bearing type
bear_m_dict = {3: 603, 4: 624}
def __init__(self, metric,
axis_h, pos_h,
axis_d=None, pos_d=0,
axis_w=None, pos_w=0,
pos=V0,
group=1,
name=''):
default_name = 'bearing_idlpulley_m' + str(metric)
self.set_name(name, default_name, change=0)
fc_clss.PartsSet.__init__(self,
axis_d=axis_d, axis_w=axis_w, axis_h=axis_h)
# save the arguments as attributes:
frame = inspect.currentframe()
args, _, _, values = inspect.getargvalues(frame)
for i in args:
if not hasattr(self, i): # so we keep the attributes by CylHole
setattr(self, i, values[i])
try:
# lwash_m is the size (metric) of the large washer
self.lwash_m = self.lwash_m_dict[metric]
# bear_type is the type of bearing, such as 603, 624,...
self.bear_type = self.bear_m_dict[metric]
# lwash_dict is the dictionary with the dimensions of large washer
self.lwash_dict = kcomp.D9021[self.lwash_m]
# rwash_dict is the dictionary with the dimensions of regular washer
self.rwash_dict = kcomp.D125[metric]
# bear is the dictionary with the dimensions of the bearing
self.bear_dict = kcomp.BEARING[self.bear_type]
except KeyError:
logger.error('Bearing/washer key not found: ' + str(metric))
else:
# dimensions of each element
# height, along axis_h
self.lwash_h = self.lwash_dict['t'] # height (thickness)
self.lwash_r_out = self.lwash_dict['do'] / 2.
self.rwash_h = self.rwash_dict['t'] # height (thickness)
self.rwash_r_out = self.rwash_dict['do'] / 2.
self.bear_h = self.bear_dict['t'] # height (thickness)
self.bear_r_out = self.bear_dict['do'] / 2.
# total height:
self.tot_h = 2 * (self.lwash_h + self.rwash_h) + self.bear_h
# inner radius of the pulley, the radius of the bearing
self.r_in = self.bear_r_out
# external radius, the radius of the large washer
self.r_ext = self.lwash_r_out
# pos_h/d/w = 0 are at the center
self.h0_cen = 1
self.d0_cen = 1
self.w0_cen = 1
# the origin (pos_o) is at the center of symmetry
# vectors from o (orig) along axis_h, to the pos_h points
# h_o is a dictionary created in Obj3D.__init__
self.h_o[0] = V0
self.h_o[1] = self.vec_h(-self.bear_h / 2.)
self.h_o[2] = self.vec_h(-self.bear_h / 2. - self.rwash_h)
self.h_o[3] = self.vec_h(- self.bear_h / 2.
- self.rwash_h
- self.lwash_h)
self.d_o[0] = V0
if self.axis_d is not None:
self.d_o[1] = self.vec_d(-metric / 2.)
self.d_o[2] = self.vec_d(-self.bear_r_out)
self.d_o[3] = self.vec_d(-self.lwash_r_out)
elif pos_d != 0:
logger.error('axis_d not defined while pos_d != 0')
self.w_o[0] = V0
if self.axis_d is not None:
self.w_o[1] = self.vec_w(-self.metric / 2.)
self.w_o[2] = self.vec_w(-self.bear_r_out)
self.w_o[3] = self.vec_w(-self.lwash_r_out)
elif pos_w != 0:
logger.error('axis_w not defined while pos_w != 0')
# calculates the position of the origin, and keeps it in attribute
# pos_o
self.set_pos_o()
# creation of the bearing
bearing = fc_clss.BearingOutl(bearing_nb=self.bear_type,
axis_h=self.axis_h,
pos_h=0,
axis_d=self.axis_d,
axis_w=self.axis_w,
pos=self.pos_o,
# pos = rwash_b.get_pos_h(1),
name='idlpull_bearing')
self.append_part(bearing)
# creation of the bottom regular washer
rwash_b = fc_clss.Din125Washer(metric=metric,
axis_h=self.axis_h,
pos_h=1,
pos=bearing.get_pos_h(-1),
name='idlpull_rwash_bt')
self.append_part(rwash_b)
# creation of the bottom large washer
lwash_b = fc_clss.Din9021Washer(metric=self.lwash_m,
axis_h=self.axis_h,
pos_h=1,
pos=rwash_b.get_pos_h(-1),
name='idlpull_lwash_bt')
self.append_part(lwash_b)
# creation of the top regular washer
rwash_t = fc_clss.Din125Washer(metric=metric,
axis_h=self.axis_h,
pos_h=-1,
pos=bearing.get_pos_h(1),
name='idlpull_rwash_tp')
self.append_part(rwash_t)
# creation of the top large washer
lwash_t = fc_clss.Din9021Washer(metric=self.lwash_m,
axis_h=self.axis_h,
pos_h=-1,
pos=rwash_t.get_pos_h(1),
name='idlpull_lwash_tp')
self.append_part(lwash_t)
if group == 1:
self.make_group()
# doc = FreeCAD.newDocument()
# idle_pulley = BearWashSet( metric=3,
# axis_h = VZ, pos_h = 0,
# axis_d = None, pos_d = 0,
# axis_w = None, pos_w = 0,
# pos = V0,
# name = '')
class Din912BoltWashSet(fc_clss.PartsSet):
""" A din 912 bolt and a wahser set
Parameters:
-----------
metric : int (could be 2.5)
Metric (diameter) of the bolt
shank_l : float
length of the bolt, not including the head
the real length depends on shank_l_adjust
wide_washer : int
0: normal washer (default) din 125
1: wide washer din 9021
shank_l_adjust : int
0: shank length will be the size of the parameter shank_l
-1: shank length will be the size of the closest shorter or equal
to shank_l available lengths for this type of bolts
1: shank length will be the size of the closest larger or equal
to shank_l available lengths for this type of bolts
-2: shank length will be the size of the closest shorter or equal
to shank_l + washer thick available lengths for this type of bolts
available lengths for this type of bolts
2: shank length will be the size of the closest larger or equal
to shank_l + washer thick available lengths for this type of bolts
shank_out : float
0: default
distance to the end of the shank, just for positioning, it doesn't
change shank_l
I don't think it is necessary, but just in case
head_out : float
0: default
distance to the end of the head, just for positioning, it doesn't
change head_l
I don't think it is necessary, but just in case
axis_h : FreeCAD.Vector
vector along the bolt axis
axis_d : FreeCAD.Vector
vector along the radius, a direction perpendicular to axis_h
if head is hexagonal or the socket, it will point the direction of a
vertex
axis_w : FreeCAD.Vector
vector along the other radius, a direction perpendicular to axis_h
and axis_d
it is not necessary if pos_w == 0
It can be None
pos_h : int
location of pos along axis_h
0: top of the head, considering head_out,
1: position of the head not considering head_out
if head_out = 0, it will be the same as pos_h = 0
2: union of the head and the shank, beginning of the washer
3: end of the washer
4: where the screw starts, if all the shank is screwed, it will be
the same as pos_h = 2
5: end of the shank, not considering shank_out
6: end of the shank, if shank_out = 0, will be the same as pos_h = 5
6: top of the head, considering xtr_head_l, if xtr_head_l = 0
will be the same as pos_h = 0
pos_d : int
location of pos along axis_d (symmetric)
0: pos is at the central axis
1: radius of the shank
2: radius of the head
3: outer radius of the washer
pos_w : int
location of pos along axis_d (symmetric)
0: pos is at the central axis
1: radius of the shank
2: radius of the head
3: outer radius of the washer
axis_w : FreeCAD.Vector
vector perpendicular to the axis_h and axis_d, along the radius
pos_w : int
location of pos along axis_w (0,1,2,3)
0: pos is centered at the cylinder axis
1: pos is at the bearing internal radius (defined by netric)
2: pos is at the bearing external radius
3: pos is at the large washer external radius
group : int
1: make a group
0: leave as individual components
pos : FreeCAD.Vector
Position of the cylinder, taking into account where the center is
axis_h
:
: shank_r
:+
: :
: :
....6......... _:_:...................
shank_out+....5.........| : | : :
| : | + thread_l :
| : | : :
| : | : :
| : | : + shank_l
4 |.:.|....: :
| : | :
| : | :
.... 3 _______|_:_|_______ :
washer_thick : | :: : :: | :
:... 2 |______::_:_::______|..........:
| : | :
| ..:.. | + head_l
...1......| : : : | :
head_out+...0......|__:_:_:__|...............:.... axis_d
0 1 2 3
: : :
:....: :
: + :
: head_r :
: :
:.........:
+ washer_ro
"""
def __init__(self, metric,
shank_l,
wide_washer=0,
shank_l_adjust=0,
shank_out=0,
head_out=0,
axis_h=VZ,
axis_d=None, axis_w=None,
pos_h=0, pos_d=0, pos_w=0,
pos=V0,
group=1, # 1: make a group
name=''):
default_name = 'd912bolt_washer_m' + str(int(metric))
self.set_name(name, default_name, change=0)
fc_clss.PartsSet.__init__(self,
axis_d=axis_d, axis_w=axis_w, axis_h=axis_h)
frame = inspect.currentframe()
args, _, _, values = inspect.getargvalues(frame)
for i in args:
if not hasattr(self, i): # so we keep the attributes by CylHole
setattr(self, i, values[i])
self.bolt_dict = kcomp.D912[metric]
if wide_washer == 0:
self.washer_dict = kcomp.D125[metric]
else:
self.washer_dict = kcomp.D9021[metric]
self.washer_thick = self.washer_dict['t']
self.washer_do = self.washer_dict['do']
self.washer_ro = self.washer_do / 2.
if shank_l_adjust == 0:
self.shank_l = shank_l
else:
sh_l_list = self.bolt_dict['shank_l_list']
if shank_l_adjust == -1: # smaller closest to shank_l
self.shank_l = [sh_l for sh_l in sh_l_list if sh_l <= shank_l][-1]
elif shank_l_adjust == 1: # larger closest to shank_l
self.shank_l = [sh_l for sh_l in sh_l_list if sh_l >= shank_l][0]
elif shank_l_adjust == -2: # smaller closest to shank_l, washer
self.shank_l = [sh_l for sh_l in sh_l_list
if sh_l <= shank_l + self.washer_thick][-1]
elif shank_l_adjust == 2: # larger closest to shank_l + washer_thick
self.shank_l = [sh_l for sh_l in sh_l_list
if sh_l >= shank_l + self.washer_thick][0]
else:
logger.error('wrong value for parameter shank_l_adjust')
self.shank_l = shank_l
if self.bolt_dict['thread'] > self.shank_l:
self.thread_l = self.shank_l
else:
self.thread_l = self.bolt_dict['thread']
self.shank_r = self.metric / 2.
self.head_l = self.bolt_dict['head_l']
self.head_r = self.bolt_dict['head_r']
self.h0_cen = 0
self.d0_cen = 1 # symmetrical
self.w0_cen = 1 # symmetrical
self.tot_l = self.head_l + self.shank_l
# vectors from o (orig) along axis_h, to the pos_h points
# h_o is a dictionary created in Obj3D.__init__
self.h_o[0] = V0 # origin
self.h_o[1] = self.vec_h(head_out)
self.h_o[2] = self.vec_h(self.head_l)
self.h_o[3] = self.vec_h(self.head_l + self.washer_thick)
self.h_o[4] = self.vec_h(self.tot_l - self.thread_l)
self.h_o[5] = self.vec_h(self.tot_l - shank_out)
self.h_o[6] = self.vec_h(self.tot_l)
self.d_o[0] = V0
if not (self.axis_d is None or self.axis_d == V0):
# negative because is symmetric
self.d_o[1] = self.vec_d(-self.shank_r)
self.d_o[2] = self.vec_d(-self.head_r)
self.d_o[3] = self.vec_d(-self.washer_ro)
elif pos_d != 0:
logger.error('axis_d not defined while pos_d != 0')
self.w_o[0] = V0
if not (self.axis_w is None or self.axis_w == V0):
# negative because is symmetric
self.w_o[1] = self.vec_w(-self.shank_r)
self.w_o[2] = self.vec_w(-self.head_r)
self.w_o[3] = self.vec_w(-self.washer_ro)
elif pos_w != 0:
logger.error('axis_w not defined while pos_w != 0')
self.set_pos_o()
# creation of the bolt, at the origin self.pos_o:
bolt = fc_clss.Din912Bolt(metric=metric,
shank_l=self.shank_l,
shank_out=shank_out,
head_out=head_out,
axis_h=self.axis_h,
axis_d=self.axis_d,
axis_w=self.axis_w,
pos_h=0, pos_d=0, pos_w=0,
pos=self.pos_o)
self.append_part(bolt)
# creation of the washer, at the origin at pos_h = 2, and at the end
# of the washer, could use an if
if wide_washer == 0:
washer = fc_clss.Din125Washer(metric=metric,
axis_h=self.axis_h,
pos_h=-1, # base of cylinder
pos=self.get_pos_h(2))
else:
washer = fc_clss.Din9021Washer(metric=metric,
axis_h=self.axis_h,
pos_h=-1, # base of cylinder
pos=self.get_pos_h(2))
self.append_part(washer)
if group == 1:
self.make_group()
# boltwash = Din912BoltWashSet(metric = 3, shank_l = 20,
# wide_washer = 0,
# shank_l_adjust = 1, # 1: take the next larger size
# shank_out = 0,
# head_out = 0,
# axis_h = VZ,
# axis_d = None, axis_w = None,
# pos_h = 0, pos_d = 0, pos_w = 0,
# pos = V0)
class Din934NutWashSet(fc_clss.PartsSet):
""" A din 934 nut and a wahser set
Parameters:
-----------
metric : int (could be 2.5)
Metric (diameter) of the bolt
wide_washer : int
0: normal washer (default) din 125
1: wide washer din 9021
axis_d_apo : int
0: default: axis_d points to the vertex
1: axis_d points to the center of a side
axis_h : FreeCAD.Vector
vector along the bolt axis
axis_d : FreeCAD.Vector
vector along the first vertex, a direction perpendicular to axis_h
it is not necessary if pos_d == 0
It can be None, but if None, axis_w has to be None
vector along the radius, a direction perpendicular to axis_h
axis_w : FreeCAD.Vector
vector along the other radius, a direction perpendicular to axis_h
and axis_d
it is not necessary if pos_w == 0
It can be None
pos_h : int
location of pos along axis_h
0: at the base of the washer
1: end of the washer, beginning of the nut
2: end of the nut
pos_d : int
location of pos along axis_d (symmetric)
0: pos is at the central axis
1: radius of the hole
2: apotheme
3: circumradius
4: radius of the washer
pos_w : int
location of pos along axis_d (symmetric)
0: pos is at the central axis
1: radius of the hole
2: apotheme
3: circumradius
4: radius of the washer
group : int
1: make a group
0: leave as individual components
pos : FreeCAD.Vector
Position of the cylinder, taking into account where the center is
axis_h
:
: metric/2
:+
: :
: :
2 ____:____ :
| : | : | + head_l
| : | : | :
.... 1 ____|__:_:_:__|____ :
washer_thick : | : : : | :
:... 0 |_______:_:_:_______|...........axis_d
0 1 23 4
: : :
:....: :
: + :
: head_r :
: :
:.........:
+ washer_ro
"""
def __init__(self, metric,
wide_washer=0,
axis_d_apo=0,
axis_h=VZ,
axis_d=None, axis_w=None,
pos_h=0, pos_d=0, pos_w=0,
pos=V0,
group=1, # 1: make a group
name=''):
default_name = 'd934' + str(int(metric))
self.set_name(name, default_name, change=0)
fc_clss.PartsSet.__init__(self,
axis_d=axis_d, axis_w=axis_w, axis_h=axis_h)
frame = inspect.currentframe()
args, _, _, values = inspect.getargvalues(frame)
for i in args:
if not hasattr(self, i): # so we keep the attributes by CylHole
setattr(self, i, values[i])
self.nut_dict = kcomp.D934[metric]
self.nut_h = self.nut_dict['l']
self.nut_ro = self.nut_dict['circ_r']
# either or the next, not exact
# self.nut_apo = self.nut_dict['a2']/2.
self.nut_apo = self.nut_ro * 0.866 # cos 30
if wide_washer == 0:
self.washer_dict = kcomp.D125[metric]
else:
self.washer_dict = kcomp.D9021[metric]
self.washer_thick = self.washer_dict['t']
self.washer_do = self.washer_dict['do']
self.washer_ro = self.washer_do / 2.
self.h0_cen = 0
self.d0_cen = 1 # symmetrical
self.w0_cen = 1 # symmetrical
self.tot_h = self.nut_h + self.washer_thick
# vectors from o (orig) along axis_h, to the pos_h points
# h_o is a dictionary created in Obj3D.__init__
self.h_o[0] = V0 # origin
self.h_o[1] = self.vec_h(self.washer_thick)
self.h_o[2] = self.vec_h(self.washer_thick + self.nut_h)
self.d_o[0] = V0
if not (self.axis_d is None or self.axis_d == V0):
# negative because is symmetric
self.d_o[1] = self.vec_d(-metric / 2.)
self.d_o[2] = self.vec_d(-self.nut_apo)
self.d_o[3] = self.vec_d(-self.nut_ro)
self.d_o[4] = self.vec_d(-self.washer_ro)
elif pos_d != 0:
logger.error('axis_d not defined while pos_d != 0')
self.w_o[0] = V0
if not (self.axis_w is None or self.axis_w == V0):
# negative because is symmetric
self.w_o[1] = self.vec_w(-metric / 2.)
self.w_o[2] = self.vec_w(-self.nut_apo)
self.w_o[3] = self.vec_w(-self.nut_ro)
self.w_o[4] = self.vec_w(-self.washer_ro)
elif pos_w != 0:
logger.error('axis_w not defined while pos_w != 0')
self.set_pos_o()
# creation of the nut, at pos h = 1
nut = fc_clss.Din934Nut(metric=metric,
axis_d_apo=axis_d_apo,
axis_h=self.axis_h,
axis_d=self.axis_d,
axis_w=self.axis_w,
pos_h=-1, pos_d=0, pos_w=0,
pos=self.get_pos_h(1))
self.append_part(nut)
# creation of the washer, at the origin , and at the end
# of the washer, could use an if
if wide_washer == 0:
washer = fc_clss.Din125Washer(metric=metric,
axis_h=self.axis_h,
pos_h=-1, # base of cylinder
pos=self.pos_o)
else:
washer = fc_clss.Din9021Washer(metric=metric,
axis_h=self.axis_h,
pos_h=-1, # base of cylinder
pos=self.pos_o)
self.append_part(washer)
if group == 1:
self.make_group()
# nut_wash = Din934NutWashSet(metric =4,
# wide_washer = 0,
# axis_d_apo = 1,
# axis_h = VZ,
# axis_d = VX, axis_w = None,
# pos_h = 2, pos_d = 2, pos_w = 0,
# pos = V0,
# group = 1, # 1: make a group
# name = '')
class NemaMotorPulleySet(fc_clss.PartsSet):
"""
Set composed of a Nema Motor and a pulley
Number positions of the pulley will be after the positions of the motor
::
axis_h
:
:
_______:_______ .....11 <-> 5
|______:_:______|.....10 <-> 4
| : : |
| : : |........9 <-> 3
| : : |
___|__:_:__|___ .....8 <-> 2
|______:_:______|.....7 <-> 1
| : : |
| : : |
| : : |
|_____:o:_____|......6 <-> 0 (for the pulley)
: : :
: : :
0...56789.......axis_d, axis_w
|
01 23456 (for the pulley)
axis_h
:
:
2 ............................
| | :
| | + shaft_l
___|1|___............. :
_____|____0____|_____......:..circle_h.:
| :: 3 :: | :
| | :
| | :
| | + base_l
| | :
| | :
| | :
|__________4__________|.....:
: : :
: : :
: : :+ rear_shaft_l (optional)
:5: :
01...2..3..4.....:...........axis_d (same as axis_w)
| | | |
| | | v
| | | end of the motor
| | v
| | bolt holes
| V
| radius of the circle (cylinder)
v
radius of the shaft
axis_w
:
:
__________:__________.....
/ \....: chmf_r
| O O |
| _ |
| . . |
| ( ( ) ) |........axis_d
| . . |
| - |
| O O |
\_____________________/
: :
:.....................:
+
motor_w (same as d): Nema size in inches /10
pos_o (origin) is at pos_d=0, pos_w=0, pos_h=1
Parameters
----------
nema_size: dict
List of sizes defines in kcomps NEMA motor dimensions.
base_l: float,
Length (height) of the base
shaft_l: float,
Length (height) of the shaft, including the small cylinder (circle)
at the base
shaft_r: float,
Radius of the shaft, if not defined, it will take the dimension defined
in kcomp
circle_r: float,
Radius of the cylinder (circle) at the base of the shaft
if 0 or circle_h = 0 -> no cylinder
circle_h: float,
Height of the cylinder at the base of the shaft
if 0 or circle_r = 0 -> no cylinder
chmf_r: float,
Chamfer radius of the chamfer along the base length (height)
rear_shaft_l: float
Length of the rear shaft, 0 : no rear shaft
bolt_depth: float
Depth of the bolt holes of the motor
pulley_pitch: float/int
Distance between teeth: Typically 2mm, or 3mm
pulley_n_teeth: int
Number of teeth of the pulley
pulley_toothed_h: float
Height of the toothed part of the pulley
pulley_top_flange_h: float
Height (thickness) of the top flange, if 0, no top flange
pulley_bot_flange_h: float
Height (thickness) of the bot flange, if 0, no bottom flange
pulley_tot_h: float
Total height of the pulley
pulley_flange_d: float
Flange diameter, if 0, it will be the same as the base_d
pulley_base_d: float
Base diameter
pulley_tol: float
Tolerance for radius (it will subtracted to the radius)
twice for the diameter. Or added if a shape to subtract
pulley_pos_h : float
position in mm of the pulley along the shaft
* 0: it is at the base of the shaft
* -1: the top of the pulley will be aligned with the end of the shaft
axis_d: FreeCAD.Vector
Depth vector of coordinate system (perpendicular to the height)
axis_w: FreeCAD.Vector
Width vector of coordinate system
if V0: it will be calculated using the cross product: axis_h x axis_d
axis_h: FreeCAD.Vector
Height vector of coordinate system
pos_d: int
location of pos along the axis_d see drawing
* Locations coinciding with the motor
* 0: at the axis of the shaft
* 1: at the radius of the shaft
* 2: at the end of the circle(cylinder) at the base of the shaft
* 3: at the bolts
* 4: at the end of the piece
* Locations of the pulley
* 5: at the inner radius
* 7: at the external radius
* 7: at the pitch radius (outside the toothed part)
* 8: at the end of the base (not the toothed part)
* 9: at the end of the flange (V0 is no flange)
pos_w: int
location of pos along the axis_w see drawing
* Same locations of pos_d
pos_h: int
location of pos along the axis_h, see drawing
* 0: at the base of the shaft (not including the circle at the base
of the shaft)
* 1: at the end of the circle at the base of the shaft
* 2: at the end of the shaft
* 3: at the end of the bolt holes
* 4: at the bottom base
* 5: at the end of the rear shaft, if no rear shaft, it will be
the same as pos_h = 4
* 6: at the base of the pulley
* 7: at the base of the bottom flange of the pulley
* 8: at the base of the toothed part of the pulley
* 9: at the center of the toothed part of the pulley
* 10: at the end (top) of the toothed part of the pulley
* 11: at the end (top) of the pulley of the pulley
pos : FreeCAD.Vector
Position of the model
name: str
Object name
"""
def __init__(self,
# motor parameters
nema_size=17,
base_l=32.,
shaft_l=24.,
shaft_r=0,
circle_r=11.,
circle_h=2.,
chmf_r=1,
rear_shaft_l=0,
bolt_depth=3.,
# pulley parameters
pulley_pitch=2.,
pulley_n_teeth=20,
pulley_toothed_h=7.5,
pulley_top_flange_h=1.,
pulley_bot_flange_h=0,
pulley_tot_h=16.,
pulley_flange_d=15.,
pulley_base_d=15.,
pulley_tol=0,
pulley_pos_h=-1,
# general parameters
axis_d=VX,
axis_w=None,
axis_h=VZ,
pos_d=0,
pos_w=0,
pos_h=1,
pos=V0,
group=1,
name=''):
default_name = 'nema' + str(nema_size) + '_pulley_set'
self.set_name(name, default_name, change=0)
if (axis_w is None) or (axis_w == V0):
axis_w = axis_h.cross(axis_d)
fc_clss.PartsSet.__init__(self, axis_d=axis_d,
axis_w=axis_w, axis_h=axis_h)
# save the arguments as attributes:
frame = inspect.currentframe()
args, _, _, values = inspect.getargvalues(frame)
for i in args:
if not hasattr(self, i):
setattr(self, i, values[i])
# pos_w = 0 and pos_d are at the center, pos_h
self.d0_cen = 1 # symmetric
self.w0_cen = 1 # symmetric
self.h0_cen = 0
# creation of the motor, we don't know all the relative positions
# so we create it at pos_d=pos_w = 0, pos_h = 1
nema_motor = comps.PartNemaMotor(
nema_size=nema_size,
base_l=base_l,
shaft_l=shaft_l,
shaft_r=shaft_r,
circle_r=circle_r,
circle_h=circle_h,
chmf_r=chmf_r,
rear_shaft_l=rear_shaft_l,
bolt_depth=bolt_depth,
bolt_out=0,
cut_extra=0,
axis_d=self.axis_d,
axis_w=self.axis_w,
axis_h=self.axis_h,
pos_d=0,
pos_w=0,
pos_h=0,
pos=pos)
self.append_part(nema_motor)
nema_motor.parent = self
self.shaft_r = nema_motor.shaft_r
self.circle_r = nema_motor.circle_r
self.circle_h = nema_motor.circle_h