molecule
ESC G431
Public Made by Adomby adom
Single-motor ESC for the drone test cell: STM32G431 + DRV8300 driving a 3-phase bridge of six BSC016N06NS MOSFETs, TPSM365 buck to 12 V, INA181 low-side current sense (25 mV/A, 131 A full-scale). Runs AM32. 64 x 74 mm, 4-layer.
main
John Lauer
Add local values, both-face contact leaders, J1 per-pin labels and MOSFET pin1 markers
181f6be
21d ago
from pathlib import Path
import json,uuid,math
D=Path(__file__).parent;ns={'__file__':str(D/'layout.py')};code=(D/'layout.py').read_text().split('# Reference association')[0];code=code.replace('max(.6,max(map(len,lines))*size*.82)','max(.2,max(map(len,lines))*size*.72)').replace('for gap in [.15,.3,.5','for gap in [.02,.05,.1,.15,.3,.5');exec(code,ns)
m=json.loads((D/'labels-v17.json').read_text());labels=ns['labels'];labels[:]=m['labels'];ns['leaders'][:]=m['leaders'];placed=ns['placed'];box,rotate,translate=ns['box'],ns['rotate'],ns['translate']
for k in placed:placed[k]=[]
for l in labels:
lines=l['text'].split('\n');w=max(.2,max(map(len,lines))*l['size']*.72);h=l['size']*1.35*len(lines);g=translate(rotate(box(-w/2,-h/2,w/2,h/2),-l.get('angle',0),origin=(0,0)),l['x'],l['y']);placed[l['layer']].append(g)
for l in m.get('contactLeaders',[]):placed[l['layer']].append(ns['LineString']([l['start'],l['mid'],l['end']]).buffer(.10))
initial=len(labels);initialleaders=len(ns['leaders']);missing=[]
for p in ns['parts']:
ref=p['ref']
if not ref.startswith(('C','R')) or ref.startswith('MC'):continue
if any(l.get('reference')==ref and 'value' in l.get('role','') for l in labels):continue
v=p['value'];v=v+('F' if ref.startswith('C') and v[-1:] in 'unp' else '')
good=False
for size in [.3,.2]:
if ns['close_label'](p,v,size,'near component value',allow_leader=True):good=True;break
if not good:missing.append(ref)
new=[]
for l in labels[initial:]:
new.append(f'(gr_text {json.dumps(l["text"])} (at {l["x"]} {l["y"]} {l.get("angle",0)}) (layer "F.SilkS") (uuid "{uuid.uuid5(uuid.NAMESPACE_URL,"value-v18"+json.dumps(l,sort_keys=True))}") (effects (font (size {l["size"]} {l["size"]}) (thickness {l["size"]*.15}))))')
for l in ns['leaders'][initialleaders:]:new.append(f'(gr_line (start {l["start"][0]} {l["start"][1]}) (end {l["end"][0]} {l["end"][1]}) (stroke (width 0.06) (type default)) (layer "F.SilkS") (uuid "{uuid.uuid5(uuid.NAMESPACE_URL,"valueleader"+json.dumps(l,sort_keys=True))}"))')
s=(D/'esc-g431-astra-silkscreen-v17.kicad_pcb').read_text();out=D/'esc-g431-astra-silkscreen-v18.kicad_pcb';out.write_text(s.rstrip()[:-1]+'\n'+'\n'.join(new)+'\n)\n');m.update(board=str(out),labels=labels,leaders=ns['leaders'],missingFrontValues=missing);(D/'labels-v18.json').write_text(json.dumps(m,indent=2));print('new',len(labels)-initial,'missing',missing)