aboutsummaryrefslogtreecommitdiff
path: root/knowledge/tooling/placement-check.md
diff options
context:
space:
mode:
authorLouis <louis@dnge.de>2026-11-11 10:08:41 +0100
committerLouis <louis@dnge.de>2026-11-11 10:08:41 +0100
commit2e433fcd0d1afadd8ab786dd30d7d4546bdee43d (patch)
treef2a5603703d56b08c1eaa672eaf529ec4b2cc3fa /knowledge/tooling/placement-check.md
downloadhw-toolchain-2e433fcd0d1afadd8ab786dd30d7d4546bdee43d.tar.gz
hw-toolchain: placer, routers and KiCad helpers for agent-driven hardware work
Rust placer (simulated annealing) and negotiated-congestion router for 2-layer KiCad boards, pnr.sh to place, route, DRC-check and install candidates, Python KiCad helpers, repo conventions (AGENTS.md) and the tool documentation under knowledge/. Konnect (KiCad MCP, AGPL) as a submodule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'knowledge/tooling/placement-check.md')
-rw-r--r--knowledge/tooling/placement-check.md58
1 files changed, 58 insertions, 0 deletions
diff --git a/knowledge/tooling/placement-check.md b/knowledge/tooling/placement-check.md
new file mode 100644
index 0000000..bfe3897
--- /dev/null
+++ b/knowledge/tooling/placement-check.md
@@ -0,0 +1,58 @@
+# Placement check
+
+`tools/placement_check.py` rates a KiCad board's component placement before routing. Use it after every placement change.
+
+## Run
+
+Needs KiCad's Python (for `pcbnew`). It reads the saved file, so the board can stay open in KiCad; save first.
+
+``` sh
+. tools/kicad_env.sh
+$KPY tools/placement_check.py board.kicad_pcb --pair U2:J2 --svg /tmp/overlay.svg
+rsvg-convert -w 1100 /tmp/overlay.svg -o /tmp/overlay.png # to look at it
+```
+
+Options:
+
+- `--ignore J3,...`: leave out parts whose long ratsnest lines would swamp the result, e.g. an off-board connector.
+- `--pair A:B[:max]`: courtyard gap between two parts that must sit close together, e.g. an Ethernet IC and its jack. With a maximum it is scored.
+- `--fill REGEX`: nets left out of the ratsnest. The default is GND-like names; nets with a copper zone are added automatically.
+- `--svg`: overlay with:
+ - courtyards (grey front, purple back);
+ - pads (green = fill net);
+ - ratsnest (blue);
+ - crossings (red circles);
+ - flagged parts (orange).
+- `--json`: all findings, for scripts.
+- `--apply-rotations OUT`: writes a copy with the suggested rotations. Turns that would hit another courtyard are never suggested.
+
+## What it checks
+
+- **Crossings** of ratsnest lines (MST per net, fill nets left out). On two layers each one costs a via or a detour.
+- **Length** of the ratsnest, total and per net class.
+- **Decoupling.** For every cap with one pad on a fill net:
+ - Its other pad must be within 3 mm of the nearest IC pin (a part with at least 4 pads) on the same net. Bulk caps (≥ 4.7 µF) get 8 mm and may also sit at an inductor or ferrite.
+ - Its ground pad must be within that limit + 2 mm of a ground pin of the same IC, as a proxy for the loop area.
+ - Each IC pin on a decoupled net must have a cap within 3 mm. Crystal nets are excluded.
+- **Rotation** of 2-pad parts: turns of 90/180/270° in place that cross less or shorten the ratsnest by more than 0.5 mm.
+- **Courtyards:** front and back overlaps, and THT pads inside another footprint's back courtyard. With `HW:DIN_Post` or `HW:DIN_Housing_<k>TE` on the board, that covers parts on housing posts, ribs and spacers ([DIN-rail board format](../topics/din-rail-format.md)).
+
+Score: 100, minus a penalty per finding, down to a minimum of 0:
+
+| Finding | Penalty |
+| ------------------- | ------------------------------------ |
+| crossing | 1 |
+| decoupling overshoot | 1 per mm, at most 5 per cap |
+| uncovered pin | 1 |
+| rotation suggestion | 2 |
+| courtyard conflict | 10 |
+| failed pair | 5 |
+
+## Reading the result
+
+- **Compare scores between variants of the same board;** the absolute number means little. Some crossings come from the pinout and no placement removes them, e.g. a swapped differential pair or a USB-C's two pad rows.
+- **Look at the overlay, not just the number.** The ratsnest is straight lines between pads, so it cannot see routing channels.
+- **Rotation suggestions cover only 2-pad parts.** For ICs and connectors, try the turns by hand.
+- `tools/placement_slots.py board.kicad_pcb slots.json [--out moved.kicad_pcb]` hill-climbs which part sits in which of a set of fixed slots (and which way it faces) against this checker's penalties. See the script's docstring for the format. It does not replace setting decoupling caps by hand: it can swap two caps out of pin order, because the ratsnest does not care.
+
+Related: [Placer](placer.md), [Rust router](rust-router.md).