ShiboSoftwareDev/nema8-20mm-dual-usbc-stepper-controller

A compact 4-layer USB‑C PD/data controller board using a CH32X035 MCU and TMC2209 driver to power and control a NEMA‑8 stepper motor, with 3.3‑V regulation, USB ESD/reverse-polarity/TVS protection, current sensing, and boot control.

Version
1.0.12
License
unset
Stars
0

scripts/test-final-route-repairs.mjs

import fs from "node:fs"
import { runAllRoutingChecks } from "@tscircuit/checks"

let circuit = JSON.parse(fs.readFileSync("dist/index/circuit.json", "utf8"))
  .filter((element) => !String(element.type).endsWith("error"))

const samePoint = (point, x, y) => Math.hypot(point.x - x, point.y - y) < 1e-5
const viaMoves = [
  ["pcb_via_53", 0.4072, 4.6301],
  ["pcb_via_75", -2.7599, 1.7044],
  ["pcb_via_89", -2.3924, -2.575],
]

for (const [viaId, x, y] of viaMoves) {
  const via = circuit.find((element) => element.type === "pcb_via" && element.pcb_via_id === viaId)
  if (!via) throw new Error(`Missing ${viaId}`)
  circuit = circuit.map((element) => {
    if (element.type === "pcb_via" && element.pcb_via_id === viaId) return { ...element, x, y }
    if (element.type !== "pcb_trace" || element.pcb_trace_id !== via.pcb_trace_id) return element
    return { ...element, route: element.route.map((point) => samePoint(point, via.x, via.y) ? { ...point, x, y } : point) }
  })
}

const vmEdgeTraceId = "source_trace_3__source_trace_4__source_trace_5__source_trace_6__source_trace_7__source_trace_8__source_trace_9__source_trace_10__source_trace_11_mst6_0"
circuit = circuit.map((element) => {
  if (element.type !== "pcb_trace" || element.pcb_trace_id !== vmEdgeTraceId) return element
  return { ...element, route: element.route.map((point) => point.x > 9.65 ? { ...point, x: 9.65 } : point) }
})

for (const viaId of ["pcb_via_48", "pcb_via_55"]) {
  const via = circuit.find((element) => element.type === "pcb_via" && element.pcb_via_id === viaId)
  if (!via) throw new Error(`Missing ${viaId}`)
  const x = via.x
  const y = 9.57
  circuit = circuit.map((element) => {
    if (element.type === "pcb_via" && element.pcb_via_id === viaId) return { ...element, x, y }
    if (element.type !== "pcb_trace" || element.pcb_trace_id !== via.pcb_trace_id) return element
    return { ...element, route: element.route.map((point) => samePoint(point, via.x, via.y) ? { ...point, x, y } : point) }
  })
}

const errors = await runAllRoutingChecks(circuit)
console.log(errors.length)
console.log(Object.entries(Object.groupBy(errors, (error) => error.type))
  .map(([kind, group]) => `${kind}\t${group.length}`).join("\n"))
console.log(errors.filter((error) => error.type !== "pcb_trace_warning")
  .map((error) => `${error.pcb_trace_id ?? error.pcb_via_id ?? ""}\t${error.message}`).join("\n"))
fs.writeFileSync("/tmp/nema8-final-repair-circuit.json", JSON.stringify(circuit))