main
John Lauer
Continue larger cooler assembly with plugged-connector and rerouted fan-wire checks
63a5240
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
"""Board32 alternative assembly envelope check, not a fabrication release."""
from pathlib import Path
import hashlib,json,math
import cadquery as cq
from step_geometry import load_step
import sexp
R=Path(__file__).resolve().parents[1]
O=R/'mechanical/passive-assembly-study';O.mkdir(exist_ok=True)
audit_path=R/'checkpoints/board32-temperature-bound/passive-body-audit.json'
audit=json.loads(audit_path.read_text())
assert audit['boardSha256']==hashlib.sha256((R/'aiflow/run/board-32.kicad_pcb').read_bytes()).hexdigest()
def box(b):
x,y,z,X,Y,Z=b
return cq.Workplane('XY').box(X-x,Y-y,Z-z,centered=(False,False,False)).translate((x,y,z)).val()
def bounds(s):
b=s.BoundingBox();return [b.xmin,b.ymin,b.zmin,b.xmax,b.ymax,b.zmax]
def source_solids(rel):
# Invert the established display transform: mirror Y, then (-100,100,2.8).
return [s.translate((100,-100,-2.8)).mirror('XZ') for s in load_step(R/rel).Solids()]
sensor_path='mechanical/sensor-gh-study/sensor-candidate.step'
fan_path='mechanical/scaffold-stack-study/fan/installed-connection.step'
sensor=source_solids(sensor_path);harness=source_solids(fan_path)
assert len(sensor)==5 and len(harness)==7
# Move 0.5 mm toward +X and -Y to reserve room at both plugged headers.
sink_b=[112.5,19.5,7.25,188.5984,95.7,58.05];sink=box(sink_b)
rows=[]
for family,shapes,names in [('sensor',sensor,['body','lead1','lead2','GH housing','GH latch']),('fan harness',harness,['5V wire','GND wire','FG wire','M20 housing','contact1','contact2','contact3'])]:
for name,s in zip(names,shapes):
rows.append({'assembly':family,'part':name,'boundsMm':bounds(s),'sinkOverlapMm3':s.intersect(sink).Volume(),'sinkDistanceMm':s.distance(sink)})
cx,cy=138.636,67.118
def fan(z):
return cq.Workplane('XY').box(40,40,20,centered=(True,True,False)).rotate((0,0,0),(0,0,1),45).translate((cx,cy,z)).val()
old=fan(42);raised=fan(62.05)
# Dimension tolerances are only supplied for the loose M20 housing here.
plug_max=box([148.15-.15,96.75-.10,2.54,155.97+.15,99.25+.10,16.54+.20])
body_conflicts=[r['ref'] for r in audit['rows'] if r['ref']!='Q1' and sink.intersect(box([v+(-.5 if i<3 else .5) for i,v in enumerate(r['boundsMm'])])).Volume()>1e-6]
assert not body_conflicts
probes=[]
for fp in sexp.find(sexp.parse((R/'aiflow/run/board-32.kicad_pcb').read_text()),'footprint'):
props={p[1]:p[2] for p in sexp.find(fp,'property')}
if props['Reference'].startswith('TP'):
x,y=map(float,sexp.first(fp,'at')[1:3]);radial=math.hypot(max(sink_b[0]-x,0,x-sink_b[3]),max(sink_b[1]-y,0,y-sink_b[4]))
probes.append({'ref':props['Reference'],'sinkEdgeDistanceMm':radial,'clearAt2mmRadius':radial>=2})
assert len(probes)==13 and all(p['clearAt2mmRadius'] for p in probes)
result={'status':'isolated-candidate-not-adopted','boardSha256':audit['boardSha256'],
'inputs':{p:hashlib.sha256((R/p).read_bytes()).hexdigest() for p in [sensor_path,fan_path,str(audit_path.relative_to(R))]},
'sinkEnvelopeMm':sink_b,'boardBoundsMm':[98,26,166,102],
'offsetChangeMm':[.5,-.5,0],'fittedBodyConflictsWith0p5mmMargin':body_conflicts,'probeChecks':probes,
'existingAssemblyChecks':rows,'fan':{'currentBoundsMm':bounds(old),'currentSinkOverlapMm3':old.intersect(sink).Volume(),'raisedCandidateBoundsMm':bounds(raised),'raisedSinkGapMm':raised.distance(sink),'raiseMm':20.05,'requiredNewCarrier':True,'requiredNewHarness':True},
'fanPlugWithStatedHousingToleranceGapMm':plug_max.distance(sink),
'moduleEnvelopeWithoutSupportsMm':[98,19.5,-2.6,188.5984,102,82.05],
'limits':['Sink is a full solid envelope, not fin geometry. Intersections reject reuse under that conservative representation; actual fin channels are not checked.',
'The raised fan is only a clearance alternative; 4 mm gap does not establish airflow or natural convection.',
'Existing sensor and harness geometry are nominal earlier assembly studies; no new physical measurement or crimp qualification.',
'J11 mating plug and programming-tool access remain unresolved. Supports, guards, cables and workcell clearance are excluded from module envelope.',
'No PCB, BOM, thermal specification or acceptance evidence changed.']}
(O/'review.json').write_text(json.dumps(result,indent=2)+'\n')
assy=cq.Assembly(name='Passive_cooling_CLEARANCE_ONLY')
assy.add(sink,name='Sink_solid_envelope',color=cq.Color(.85,.6,.2,.25))
assy.add(raised,name='Raised_fan_solid_envelope',color=cq.Color(.2,.7,.7,.4))
assy.add(box([98,26,-1.6,166,102,0]),name='PCB_outline_envelope',color=cq.Color(.1,.35,.25))
for i,s in enumerate(sensor):assy.add(s,name=f'Existing_sensor_{i}',color=cq.Color(.3,.3,.3))
assy.save(str(O/'clearance-study.step'))
assert all(s.isValid() for s in load_step(O/'clearance-study.step').Solids())
print(json.dumps(result,indent=2))