Hole spacing to a fixed via measured from where it is, with its own drill
A fixed via sits anywhere, not on a cell centre, and may have a bigger drill than the router's via; checking hole spacing between cell centres with one drill let the flight controller's routed 0.2 mm via come 0.19 mm from a hand-placed 0.25 mm one. The board now carries each fixed via's drill (from KiCad's padstack name), and cells are checked against fixed vias exactly.
This commit is contained in:
@@ -23,6 +23,7 @@ the containment invariant, and pads are centre-symmetric in practice).
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
import re
|
||||
|
||||
from freeroute.dsn.model import DsnBoard
|
||||
from freeroute.dsn.shapes import Circle, Path, Polygon, Rectangle, Shape
|
||||
@@ -38,6 +39,9 @@ from .transform import CoordinateTransform
|
||||
|
||||
__all__ = ["build_board"]
|
||||
|
||||
# DSN units per micrometre, for drills KiCad gives in um in via padstack names
|
||||
_DSN_PER_UM = {"um": 1.0, "mm": 0.001, "mil": 1 / 25.4, "inch": 1 / 25400}
|
||||
|
||||
|
||||
def build_board(dsn: DsnBoard) -> BasicBoard:
|
||||
"""Construct a :class:`BasicBoard` from a parsed :class:`DsnBoard`."""
|
||||
@@ -503,10 +507,15 @@ def _insert_wiring(dsn: DsnBoard, board: BasicBoard, transform: CoordinateTransf
|
||||
location = transform.dsn_to_board_point(via.x, via.y)
|
||||
pad = _pad_tile(max(padstack.shapes, key=_shape_extent), transform)
|
||||
box = pad.bounding_box()
|
||||
drill = re.search(r"_([\d.]+):([\d.]+)_um", via.padstack)
|
||||
drill_board = (
|
||||
round(transform.dsn_to_board(float(drill.group(2)) * _DSN_PER_UM.get(dsn.unit, 1.0)))
|
||||
if drill else 0
|
||||
)
|
||||
board.insert(
|
||||
Via(
|
||||
net_nos=[numbers[via.net]], fixed=True, padstack_name=via.padstack,
|
||||
location=location, layers=sorted(layers or signal_layers),
|
||||
drill=drill_board, location=location, layers=sorted(layers or signal_layers),
|
||||
shape=IntBox(box.ll.x + location.x, box.ll.y + location.y,
|
||||
box.ur.x + location.x, box.ur.y + location.y),
|
||||
)
|
||||
|
||||
@@ -117,6 +117,8 @@ class Via(Item):
|
||||
#: layer indices the via's pads occupy, and the largest pad as a box
|
||||
layers: list[int] = field(default_factory=list)
|
||||
shape: object = None
|
||||
#: drill diameter in board units, when the padstack name gives it
|
||||
drill: int = 0
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -268,6 +268,8 @@ class GridRouter:
|
||||
self._via_nets: dict[Cell, dict[int, int]] = {} # routed via centres
|
||||
self._via_centres: list[IntPoint] | None = None # cache for _hole_clear_at
|
||||
self._fixed_vias: dict[Cell, int] = {}
|
||||
# fixed vias sit anywhere, not on cell centres: exact hole checks
|
||||
self._fixed_holes: list[tuple[IntPoint, int]] = []
|
||||
self._fixed_via_points: set[tuple[int, IntPoint]] = set()
|
||||
|
||||
if layers is None:
|
||||
@@ -301,6 +303,9 @@ class GridRouter:
|
||||
if isinstance(item, Via) and item.fixed and item.net_nos:
|
||||
self._fixed_vias[self._cell_of(item.location)] = item.net_nos[0]
|
||||
self._fixed_via_points.add((item.net_nos[0], item.location))
|
||||
# its own drill, from KiCad's padstack name (Via[0-3]_500:250_um)
|
||||
reach = self._via_drill // 2 + (item.drill or self._via_drill) // 2 + self._hole_gap
|
||||
self._fixed_holes.append((item.location, reach))
|
||||
# Through-hole pads have holes too, and a route changes layer at one
|
||||
# for free, so no via (of any net) goes within hole spacing of one.
|
||||
# The DSN has no drill for a pad; its smaller half size stands in.
|
||||
@@ -545,6 +550,12 @@ class GridRouter:
|
||||
and no through-hole pad's hole within reach at all."""
|
||||
if cell in self._tht_block:
|
||||
return False
|
||||
if self._fixed_holes:
|
||||
here = self._cell_center(cell)
|
||||
for loc, reach in self._fixed_holes:
|
||||
d = math.hypot(loc.x - here.x, loc.y - here.y)
|
||||
if d < reach and d > self.step: # beyond its own cell: too close
|
||||
return False
|
||||
if self._via_nets_at(cell) - {net_no}:
|
||||
return False
|
||||
cx, cy = cell
|
||||
|
||||
Reference in New Issue
Block a user