main
John Lauer
Preserve exact geometry and request inputs behind service-access diagnostics
637355e
from pathlib import Path
import cadquery as cq,json,hashlib,copy
p=Path('/home/adom/project/adom-custom-electronic-load');d=p/'revisions/compact-r11/issue-1-copper';sha=lambda f:hashlib.sha256(f.read_bytes()).hexdigest()
solids=cq.importers.importStep(str(d/'board20-full.step')).solids().vals();inventory=[{'index':i,'name':'native-board-solid-'+str(i)} for i in range(len(solids))]
a=cq.Assembly.importStep(str(p/'revisions/compact-r11/sensor-access-offset-review/v8-mechanics.step'))
for name,obj in a.traverse():
if obj.obj:
for s in obj.obj.located(obj.loc).Solids():inventory.append({'index':len(solids),'name':name});solids.append(s)
out=d/'board20-access-assembly.step';cq.exporters.export(cq.Compound.makeCompound(solids),str(out))
# STEP round-trip solid ordering must match the input inventory before exclusions.
rt=cq.importers.importStep(str(out)).solids().vals();assert len(rt)==len(solids)
for a,b in zip(solids,rt):
assert abs(a.Volume()-b.Volume())<1e-4
assert (a.Center()-b.Center()).Length<1e-4
(d/'board20-access-solid-inventory.json').write_text(json.dumps(inventory,indent=2)+'\n')
idx={r['name']:r['index']for r in inventory}
def motion(zs,segments):return {'axis':[0,0,1],'pointsMm':[[32,46.5,z]for z in zs],'toolSegments':segments}
shaft=[{'fromMm':-50,'toMm':0,'radiusMm':2},{'fromMm':-90,'toMm':-50,'radiusMm':12.5}]
excluded=[{'index':idx['Heatsink_NTC_M3x4_screw'],'reason':'Target screw: modeled solid lacks the actual hex recess. Engagement is intentional; recess fit requires hardware verification.'}]
stages=[{'name':'approach','motions':[motion([-12,4.3],shaft)],'excludedSolids':excluded},{'name':'engagement','motions':[motion([4.3,4.5],shaft)],'excludedSolids':excluded},{'name':'withdrawal','motions':[motion([4.5,-12],shaft)],'excludedSolids':excluded},{'name':'extraction','motions':[motion([7.845,-12],[{'fromMm':-3,'toMm':0,'radiusMm':2.75},{'fromMm':0,'toMm':4,'radiusMm':1.5}])],'excludedSolids':excluded+[{'index':idx['Heatsink_base'],'reason':'Target threaded hole: extracted screw shaft intentionally overlaps modeled tap-drill cylinder; thread disengagement is not simulated. No separate tool clearance claim against excluded base.'}]}]
r={'schemaVersion':1,'units':'mm','board':{'path':'../../../aiflow/compact-r11/board-20.kicad_pcb','sha256':sha(p/'aiflow/compact-r11/board-20.kicad_pcb')},'assembly':{'path':out.name,'sha256':sha(out)},'clearanceMm':.2,'fasteners':[{'id':'heatsink-NTC-M3x4','stages':stages}],'scope':'Diagnostic native board plus existing cooling/sensor CAD. Missing fan/harness/scaffold/hand and lug-removal path; provisional tool. Explicit thread/recess contacts excluded. Not complete assembly acceptance.'}
(d/'board20-assembly-access-request.json').write_text(json.dumps(r,indent=2)+'\n');print('Wrote',len(solids),'solids')