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

BAT54C dual Schottky diode in a 3-pin SMD package, with two anodes and a shared cathode.

Version
1.0.14
License
unset
Stars
0

scripts/search-v5-prefix.mjs

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

const base=JSON.parse(fs.readFileSync("dist/index/circuit.json","utf8")).filter(e=>!String(e.type).endsWith("error"))
const trace=base.find(e=>e.type==="pcb_trace"&&e.pcb_trace_id==="source_net_26_mst1_0"),start=trace.route[0],join=trace.route[7],suffix=trace.route.slice(7)
const wire=(x,y,layer)=>({route_type:"wire",x,y,layer,width:0.1}),via=(x,y)=>({route_type:"via",x,y,from_layer:"inner1",to_layer:"top",via_diameter:0.45,via_hole_diameter:0.3})
const makeCircuit=(x,y,mode)=>{
 const prefix=mode===0?[{...start,width:0.1},wire(x,start.y,"top"),wire(x,y,"top"),via(x,y),wire(x,y,"inner1"),wire(join.x,join.y,"inner1")]
 :[{...start,width:0.1},wire(start.x,y,"top"),wire(x,y,"top"),via(x,y),wire(x,y,"inner1"),wire(join.x,join.y,"inner1")]
 const route=[...prefix,...suffix.slice(1)]
 return base.map(e=>e.type==="pcb_via"&&e.pcb_via_id==="pcb_via_14"?{...e,x,y}:e.type==="pcb_trace"&&e.pcb_trace_id===trace.pcb_trace_id?{...e,route}:e)
}
if(process.argv.length>=4){const errors=await runAllRoutingChecks(makeCircuit(Number(process.argv[2]),Number(process.argv[3]),Number(process.argv[4]??0)));console.log(errors.length);console.log(errors.map(e=>e.message).join("\n"));process.exit(0)}
let best={count:Infinity}
for(let x=-8;x<=-3+1e-9;x+=0.25)for(let y=-2;y<=3+1e-9;y+=0.25)for(let mode=0;mode<2;mode++){
 const cx=Number(x.toFixed(3)),cy=Number(y.toFixed(3)),errors=await runAllRoutingChecks(makeCircuit(cx,cy,mode));if(errors.length<best.count){best={count:errors.length,x:cx,y:cy,mode,errors};console.log("best",best.count,best.x,best.y,best.mode)}if(errors.length<=6){console.log(JSON.stringify({count:errors.length,x:cx,y:cy,mode}));console.log(errors.map(e=>e.message).join("\n"));process.exit(0)}
}
console.log(JSON.stringify(best,null,2))