imrishabh18/rp2040-motor-controller

The circuit implements a powered USB interface with a W25Q16 flash memory chip, a RP2040 microcontroller, and AO3400A MOSFETs for switch control, enabling USB communication, memory storage, and device power management.

Version
1.0.19
License
unset
Stars
0

scripts/route-metrics.ts

import { readFileSync,writeFileSync } from 'node:fs';
import {checkSourceTracesMatchPcbTraceThickness} from '@tscircuit/checks';
const json:any[]=JSON.parse(readFileSync(process.argv[2]??'dist/index/circuit.json','utf8'));
const widths=checkSourceTracesMatchPcbTraceThickness(json);
const metrics=json.filter(e=>e.type==='source_trace'&&/^MOTOR_[AB]_(PLUS|MINUS)$/.test(e.name??'')).map(source=>{
 const traces=json.filter(e=>e.type==='pcb_trace'&&e.source_trace_id===source.source_trace_id);
 let length=0,area=0,nominal=0,min=Infinity,run=0,maxRun=0,vias=0;
 for(const t of traces){run=0;for(let i=0;i<t.route.length;i++){
   const a=t.route[i],b=t.route[i+1];if(a.route_type==='via')vias++;
   if(a.route_type!=='wire'||b?.route_type!=='wire'||a.layer!==b.layer){run=0;continue;}
   const d=Math.hypot(a.x-b.x,a.y-b.y),w=Math.min(a.width,b.width);length+=d;area+=d*w;min=Math.min(min,w);
   if(w>=.85-1e-6){nominal+=d;run=0;}else {run+=d;maxRun=Math.max(run,maxRun);}
 }}
 return {name:source.name,lengthMm:length,averageWidthMm:area/length,minWidthMm:min,atLeast085mmFraction:nominal/length,longestNarrowRunMm:maxRun,vias};
});
const result={widthWarnings:widths.length,underWidthTraceCount:new Set(widths.map(w=>w.pcb_trace_id)).size,motorTraces:metrics};
writeFileSync('reports/route-metrics.json',JSON.stringify(result,null,2));console.log(JSON.stringify(result,null,2));