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/search-specific-component.mjs
import fs from "node:fs"
import { runAllRoutingChecks } from "@tscircuit/checks"
const componentId = process.argv[2]
const radius = Number(process.argv[3] ?? 0.8)
const step = Number(process.argv[4] ?? 0.1)
if (!componentId) throw new Error("usage: node search-specific-component.mjs <pcb_component_id> [radius] [step]")
const circuit = JSON.parse(fs.readFileSync("dist/index/circuit.json", "utf8"))
.filter((element) => !String(element.type).endsWith("error"))
const portIds = new Set(circuit
.filter((element) => element.type === "pcb_port" && element.pcb_component_id === componentId)
.map((element) => element.pcb_port_id))
const shift = (dx, dy) => circuit.map((element) => {
if (element.pcb_component_id === componentId &&
typeof element.x === "number" && typeof element.y === "number") {
return { ...element, x: element.x + dx, y: element.y + dy }
}
if (element.type === "pcb_component" && element.pcb_component_id === componentId) {
return { ...element, center: { x: element.center.x + dx, y: element.center.y + dy } }
}
if (element.type !== "pcb_trace") return element
return {
...element,
route: element.route.map((point) =>
portIds.has(point.start_pcb_port_id) || portIds.has(point.end_pcb_port_id)
? { ...point, x: point.x + dx, y: point.y + dy }
: point),
}
})
const originalErrors = await runAllRoutingChecks(circuit)
let best = { count: originalErrors.length, dx: 0, dy: 0, errors: originalErrors }
console.log(`start\t${best.count}`)
for (let dx = -radius; dx <= radius + 1e-9; dx += step) {
for (let dy = -radius; dy <= radius + 1e-9; dy += step) {
if (Math.abs(dx) < 1e-9 && Math.abs(dy) < 1e-9) continue
let errors
try {
errors = await runAllRoutingChecks(shift(Number(dx.toFixed(3)), Number(dy.toFixed(3))))
} catch {
continue
}
if (errors.length < best.count) {
best = { count: errors.length, dx, dy, errors }
console.log(`best\t${best.count}\t${dx.toFixed(3)},${dy.toFixed(3)}`)
}
}
}
console.log(`winner\t${best.count}\t${best.dx.toFixed(3)},${best.dy.toFixed(3)}`)
console.log(best.errors.map((error) => error.message).join("\n"))