tools/epro2/kicad: fix two structural ERC bugs — wire_dangling -88%, pin_not_connected -52%
Bisect found two semantics mismatches between EPRO2 and KiCad that cause the 850 real-connectivity ERC violations on the ESP-VoCat ref project: 1. sym_writer was emitting lib coords without negating Y, but KiCad lib uses Y-up and re-flips Y on placement (Y-down schematic). So vertically arranged pins ended up at Y-mirrored absolute positions and wires that reach the geometric pin tip in EPRO2 missed the rendered pin tip in KiCad. Fix: lib_y = -epro2_y, lib_rot = (360 - rot) % 360 for pin/text. 2. sch_writer was treating each LINE as an isolated wire — but EPRO2 binds segments into nets by NAME (WIRE.NET attr), not just geometry. Multi-segment nets like GND/VBUS show up as N disconnected stubs to KiCad. Fix: per-LINE, look up lineGroup → WIRE → NET attr and emit a `(label "<NET>")` at the LINE's start. Same-named labels on distinct physical wires is how KiCad's ERC recognizes a multi-segment net. ESP-VoCat 9 sheets: wire_dangling 444 → 52 (-88%) pin_not_connected 406 → 196 (-52%) real connectivity total 850 → 248 (-71%) Why we did NOT round to grid (the obvious-looking fix): EPRO2 places some pins on a 10-mil pitch (e.g. magnetic socket); rounding to KiCad's default 50-mil ERC grid would collapse those pins. The 248 residual is fundamentally cross-sheet — single-sheet ERC can't see a net's other endpoints on sibling sheets — and is a Phase-3 (hierarchical sheet) problem, not a per-sheet one. 41 → 46 unit tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,7 @@ class WriteStats:
|
||||
junctions: int = 0
|
||||
symbol_placements: int = 0
|
||||
text: int = 0
|
||||
labels: int = 0
|
||||
skipped: int = 0
|
||||
lib_symbols_embedded: int = 0
|
||||
lib_symbols_missing: int = 0
|
||||
@@ -92,6 +93,14 @@ def write_sch_page(
|
||||
elements: list = []
|
||||
|
||||
# 1. Wires from LINE primitives. Each LINE contributes one (wire ...).
|
||||
# EPRO2 binds wires into nets by NAME (WIRE.NET attr), not just geometry,
|
||||
# so we also emit a (label "<NET>") at one endpoint of each named LINE.
|
||||
# Same-named labels on physically distinct LINEs are how KiCad's ERC
|
||||
# recognizes a multi-segment net — without them every LINE looks like a
|
||||
# dangling stub. We label per-LINE (not per-WIRE id) because a single
|
||||
# WIRE op may contain segments that don't share endpoints, and KiCad
|
||||
# flags any unlabeled segment in such a group as wire_dangling.
|
||||
wire_net_cache: dict[str, str | None] = {}
|
||||
for oid, obj in doc.objects.items():
|
||||
if obj.get("_type") != "LINE":
|
||||
continue
|
||||
@@ -111,6 +120,24 @@ def write_sch_page(
|
||||
])
|
||||
stats.wires += 1
|
||||
|
||||
wire_id = obj.get("lineGroup")
|
||||
if not wire_id:
|
||||
continue
|
||||
wid = str(wire_id)
|
||||
if wid not in wire_net_cache:
|
||||
wire_net_cache[wid] = (rel.attrs_dict(wid) or {}).get("NET")
|
||||
net = wire_net_cache[wid]
|
||||
if not net:
|
||||
continue
|
||||
elements.append([
|
||||
Sym("label"), str(net),
|
||||
[Sym("at"), x1, y1, 0],
|
||||
[Sym("effects"), [Sym("font"), [Sym("size"), 1.27, 1.27]],
|
||||
[Sym("justify"), Sym("left"), Sym("bottom")]],
|
||||
[Sym("uuid"), _new_uuid()],
|
||||
])
|
||||
stats.labels += 1
|
||||
|
||||
# 2. Symbol placements from COMPONENT ops. Body deferred to Phase 2 (lib_symbols).
|
||||
# For now we emit (symbol ...) entries that reference a placeholder lib_id.
|
||||
# KiCad will draw a red ? but the position + properties are correct.
|
||||
|
||||
Reference in New Issue
Block a user