forked from URJCMakerGroup/MakerWorkbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parts_new.py
2178 lines (1950 loc) · 92.2 KB
/
parts_new.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
import FreeCAD
import Part
import DraftVecUtils
import inspect
import logging
import fcfun
import kcomp
import NuevaClase
#import NuevaClase_b
from NuevaClase import Obj3D
#from NuevaClase_b import Obj3D
from fcfun import V0, VX, VY, VZ
from kcomp import TOL
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
# exec(open("parts_new.py").read())
class BareShaftHolder(Obj3D):
"""
Creates a shaft holder, similar to the sk component, but just the holder part
It may have a reinforcement
axis_h
:
:
:
cut_w
___::___ 3 _____ ............................
| || | | " |.. :
nut|:::||:::|head 2| O |..: bolt_m :
| || | |.."..| ..... :
| / \ | | | : :holder_h
| | | | 1| | - - : shaft_diam -: :
| \__/ | |.....| ....: :shaft_h :
| | | | : :
|________|...> 0|_____|....> axis_d.......:.........:
: o : axis_w : o :
:........: :.....:
+ +
holder_w holder_d
-1 0 1 -1 0 1 :it is simmetrical in axis_d
(not sim but almost)
o: is the position of the object
support reinforcement:
reinf_w: on the side of the head, positive axis_w
reinf_nw: on the side of the nut, negative axis_w
if there is support it will be 45 degrees from the shaft diameter
___ ___
| || |
nut|:::||:::|head
| || |
| / \ |
/ | | \
reinf_nw / \__/ \ reinf_w
/ \
/________________\...> axis_w
-2 -1 0 1 2
: :
:....:
shaft_h: it is 45 degrees
:.......:
holder_w
___::___ 3 _____ ............................
| || | | " |.. :
nut|:::||:::|head 2| O |..: bolt_m :
| || | | ."..| ..... :
| //\\ | |: | : :holder_h
| || || | 1|: | - - : shaft_diam -: :
| \\// | | ...:| ....: :shaft_h :
| | | | : :
|________|...> 0|_____|....> axis_d.......:.........:
: o : axis_w : o :
:........: :....2:
:: ::: ::
:: ::: sh_stop_d (if sh_stop ==2)
:: :::
sh_stop_in :: sh_stop_d_chmf
::
-2
sh_stop_d (if sh_stop == 1 or 2)
sh_stop = a stop for the shaft (or bearing)
0: no stop
1: normal stop (90 degre cut)
sh_stop_in: how much the inner radius is disminshed
sh_stop_d: how far it goes inside
sh_stop_d_chmf: how far the chamfer goes inside axis_d
Parameters
----------
shaft_diam : mm. positive, usually integer. Tolerance is appart
Diameter of the shaft to be hold.
Dont include tolerance, it is another parameter
holder_d : mm. positive float
Shaft holder depth (see drawing). SH8 and SH10 are 14mm
tbolt_m : mm. positive, integer or float
metric of the bolt (diameter of the shank).
Dont include tolerance, it is another parameter
holder_h : mm. positive float or 0
holder height, if 0, it will the minimum calculated height
holder_w : mm (milimiters). positive float or 0
holder width, if 0, it will the minimum calculated width
shaft_h : mm. positive float or 0
position of shaft center in axis_h, from bottom, if 0: minimum height
cut_w : mm. positive float (default 1mm)
width of of the upper separation cut
sh_tol : mm. positive float
tolerance added for the shaft radius (x2 for diam)
tbolt_tol = multipliying factor
tolerance multipliying the tightening bolt (radius of shank and head)
reinf_w : 0, 1
if it has a support on axis_w positive
It doesnt consider the extra on axis_w: xtr_w, and xtr_nw.
It considers xtr_nh, xtr_d and xtr_nd
reinf_nw : 0, 1
if it has a support on axis_w negative
nut : 0, 1
if 1, make also a hole for the nut
sh_stop : 0, 1, 2
if it has a stop for the shaft (or bearing)
0: no stop
1: with stop
2: with stop also at front (both back and front)
sh_stop_in: positive float or zero
How much the shaft radius is diminised by the stop
sh_stop_d: positive float or zero
How much the stop goes in. Not counting the chamfer, so
if zero, it still has the stop
sh_stop_d_chmf : positive float or zero
if >0 there will be a chamfer, going d inside
axis_d: FreeCAD Vector
Axis in direction of the shaft
axis_w: FreeCAD Vector
Axis perpendicular to axis_h and axis_d
axis_h: FreeCAD Vector
Axis along the cut, perpendicular to axis_d
xtr_d : float, >= 0
Extra depth, if there is an extra depth along axis_d
xtr_nd : float, >= 0
Extra depth, if there is an extra depth along axis_d.negative
xtr_w : float, >= 0
Extra width, if there is an extra width along axis_w
xtr_nw : float, >= 0
Extra width, if there is an extra width along axis_w.negative
xtr_h : float, >= 0
Extra height, if there is an extra height along axis_h
xtr_nh : float, >= 0
Extra height, if there is an extra height along axis_h.negative
pos_d : integer = 0,
Location of pos along axis_d. see drawing
pos_w : integer = 0,
Location of pos along axis_w. see drawing
pos_h : positive integer = 0,
Location of pos along axis_h. see drawing
pos : FreeCAD.Vector
Position, at the point defined by pos_d, pos_w and pos_h
"""
def __init__ (self, # BareShaftHolder
shaft_diam, # shaft diameter
holder_d = 14, # shaft holder depth (SH8 and SH10 are 14)
tbolt_m = 3, # metric of the bolt
holder_h = 0, # holder height, if 0, it will the minimum
holder_w = 0, # holder width, if 0, it will be the minimum width
shaft_h = 0, # position of shaft center, if 0: minimum height
cut_w = 1, # cut width of the upper separation
sh_tol = 0.3, # tolerance added for the shaft radius (0.6 for diam)
tbolt_tol = 1.1, # tolerance multiplied for the tightening bolt
reinf_w = 0, # if it has a support on axis_w
reinf_nw = 0, # if it has a support on axis_w negative
nut = 1, # if 1, make also a hole for the nut
sh_stop = 0, # no stop for the bearing or shaft
sh_stop_in = 0, # radius dimished by the stop
sh_stop_d = 0, # how long is the stop in axis_d
sh_stop_d_chmf = 0, # how long the chammfer goes insided
# extra lenght en each direction
axis_d = VY, axis_w = VX, axis_h = VZ,
xtr_d=0, xtr_nd=0, xtr_w=0, xtr_nw=0, xtr_h = 0, xtr_nh= 0,
pos_w = 0,
pos_d = 1,
pos_h=0,
pos = V0,
model_type=3, # to be printed (check)
child = 0, # if it is a child, its position will be defined first
# check with model type
name=None):
if child==0:
self.pos = FreeCAD.Vector(0,0,0)
else:
self.pos = pos
self.position = pos
if name is None:
name = 'bare_shaft' + str(shaft_diam) + '_holder'
NuevaClase.Obj3D.__init__(self, axis_d, axis_w, axis_h, name)
#NuevaClase_b.Obj3D.__init__(self, axis_d, axis_w, axis_h, name)
# 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])
# normal axes to print without support
self.prnt_ax = self.axis_d
# let's have a minimum distance to the end
self.min_dist_h = 1.
self.min_dist_w = 2.2 # in axis_w, from the shaft to the end
self.shaft_r = shaft_diam/2. # shaft radius
# minimum distance from the bottom to the shaft center
self.shaft_h_min = self.shaft_r + self.min_dist_h
if shaft_h == 0:
self.shaft_h = self.shaft_h_min
elif shaft_h < self.shaft_h_min:
logger.debug('Shaft height less than minimum: ' + str(shaft_h) <
'<' + str(self.shaft_h_min))
self.shaft_h = self.shaft_h_min
else:
self.shaft_h = shaft_h
# tightening bolt
if tbolt_m > 0:
# bolt din 912
self.tbolt_dict = kcomp.D912[tbolt_m]
self.tbolt_head_r = self.tbolt_dict['head_r']
self.tbolt_head_r_tol = self.tbolt_head_r*tbolt_tol
#tbolt_head_r_tol = self.tbolt_dict['head_r_tol'] #alternative
self.tbolt_head_l_tol = self.tbolt_dict['head_l']*tbolt_tol
# nut din 934
self.tnut_dict = kcomp.D934[tbolt_m]
# radius values are minimum, so making tolerance larger, using predefined
self.tnut_r_tol = max(self.tnut_dict['circ_r_tol'],
self.tnut_dict['circ_r']*tbolt_tol)
self.tnut_l_tol = self.tnut_dict['l_tol']
else:
self.tbolt_head_r = 0
self.tbolt_head_r_tol = 0
self.tbolt_head_l_tol = 0
# minimum total height
self.holder_h_min = (self.shaft_h + self.shaft_r + 2*self.min_dist_h
+ 2*self.tbolt_head_r)
if holder_h == 0:
self.holder_h = self.holder_h_min
elif holder_h < self.holder_h_min:
logger.debug('holder height less than minimum: ' + str(holder_h) +
'<' + str(self.holder_h_min))
self.holder_h = self.holder_h_min
else:
self.holder_h = holder_h
# minimum holder width (without reinforcement support)
self.holder_w_min = self.shaft_diam + 2* self.min_dist_w # x2: on each side
if holder_w == 0:
self.holder_w = self.holder_w_min
elif holder_w < self.holder_w_min:
logger.debug('holder width less than minimum: ' + str(holder_w) +
'<' + str(self.holder_w_min))
self.holder_w = self.holder_w_min
else:
self.holder_w = holder_w
# definition of which axis is symmetrical
self.h0_cen = 0
self.d0_cen = 1 # symmetrical
self.w0_cen = 1 # symmetrical (not really, but almost)
# vectors from the origin to the points along axis_h:
self.h_o[0] = V0
self.h_o[1] = self.vec_h(self.shaft_h)
self.h_o[2] = self.vec_h(self.shaft_h + self.shaft_r + self.min_dist_h +
self.tbolt_head_r)
self.h_o[3] = self.vec_h(self.holder_h)
# vectors from the origin to the points along axis_w:
self.w_o[0] = V0
self.w_o[1] = self.vec_w(-self.holder_w/2.) # AAA change this to be positive
if reinf_w == 1:
# shaft_h because is 45 degrees
self.w_o[2] = self.w_o[1] + self.vec_w(shaft_h)
else:
self.w_o[2] = self.w_o[1]
if reinf_nw == 1:
self.w_o[-2] = self.vec_w(-self.holder_w/2. - shaft_h)
#self.w_o[-2] = self.get_o_to_w(-1) + self.vec_w(-shaft_h)
else:
self.w_o[-2] = -self.w_o[1] #self.get_o_to_w(-1)
# vectors from the origin to the points along axis_d:
self.d_o[0] = V0
self.d_o[1] = self.vec_d(-self.holder_d/2.) ### AAA change this to put positive
# calculates the position of the origin, and keeps it in attribute pos_o
self.set_pos_o()
# Make the central box, without reinforcement
shp_box = fcfun.shp_box_dir_xtr(
box_w = self.holder_w,
box_d = self.holder_d,
box_h = self.holder_h,
fc_axis_h = self.axis_h,
fc_axis_d = self.axis_d,
cw=1, cd=1, ch=0,
xtr_d = xtr_d,
xtr_nd = xtr_nd,
xtr_w = xtr_w,
xtr_nw = xtr_nw,
xtr_h = xtr_h,
xtr_nh = xtr_nh,
pos=self.pos_o)
#pos=self.get_pos_dwh(0,0,0))
#fcfun.add_fcobj(shp_box,'box')
# check if there is reinforcement on any side
if reinf_w == 1 or reinf_nw == 1:
# make a big box
shp_box_reinf = fcfun.shp_boxdir_fillchmfplane(
box_w = self.holder_w + 2*self.shaft_h,
box_d = self.holder_d,
box_h = self.shaft_h,
axis_d = self.axis_d,
axis_w = self.axis_w,
axis_h = self.axis_h,
cw=1, cd=1, ch=0,
xtr_d = xtr_d, xtr_nd = xtr_nd,
xtr_w = 0, xtr_nw = 0,
xtr_h = 0, xtr_nh = xtr_nh + 2,
fillet = 0, # chamfer
radius = self.shaft_h,
plane_fill = self.axis_h,
both_planes = 0,
edge_dir = self.axis_d,
pos=self.pos_o)
#pos=self.get_pos_dwh(0,0,0))
#fcfun.add_fcobj(shp_box_reinf,'reinf')
# take away the bottom
shp_box_reinfcut_bot = fcfun.shp_box_dir_xtr(
box_w = self.holder_w + 2*self.shaft_h,
box_d = self.holder_d,
box_h = 2,
fc_axis_h = -self.axis_h,
fc_axis_d = self.axis_d,
fc_axis_w = self.axis_w,
cw=1, cd=1, ch=0,
xtr_d = xtr_d+1,
xtr_nd = xtr_nd+1,
xtr_w = 1+xtr_w,
xtr_nw = 1+xtr_nw,
xtr_h = xtr_nh + 2,
xtr_nh = 0, # axis_h has negative direction
pos=self.get_pos_dwh(0,0,0)+self.vec_h(-xtr_nh))
#fcfun.add_fcobj(shp_box_reinfcut_bot,'reinf_cutbot')
shp_box_reinf = shp_box_reinf.cut(shp_box_reinfcut_bot)
shp_box_reinf = shp_box_reinf.removeSplitter()
if reinf_w == 0 or reinf_nw == 0 : # take away the part
if reinf_nw == 0:
axis_w_tmp = - self.axis_w # cut the left part
else:
axis_w_tmp = self.axis_w #cut the right part
shp_box_reinfcut = fcfun.shp_box_dir_xtr(
box_w = self.holder_w/2. + self.shaft_h,
box_d = self.holder_d,
box_h = self.holder_h,
fc_axis_h = self.axis_h,
fc_axis_d = self.axis_d,
fc_axis_w = axis_w_tmp,
cw=0, cd=1, ch=0,
xtr_d = xtr_d+1,
xtr_nd = xtr_nd+1,
xtr_w = xtr_w,
xtr_nw = 0,
xtr_h = 1,
xtr_nh = xtr_nh+1,
pos=self.pos_o)
#pos=self.get_pos_dwh(0,0,0))
#fcfun.add_fcobj(shp_box_reinfcut,'reinfcut')
shp_box_reinf = shp_box_reinf.cut(shp_box_reinfcut)
shp_box_reinf = shp_box_reinf.removeSplitter()
#fcfun.add_fcobj(shp_box_reinf,'reinf')
shp_box = shp_box.fuse(shp_box_reinf)
shp_box = shp_box.removeSplitter()
# make the holes
holes = []
# shaft hole
if sh_stop == 0: # no stop
shp_shaft_hole = fcfun.shp_cylcenxtr(r=self.shaft_r + sh_tol,
h=self.holder_d,
normal=self.axis_d,
ch=1,
xtr_top=xtr_d +1,
xtr_bot=xtr_nd+1,
# position of the motor axis, at the top
pos=self.get_pos_h(1))
self.d_o[2] = V0
else: # stop
self.d_o[2] = - self.vec_w(self.holder_d-sh_stop_d) #AAA put positive
shp_shaft_hole = fcfun.shp_cylcenxtr(r=self.shaft_r + sh_tol,
h=self.holder_d-sh_stop_d,
normal=-self.axis_d,
ch=0,
xtr_top=0,
xtr_bot=xtr_d +1,
# position of the motor axis, at the top
pos=self.get_pos_dwh(1,0,1))
#fcfun.add_fcobj(shp_shaft_hole,'sh_hole')
# inner goes all the way, it will be merged
shp_shaft_innhole = fcfun.shp_cylcenxtr(r=self.shaft_r-sh_stop_in,
h=self.holder_d,
normal=self.axis_d,
ch=1,
xtr_top=xtr_d +1,
xtr_bot=xtr_nd+1,
# position of the motor axis, at the top
pos=self.get_pos_dwh(-1,0,1))
#fcfun.add_fcobj(shp_shaft_innhole,'inhole_chmf')
# if there is chamfer:
if sh_stop_d_chmf > 0:
pos_chmf = self.get_pos_dwh(-1,0,1) + self.vec_d(sh_stop_d)
shp_shaft_chmf = fcfun.shp_cylcenxtr(r=self.shaft_r + sh_tol,
h=sh_stop_d_chmf,
normal=self.axis_d,
ch=0,
xtr_top=0,
xtr_bot=0,
# position of the motor axis, at the top
pos=pos_chmf)
#fcfun.add_fcobj(shp_shaft_chmf,'chmf2')
shp_chmf_sphere = Part.makeSphere(self.shaft_r + sh_tol,
pos_chmf + self.vec_d(sh_stop_d_chmf))
#fcfun.add_fcobj(shp_chmf_sphere,'sphr')
shp_shaft_chmf = shp_shaft_chmf.cut(shp_chmf_sphere)
#shp_shaft_chmf = fcfun.shp_cir_fillchmf(shp_shaft_chmf,
#circen_pos=pos_chmf, fillet = 1, radius=sh_stop_d_chmf)
shp_shaft_chmf = shp_shaft_chmf.removeSplitter()
shp_shaft_hole = shp_shaft_hole.cut(shp_shaft_chmf)
shp_shaft_hole = shp_shaft_hole.removeSplitter()
#fcfun.add_fcobj(shp_shaft_hole,'chmf')
shp_shaft_hole = fcfun.fuseshplist([shp_shaft_hole, shp_shaft_innhole])
if sh_stop == 2: # front stop also
shp_front_stop = fcfun.shp_box_dir(
box_w = self.shaft_diam + 2*sh_tol,
box_d = sh_stop_d,
box_h = self.shaft_h-0.85*self.shaft_r,
fc_axis_h = self.axis_h,
fc_axis_d = - self.axis_d,
cw=1, cd=0, ch=0,
pos=self.get_pos_dwh(1,0,0))
shp_shaft_hole = shp_shaft_hole.cut(shp_front_stop)
#fcfun.add_fcobj(shp_shaft_hole,'shaft_hole')
holes.append(shp_shaft_hole)
# vertical cut
if cut_w > 0:
shp_vcut = fcfun.shp_box_dir_xtr(
box_w = cut_w,
box_d = self.holder_d,
box_h = self.get_h_ab(1,3).Length,
fc_axis_d = self.axis_d,
fc_axis_w = self.axis_w,
fc_axis_h = self.axis_h,
cw=1, cd=1, ch=0,
xtr_d = 1, xtr_nd = 1,
xtr_w = 0, xtr_nw = 0,
xtr_h = xtr_h + 1, xtr_nh = 0,
pos=self.get_pos_h(1))
#fcfun.add_fcobj(shp_vcut,'vcut')
holes.append(shp_vcut)
if tbolt_m > 0:
xtr_nonut = 0
if nut == 0:
# make the nut being outside, so it will not carve
xtr_nonut = 2* self.tnut_l_tol + xtr_nw # make the nut being outside
# add the bolt+nut hole
shp_bolt = fcfun.shp_boltnut_dir_hole(
r_shank = tbolt_m/2. * tbolt_tol,
l_bolt = self.holder_w + xtr_nonut,
r_head = self.tbolt_head_r_tol,
l_head = self.tbolt_head_l_tol,
r_nut = self.tnut_r_tol,
l_nut = self.tnut_l_tol,
hex_head=0,
xtr_head=xtr_w+1, xtr_nut=xtr_nw + 1,
supp_head=1, supp_nut=1,
headstart=1,
fc_normal = -self.axis_w,
fc_verx1 = self.axis_d, # hexagon is flat on axis_d
pos = self.get_pos_dwh(0,1,2))
#fcfun.add_fcobj(shp_bolt,'bolt')
holes.append(shp_bolt)
if nut == 0: # no nut
self.tnut_r_tol = 0
self.tnut_l_tol = 0
shp_holes = fcfun.fuseshplist(holes)
shp_motorholder = shp_box.cut(shp_holes)
shp_bracket = shp_motorholder.removeSplitter()
self.shp = shp_bracket
#super().create_fco()
#self.fco.Placement.Base = FreeCAD.Vector(0, 0, 0)
#self.fco.Placement.Base = self.position
#b_shaft_hold = BareShaftHolder(
# shaft_diam = 8,
# holder_d = 10, # shaft holder depth
# tbolt_m = 3, # metric of the tightening bolt
# holder_h = 0, # holder height, if 0, it will the minimum
# holder_w = 0, # holder width, if 0, it will be the minimum width
# shaft_h = 0, # position of shaft center, if 0: minimum height
# cut_w = 1, # cut width of the upper separation
# sh_tol = 0.3, # tolerance added for the shaft radius (0.6 for diam)
# tbolt_tol = 1.1, # tolerance multiplied for the tightening bolt
# reinf_w = 1, # if it has a support on axis_w
# reinf_nw = 0, # if it has a support on axis_w negative
# nut = 1, # if 1, make also a hole for the nut
# sh_stop = 1, # stop for the bearing or shaft
# sh_stop_in = 2, # radius dimished by the stop
# sh_stop_d = 2.5, # how long is the stop in axis_d
# sh_stop_d_chmf = 2, # how long the chammfer goes insided
# # extra lenght en each direction
# axis_d = VY, axis_w = VX, axis_h = VZ,
# xtr_d=0, xtr_nd=0, xtr_w=0, xtr_nw=0, xtr_h = 0, xtr_nh= 0,
# pos_w = 0,
# pos_d = -1,
# pos_h=0,
# pos = FreeCAD.Vector(3,4,5),
# model_type=3, # to be printed (check)
# name=None)
class EndLdScrewHolder(Obj3D):
"""
Creates the end of a linear stage based on a leadscrew and 2 shafts
axis_h
tbolt _____::_____ 6 6(central)
: ___::___ | || | ___::___7 7(side)
v | || | |:::::||:::::|4 | || |
head|:::||:::|nut | || | 5 nut|:::||:::|head 4(cen)-5(side)
| || | | / \ | | || |
| / \ | | / \ | | / \ |
| | | | | | 2 | | | | 3 | | 2(central)-3(side)
| \__/ | | \ / | | \__/ |
| | | \____/ | | |
____| |______| |______| |____ 1
| :: :: :: :: |
|_::_____________::__________________::____________::_|.0....> axis_w
o 1 2 3 4 5 6 7
: :
: : : :.................:
: : : : +
:....: :........: sh_w
+ +
sh_diam ldscrewbear_diam
axis_d
:
:
:
_____________________________________________________ 1 ....
| | : || : | | : || :| | : || : | | :
| O | : || : | O | : || :| O | : || : | O | 0 :+holder_d
|____|_:_||_:_|______|_:___||____:|______|_:_||_:_|___| -1 ....:
o :
midbbolt (if possible)
axis_h
_____::_____ 6
| || | ___::___
|:::::||:::::|6 | || |
| || | 5 nut|:::||:::| t_bolt
| / \ | | || |
| / 2 \ | | /3 \ |
| | ldscrew| | | | sh | | ..............
| \ / | | \__/ | :
continue | \____/ | | | :+ldscrew_h (2)
<- ...___| |______| |____.... :+sf_h (3)
:: :: :: | +base_h:
..::__________________::____________::_|...:0.....:
: :
:.......................:
+
bbolt_w
Parameters
----------
ldscrewbear_diam : mm. positive float (or integer)
leadscrew bearing diameter central holder, dont include tol
Dont include tolerance, it is another parameter
sh_diam : mm. positive, usually integer. Tolerance is appart
Diameter of the shaft to be hold.
Dont include tolerance, it is another parameter
holder_d : mm. positive float
Shaft holder depth (see drawing). SH8 and SH10 are 14mm
tbolt_m : mm. positive, integer or float
metric of the tightening bolt (diameter of the shank).
Dont include tolerance, it is another parameter
ldscrew_h : mm. positive float or 0
position of leadscrew center in axis_h, from bottom, if 0: minimum height
sh_h : mm. positive float or 0
position of shafts (sides) center in axis_h, from bottom,
if 0: minimum height
sh_w : mm. positive float
position of shafts (sides) center in axis_w, from center,
base_h : mm. positive float (or integer)
base holder height (see drawing). SH8 to SH12 are 6mm
bbolt_m : mm. positive, integer or float
metric of the base bolt (diameter of the shank).
Dont include tolerance, it is another parameter
bbolt_w : mm. positive float
position of base bolt at the end of axis_w, from center,
if 0: minimum distance
stop_bearing : 0 1 2
if the bearing has a stop, it will be just 1mm with chamfer
if 2, it will also have it at front, but just 1/3 of the radius,no chmf
axis_h: FreeCAD Vector
Axis along the axis of the motor
axis_d: FreeCAD Vector
Axis normal to surface where the holder will be attached to
axis_w: FreeCAD Vector
Axis perpendicular to axis_h and axis_d, symmetrical (not necessary)
pos_d : int
Location of pos along axis_d (0,1). Symmetrical
0: at the center
1: at the end
pos_w : int
Location of pos along axis_w (0,1,2,3,4,5,6,7). Symmetrical
0: at the center of symmetry
1: at the end of leadscrew holder
2: at the inner base bolt (if exists)
3: at the beginning of the shaft holder
4: at the center of the shaft
5: at the end of the shaft holder
6: at the end base bolt
7: at the end of the pieced
pos_h : int
Location of pos along axis_h (0,1,2,3, 4, 5 6, 7)
0: at the bottom
1: base height
2: leadscrew center
3: shaft (side)
4: tightening bolt of leadscrew
5: tightening bolt of shafts
6: top of leadscrew holder
7: top of shaft holder
pos : FreeCAD.Vector
Position of the piece
"""
def __init__ (self, #EndLdScrewHolder
ldscrewbear_diam, # leadscrew bearing diameter central holder, dont include tol
sh_diam, # shaft diameter (side holders), dont include toleran
holder_d = 14,# shaft holder depth (SH8 and SH10 are 14mm)
tbolt_m = 3, # metric of the tightening bolt, dont include toleran
base_h = 6, # height of the base. SH8 to SH12 are 6mm
ldscrew_h = 36, # pos of center of the leadscrew. if 0, min height
sh_h = 0, # pos of center of the shaft axis_h, if 0, same as ldscrew
sh_w = 40, # pos of center of the shaft axis_w
bbolt_m = 4, # metric of the tightening bolt, dont include toleran
bbolt_w = 0, # distance from center of the side bolts at the end
cut_w = 1, # cut width of the upper separation of shaft holders
sh_tol = 0.3, # tolerance added for the shaft/ld radius (0.6 for diam)
tbolt_tol = 1.1, # tolerance multiplied for the tightening bolt
stop_bearing = 1, # if bearing has a stop
axis_h=VZ,
axis_d=VX,
axis_w=VY,
pos_h=0, # 0: base
pos_d=0, # 0: center
pos_w=0, # 0: center of symmetry
pos=V0,
model_type=3, # to be printed
name=None):
self.pos = FreeCAD.Vector(0, 0, 0)
self.position = pos
if name is None:
name = 'ld' + str(ldscrewbear_diam) + '_sh' + str(sh_diam) + '_holder'
if axis_w is None or axis_w == V0:
axis_w = axis_h.cross(axis_d)
NuevaClase.Obj3D.__init__(self, axis_d, axis_w, axis_h, name)
#NuevaClase_b.Obj3D.__init__(self, axis_d, axis_w, axis_h, name)
# 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])
# normal axes to print without support
self.prnt_ax = self.axis_d
if tbolt_m > 0:
# bolt din 912
self.tbolt_dict = kcomp.D912[tbolt_m]
self.tbolt_head_r = self.tbolt_dict['head_r']
self.tbolt_head_r_tol = self.tbolt_head_r*tbolt_tol
#tbolt_head_r_tol = self.tbolt_dict['head_r_tol'] #alternative
self.tbolt_head_l_tol = self.tbolt_dict['head_l']*tbolt_tol
# nut din 934
self.tnut_dict = kcomp.D934[tbolt_m]
# radius values are minimum, so making tolerance larger, using predefined
self.tnut_r_tol = max(self.tnut_dict['circ_r_tol'],
self.tnut_dict['circ_r']*tbolt_tol)
self.tnut_l_tol = self.tnut_dict['l_tol']
else:
self.tbolt_head_r = 0
self.tbolt_head_r_tol = 0
self.tbolt_head_l_tol = 0
if bbolt_m > 0:
# bolt din 912
self.bbolt_dict = kcomp.D912[bbolt_m]
self.bbolt_head_r = self.bbolt_dict['head_r']
self.bbolt_shank_r_tol = self.bbolt_dict['shank_r_tol']
#self.bbolt_head_r_tol = self.bbolt_head_r*tbolt_tol
#tbolt_head_r_tol = self.tbolt_dict['head_r_tol'] #alternative
#self.tbolt_head_l_tol = self.tbolt_dict['head_l']*tbolt_tol
# nut din 934
#self.tnut_dict = kcomp.D934[tbolt_m]
# radius values are minimum, so making tolerance larger, using predefined
#self.tnut_r_tol = max(self.tnut_dict['circ_r_tol'],
#self.tnut_dict['circ_r']*tbolt_tol)
#self.tnut_l_tol = self.tnut_dict['l_tol'
else:
self.tbolt_head_r = 0
self.tbolt_head_r_tol = 0
self.tbolt_head_l_tol = 0
# definition of which axis is symmetrical
self.h0_cen = 0
self.d0_cen = 1 # symmetrical
self.w0_cen = 1 # symmetrical
# vectors from the origin to the points along axis_h:
self.h_o[0] = V0
self.h_o[1] = self.vec_h(base_h)
self.d_o[0] = V0
self.d_o[1] = self.vec_d(-holder_d/2.)
self.w_o[0] = V0
self.w_o[4] = self.vec_w(-sh_w)
obj3d_ldscrew_hold = BareShaftHolder(
shaft_diam = ldscrewbear_diam,
holder_d = holder_d, # shaft holder depth
tbolt_m = tbolt_m, # metric of the tightening bolt
holder_h = 0, # holder height, if 0, it will the minimum
holder_w = 0, # holder width, if 0, it will be the minimum width
shaft_h = ldscrew_h, # position of shaft center, if 0: minimum height
cut_w = cut_w, # cut width of the upper separation
sh_tol = sh_tol, # tolerance added for the shaft radius (0.6 for diam)
tbolt_tol = tbolt_tol, # tolerance multiplied for the tightening bolt
reinf_w = 0, # if it has a support on axis_w
reinf_nw = 0, # if it has a support on axis_w negative
nut = 1, # if 1, make also a hole for the nut
sh_stop = stop_bearing, # stop for the bearing or shaft
sh_stop_in = 1, # radius dimished by the stop
sh_stop_d = 1, # how long is the stop in axis_d
# 7 is the width of the bearing of k08
sh_stop_d_chmf = 3.5, # how long is the chamfer in axis_d
axis_d = self.axis_d,
axis_w = self.axis_w,
axis_h = self.axis_h,
xtr_d=0, xtr_nd=0, xtr_w=0, xtr_nw=0, xtr_h = 0, xtr_nh= 1,
pos_w = 0,
pos_d = pos_d,
pos_h=0,
pos = self.pos,
model_type=3, # to be printed (check)
child = 1,
name=None)
if ldscrew_h == 0: # it is the minimum height
self.ldscrew_h = obj3d_ldscrew_hold.get_o_to_h(1).Length
if sh_h == 0:
self.sh_h = self.ldscrew_h
self.h_o[2] = self.vec_h(self.ldscrew_h)
self.h_o[3] = self.vec_h(self.sh_h)
self.h_o[4] = obj3d_ldscrew_hold.get_h_ab(0,2)
self.h_o[6] = obj3d_ldscrew_hold.get_h_ab(0,3)
self.w_o[1] = self.vec_w(-obj3d_ldscrew_hold.get_o_to_w(1).Length)
shps_add = []
shps_add.append(obj3d_ldscrew_hold.shp)
#fcfun.add_fcobj(obj3d_ldscrew_hold.shp,'central')
# change the use of negative in sym AAA
for w_i in -4, 4:
obj3d_sh_hold = BareShaftHolder(
shaft_diam = sh_diam,
holder_d = holder_d, # shaft holder depth
tbolt_m = tbolt_m, # metric of the tightening bolt
holder_h = 0, # holder height, if 0, it will the minimum
holder_w = 0, # holder width, if 0, it will be the minimum width
shaft_h = self.sh_h, # position of shaft center, if 0: minimum height
cut_w = cut_w, # cut width of the upper separation
sh_tol = sh_tol, # tolerance added for the shaft radius (0.6 for diam)
tbolt_tol = tbolt_tol, # tolerance multiplied for the tightening bolt
reinf_w = 0, # if it has a support on axis_w
reinf_nw = 0, # if it has a support on axis_w negative
nut = 1, # if 1, make also a hole for the nut
axis_d = self.axis_d,
axis_w = self.axis_w * (w_i/(abs(w_i))),#get sign:change bolt head
axis_h = self.axis_h,
xtr_d=0, xtr_nd=0, xtr_w=0, xtr_nw=0, xtr_h = 0, xtr_nh= 1,
pos_w = 0,
pos_d = pos_d,
pos_h=0,
pos = self.get_o_to_w(w_i),
model_type=3, # to be printed (check)
child = 1,
name=None)
shps_add.append(obj3d_sh_hold.shp)
#fcfun.add_fcobj(obj3d_sh_hold.shp,'side')
# the minimum space is 3 * bbolt_head_r, so the center is at 1.5
# this has to be changed because is confusing.
# begin positive, it is a substraction
self.shholder = obj3d_sh_hold
o_to_w1 = obj3d_sh_hold.get_o_to_w(1)
self.w_o[3] = self.w_o[4] + obj3d_sh_hold.get_o_to_w(1)
# addition
self.w_o[5] = self.w_o[4] - obj3d_sh_hold.get_o_to_w(1)
self.h_o[5] = obj3d_sh_hold.get_h_ab(0,2)
self.h_o[7] = obj3d_sh_hold.get_h_ab(0,3)
# see if there is space in the middle
bbolt_space = self.dist_w_ab(3,5)
self.set_pos_o()
holes = []
if bbolt_space < 3*self.bbolt_head_r :
logger.debug('Not enough distance for a middle bolt: ' + str(bbolt_space) +
'<' + str(3*self.bbolt_head_r))
if bbolt_space < 0:
logger.debug('Negative space')
self.w_o[2]= self.w_o[0] # no bolts
else:
#self.w_o[2]= self.w_o[1] + self.vec_w(-1.5*self.bbolt_head_r)
self.w_o[2]= self.w_o[1] - self.get_w_ab(1,3)/2.
# base bolt holes
for w_i in -2, 2:
shp_hole = fcfun.shp_cylcenxtr(r=self.bbolt_shank_r_tol,
h=self.base_h,
normal=self.axis_h,
ch=0,
xtr_top=1,
xtr_bot=1,
pos=self.get_pos_dwh(0, w_i, 0))
holes.append(shp_hole)
# calculate the closest position for the external bolts:
bbolt_min_w = self.dist_w_ab(0,5) + 1.5*self.bbolt_head_r
if bbolt_w == 0:
# minimum distance
self.w_o[6] = self.w_o[5] + self.vec_w(-1.5*self.bbolt_head_r)
self.w_o[7] = self.w_o[5] + self.vec_w(-3*self.bbolt_head_r)
self.bbolt_w = self.dist_w_ab(0,6)
elif bbolt_w < bbolt_min_w:
logger.debug('Base bolt too close: ' + str(bbolt_w) +
'<' + str(bbolt_min_w))
self.w_o[6] = self.w_o[5] + self.vec_w(-1.5*self.bbolt_head_r)
self.w_o[7] = self.w_o[5] + self.vec_w(-3*self.bbolt_head_r)
self.bbolt_w = self.dist_w_ab(0,6)
else:
self.w_o[6] = bbolt_w
self.w_o[7] = self.w_o[5] + self.vec_w(-3*self.bbolt_head_r)
# making the external bolt holes
for w_i in -6, 6:
shp_hole = fcfun.shp_cylcenxtr(r=self.bbolt_shank_r_tol,
h=self.base_h,
normal=self.axis_h,
ch=0,
xtr_top=1,
xtr_bot=1,
pos=self.get_pos_dwh(0, w_i, 0))
holes.append(shp_hole)
self.tot_w = self.dist_w_ab(-7,7)
self.tot_d = self.holder_d
self.tot_h = max(self.dist_h_ab(0,7), self.dist_h_ab(0,6))
# making the base
shp_base = fcfun.shp_box_dir(box_w=self.tot_w,
box_d=self.tot_d,
box_h=self.base_h,
fc_axis_h=self.axis_h,
fc_axis_d=self.axis_d,
cw=1, cd=1, ch=0, pos=self.pos_o)
# cut the base in case the shaft/leadscrew are below the top of the base
for w_i in -4, 4:
shp_shhole = fcfun.shp_cylcenxtr(r=self.sh_diam/2.+self.sh_tol,
h=self.holder_d,
normal=self.axis_d,
ch=1,
xtr_top=1,
xtr_bot=1,
pos=self.get_pos_dwh(0, w_i, 3))
holes.append(shp_shhole)
shp_ldhole = fcfun.shp_cylcenxtr(r=self.ldscrewbear_diam/2.+self.sh_tol,
h=self.holder_d,
normal=self.axis_d,
ch=1,
xtr_top=1,
xtr_bot=1,
pos=self.get_pos_dwh(0, w_i, 2))
holes.append(shp_ldhole)
shp_baseholes = fcfun.fuseshplist(holes)
shp_base = shp_base.cut(shp_baseholes)
shp_base = shp_base.removeSplitter()
shps_add.append(shp_base)
shp_holder = fcfun.fuseshplist(shps_add)
# take away in case there is something at the bottom
shp_cleanbot = fcfun.shp_box_dir_xtr(box_w=self.tot_w,
box_d=self.tot_d,
box_h=2,
fc_axis_h=-self.axis_h,
fc_axis_d=self.axis_d,
cw=1, cd=1, ch=0,
xtr_w = 1, xtr_nw=1,
xtr_d = 1, xtr_nd=1,
xtr_h = 0, xtr_nh=0,
pos=self.pos_o)
shp_holder = shp_holder.cut(shp_cleanbot)
shp_holder = shp_holder.removeSplitter()
self.shp = shp_holder
super().create_fco()
# Need to set first in (0,0,0) and after that set the real placement.
# This enable to do rotations without any issue
self.fco.Placement.Base = FreeCAD.Vector(0, 0, 0)
self.fco.Placement.Base = self.position
obj3d = EndLdScrewHolder (
ldscrewbear_diam = 22, # leadscrew bearing diameter central holder, dont include tol
sh_diam = 8, # shaft diameter (side holders), dont include toleran
holder_d = 13,# shaft holder depth (SH8 and SH10 are 14mm)
tbolt_m = 3, # metric of the tightening bolt, dont include toleran
base_h = 8, # height of the base. SH8 to SH12 are 6mm
ldscrew_h = 28.4, # pos of center of the leadscrew. if 0, min height
sh_h = 0, # pos of center of the shaft axis_h, if 0, same as ldscrew
sh_w = 28.6, # pos of center of the shaft axis_w
bbolt_m = 4, # metric of the tightening bolt, dont include toleran
bbolt_w = 0, # distance from center of the side bolts at the end
cut_w = 1, # cut width of the upper separation of shaft holders