69 lines
4.1 KiB
Python
69 lines
4.1 KiB
Python
"""Illustrative PCB holder attached to 2020 rails; not a print-ready design."""
|
|
import math,time,traceback
|
|
from pathlib import Path
|
|
import FreeCAD as A, FreeCADGui as G, Part, Import
|
|
from pivy import coin
|
|
R=Path(__file__).resolve().parent.parent
|
|
O=R/'models'/'profile_mount_check'
|
|
V=A.Vector
|
|
source=A.openDocument(str(O/'Direct.FCStd'))
|
|
keep=['Motor','Holder','Magnet','PCB','Chip']+['PCBHead%d'%i for i in range(1,4)]+['Corner%d'%i for i in range(4)]+['Rail%d'%i for i in range(2)]+['MountM4_%d'%i for i in range(1,5)]
|
|
shape={n:source.getObject(n).Shape.copy() for n in keep}
|
|
support=source.getObject('Bracket').Shape.copy()
|
|
A.closeDocument(source.Name)
|
|
doc=A.newDocument('ProfileMountedEncoderOption')
|
|
def item(name,label,s,c,t=0):
|
|
o=doc.addObject('PartDesign::Feature',name);o.Label=label;o.Shape=s;o.ViewObject.ShapeColor=c;o.ViewObject.LineColor=(.1,.1,.1);o.ViewObject.Transparency=t;return o
|
|
cols={'Motor':(.3,.32,.35),'Holder':(.96,.55,.1),'Magnet':(.8,.8,.8),'PCB':(.04,.65,.19),'Chip':(.1,.1,.1)}
|
|
objects={}
|
|
for n in keep:
|
|
c=cols.get(n,(.84,.47,.13) if n.startswith('Corner') else (.55,.56,.6) if n.startswith('Rail') else (.78,.78,.78))
|
|
objects[n]=item(n,n,s=shape[n],c=c,t=70 if n=='Motor' else 20 if n.startswith('Corner') else 0)
|
|
# Preserve the original ring, PCB mounting bosses and positions; remove all
|
|
# four PCD50 feet, shims and fastening heads. Mount on the extrusion faces.
|
|
ring=support.common(Part.makeBox(100,100,3.2,V(-50,-50,10.9)))
|
|
face=38/math.sqrt(2)-6+20
|
|
bridge=Part.makeBox(face-16,6,3.2,V(16,5,10.9))
|
|
flange=Part.makeBox(3,22,12,V(face-3,-11,4))
|
|
# Vertical 9.5x5.5 slot; shaft is perpendicular to the 2020 inner face.
|
|
axis=V(1,0,0)
|
|
slot=Part.makeBox(3.04,5.5,4,V(face-3.02,-2.75,8))
|
|
for z in (8,12):slot=slot.fuse(Part.makeCylinder(2.75,3.04,V(face-3.02,0,z),axis))
|
|
flange=flange.cut(slot)
|
|
arm=bridge.fuse(flange).removeSplitter()
|
|
left=arm.mirror(V(),V(1,0,0))
|
|
holder=ring.fuse(arm).fuse(left).removeSplitter()
|
|
if holder.isNull() or not holder.isValid() or len(holder.Solids)!=1:raise RuntimeError('encoder support not a single valid solid')
|
|
h=item('NewHolder','Concept PCB ring - extrusion fasteners and vertical slots',holder,(.18,.47,.86))
|
|
# M4 illustration: 7x2.5 head and shank in flange; extrusion T nut is not modelled.
|
|
bolts=[]
|
|
for side in (1,-1):
|
|
head=Part.makeCylinder(3.5,2.5,V(face-5.5,0,10),axis)
|
|
shank=Part.makeCylinder(1.95,3.01,V(face-3.01,0,10),axis)
|
|
b=head.fuse(shank).removeSplitter()
|
|
if side<0:b=b.mirror(V(),V(1,0,0))
|
|
bolts.append(item('HolderBolt%d'%len(bolts),'M4 illustrative head, T-nut not modelled',b,(.8,.8,.8)))
|
|
doc.recompute()
|
|
targets=['Motor','Holder','Magnet','PCB','Chip']+['PCBHead%d'%i for i in range(1,4)]+['Corner%d'%i for i in range(4)]+['Rail%d'%i for i in range(2)]+['MountM4_%d'%i for i in range(1,5)]
|
|
res=[]
|
|
for n in targets:
|
|
other=objects[n]
|
|
if not h.Shape.BoundBox.intersect(other.Shape.BoundBox):continue
|
|
vol=h.Shape.common(other.Shape).Volume
|
|
if vol>0.0001:res.append((h.Name,other.Name,vol))
|
|
for b in bolts:
|
|
for o in [h]+[objects[n] for n in targets]:
|
|
if not b.Shape.BoundBox.intersect(o.Shape.BoundBox):continue
|
|
v=b.Shape.common(o.Shape).Volume
|
|
if v>.0001:res.append((b.Name,o.Name,v))
|
|
(O/'RailHolder_check.txt').write_text('Concept only. The original PCB position is retained (nominal sensor gap 1mm); no PCD50 shims are used.\nNew holder/bolt collisions >0.0001mm3:\n'+('\n'.join('%s / %s %.5f mm3'%r for r in res) if res else 'none in checked pairs')+'\n',encoding='utf8')
|
|
view=G.activeDocument().activeView()
|
|
def render(kind,name):
|
|
if kind=='top':view.viewTop()
|
|
else:view.getCameraNode().orientation.setValue(coin.SbRotation(0.880476,0.115917,-.279848,-.364705))
|
|
G.updateGui();time.sleep(.3);G.updateGui();view.fitAll();G.updateGui();time.sleep(.3);G.updateGui();view.saveImage(str(O/name),1600,1200,'White')
|
|
render('top','RailHolder_rear.png');render('axon','RailHolder_axon.png')
|
|
doc.recompute();doc.saveAs(str(O/'RailHolder.FCStd'))
|
|
Import.export([o for o in doc.Objects if hasattr(o,'Shape')],str(O/'RailHolder.step'))
|
|
(O/'RAIL_DONE.txt').write_text('success\n',encoding='utf8')
|