main
John Lauer
Review cumulative land candidates and correct complete STEP assembly clearance checks
ca3da55
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
#!/usr/bin/env python3
"""Nominal installed Adom fan harness. No cut-length or assembly release."""
from pathlib import Path
from step_geometry import load_step
import json,math,hashlib,shutil
import cadquery as cq
from glb_shape_helpers import read_glb,write_glb,add_shape
R=Path(__file__).resolve().parents[1];O=R/'mechanical/installed-fan-study';O.mkdir(exist_ok=True)
F=O/'source'
review=json.loads((R/'mechanical/carrier-study/review.json').read_text())
audit=json.loads((R/'mechanical/cooling-680-body-audit.json').read_text())
screen=json.loads((R/'mechanical/cooling-680-screen.json').read_text())
cx,cy=screen['sinkCenterXY'];fan_z=39.84
assert audit['boardSha256']==hashlib.sha256((R/'kicad/adom-custom-electronic-load.kicad_pcb').read_bytes()).hexdigest()
g,blob=read_glb(F/'fan-animated.glb')
c=math.sqrt(.5)
# Native XY into the board's MP1-anchored Z-up GLB frame. All translations metres.
g['nodes'][0]['matrix']=[c,-c,0,0,-c,-c,0,0,0,0,1,0,(cx-100)*.001,(100-cy)*.001,(fan_z+5.98)*.001,1]
root=len(g['nodes']);g['nodes'].append({'name':'Adom.InstalledFan.Connection','children':[],'extras':{'scope':'nominal custom trimmed harness; not factory termination or cut-length release'}});g['scenes'][g.get('scene',0)]['nodes'].append(root)
assy=cq.Assembly(name='Installed_fan_connection_NOMINAL');pieces=[]
def add(name,shape,color,scope):
rendered=shape.mirror('XZ').translate((-100,100,5.98))
add_shape(g,blob,rendered,name,color,root,scope)
assy.add(rendered,name=name.replace('.','_'),color=cq.Color(*color));pieces.append((name,shape))
def box(bounds):
x,y,z,X,Y,Z=bounds
return cq.Workplane('XY').box(X-x,Y-y,Z-z,centered=(False,False,False)).translate((x,y,z)).val()
lengths=[];wires=[];bend_radii=[]
for i,(signal,color)in enumerate([('5V',(.65,.035,.035)),('GND',(.04,.045,.05)),('FG',(.85,.65,.02))]):
z=fan_z+3+2.54*i;x=154.6-2.54*i
# Nominal exit inherited from the reusable component. Route outside sink and carrier.
pts=[(cx+5*c,cy+35*c,z),(146.5,96+i*1.5,z+1),(x,99.5+i*1.5,z-1),
(x+3,100+i*1.5,34),(x,99.5+i*1.5,25),(x,98,20),(x,98,16.54)]
edge=cq.Edge.makeSpline([cq.Vector(*p)for p in pts]);wire=cq.Wire.assembleEdges([edge]);tangent=edge.tangentAt(0)
shape=cq.Workplane(cq.Plane(origin=cq.Vector(*pts[0]),normal=tangent)).circle(.6).sweep(wire,isFrenet=True).val()
add('Fan.InstalledLead.'+signal,shape,color,'26 AWG UL1007; nominal 1.2 mm insulation OD and route; trim length requires physical fit')
points=[edge.positionAt(j/300) for j in range(301)];radii=[]
for a,b,cpt in zip(points,points[1:],points[2:]):
u=b-a;v=cpt-a;cross=u.cross(v).Length
if cross>1e-10:radii.append(u.Length*(cpt-b).Length*v.Length/(2*cross))
bend_radii.append(min(radii) if radii else None)
lengths.append({'sampledMinimumBendRadiusMm':bend_radii[-1],'circuit' :i+1,'signal':signal,'pathLengthMm':wire.Length(),'provisionalBlankLengthMm':math.ceil((wire.Length()+10)/5)*5,'allowanceMm':10,'endpointMm':pts[-1]});wires.append(shape)
# Nominal female housing seats on header body at z2.54; depth/contacts require mating validation.
housing=box([152.06-7.82/2,96.75,2.54,152.06+7.82/2,99.25,16.54])
for x in [154.6,152.06,149.52]:housing=housing.cut(box([x-.5,97.5,2.4,x+.5,98.5,16.7]))
add('Connector.M20-1060300.Housing',housing,(.055,.06,.065),'Adom-added Harwin housing; unpolarized; nominal mate to J9 M20-9990346')
for i,x in enumerate([154.6,152.06,149.52]):
contact=box([x-.425,97.575,6.54,x+.425,98.425,15.54]).cut(box([x-.325,97.675,6.4,x+.325,98.325,15.7]))
add(f'Connector.Contact.{i+1}',contact,(.7,.72,.74),'M20-1180046: simplified contact envelope, not detailed spring or crimp geometry')
# Full wire-to-wire checks and conservative fitted-body/probe checks, excluding intentional J9 mating.
wire_conflicts=[{'a':i+1,'b':j+1,'overlapMm3':a.intersect(b).Volume()}for i,a in enumerate(wires)for j,b in enumerate(wires)if j>i and a.intersect(b).Volume()>1e-6]
body_conflicts=[];probe_conflicts=[]
for name,shape in pieces:
for row in audit['rows']:
if row['ref']=='J9' and name.startswith('Connector.'):continue
v=shape.intersect(box(row['boundsMm'])).Volume()
if v>1e-6:body_conflicts.append({'part':name,'reference':row['ref'],'overlapMm3':v})
for p in screen['probeChecks']:
approach=cq.Solid.makeCylinder(2,75,cq.Vector(p['x'],p['y'],0))
if shape.intersect(approach).Volume()>1e-6:probe_conflicts.append({'part':name,'reference':p['ref']})
carrier=load_step(R/'mechanical/carrier-study/carrier-layout.step')
supports=[s for s in carrier.Solids() if s.BoundingBox().zmin < fan_z+5.98-0.01]
carrier_conflicts=[]
for i,wire in enumerate(wires):
w=wire.mirror('XZ').translate((-100,100,5.98))
volume=sum(w.intersect(s).Volume() for s in supports)
if volume>1e-6:carrier_conflicts.append({'circuit':i+1,'overlapMm3':volume})
swept=cq.Solid.makeCylinder(18.5,20,cq.Vector(cx,cy,fan_z))
rotor_conflicts=[{'circuit':i+1,'overlapMm3':w.intersect(swept).Volume()}for i,w in enumerate(wires)if w.intersect(swept).Volume()>1e-6]
assert all(s.isValid()for _,s in pieces)
write_glb(O/'installed-fan.glb',g,blob);assy.save(str(O/'installed-connection.step'))
for source,target in [('states.json','states.json'),('controller.mjs','controller.mjs'),('LICENSE','LICENSE')]:shutil.copyfile(F/source,O/target)
states=json.loads((O/'states.json').read_text());states['motion']['model']='installed-fan.glb';states['motion']['sha256']=hashlib.sha256((O/'installed-fan.glb').read_bytes()).hexdigest()
for state in states['states']:state['models']={'glb':'installed-fan.glb'};state.pop('image',None)
(O/'states.json').write_text(json.dumps(states,indent=2)+'\n')
report={'status' :'nominal-installed-harness-study','boardSha256':audit['boardSha256'],'fan':'MF40200V1-1000U-G99','sourceFanGlbSha256':hashlib.sha256((F/'fan-animated.glb').read_bytes()).hexdigest(),'connector':'M20-1060300','contacts':'3 x M20-1180046','header':'J9 M20-9990346','leadPreparation':'Custom trim/retermination of factory 305 ±10 mm leads; provisional lengths only; 3–4 mm contact strip requirement','routes':lengths,'wireConflicts':wire_conflicts,'bodyConflicts':body_conflicts,'probeConflicts':probe_conflicts,'carrierOrSinkEnvelopeConflicts':carrier_conflicts,'rotorSweptVolumeConflicts':rotor_conflicts,'validSolids':True,'rotorNode':'Fan.Rotor','animation':'Fan.Rotor.Revolution','limitations':['Fan body and rotor are Adom nominal geometry, not manufacturer CAD.','Nominal connector engagement and simplified contacts are not mating/crimp qualification.','Factory exit and 1.2 mm wire OD are illustrative; physical fit, bend radii, strain relief and service slack require validation.','Support checks exclude the nominal fan housing at the assumed lead exit; physical strain relief still needs validation.','No measured RPM, hardware I/O or fabrication release.']}
(O/'review.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report,indent=2))