mohan-bee/gimbal-one-budget-pcb
A 4-layer STM32-based gimbal controller PCB with an onboard LSM6DS3TR-C IMU, three DRV8313 3-phase motor drivers, protected 3S battery input, 3.3 V buck regulation, and SWD/UART control interfaces.
- Version
- 0.1.0
- License
- unset
- Stars
- 0
review-supplier-orientations.ts
PCB
Schematic
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "node:fs"
import { getPlatformConfig } from "@tscircuit/eval/platform-config"
import { analyzePcbPin1Location } from "@tscircuit/circuit-json-util"
// Retain the exact supplier library geometry used for orientation comparison.
const circuit=JSON.parse(readFileSync("dist/controller/circuit.json","utf8"))
const engine=getPlatformConfig().partsEngine!
const codes=JSON.parse(readFileSync("supplier-codes.json","utf8"))
mkdirSync("supplier-library",{recursive:true})
const parts=new Map<string,any>()
for(const s of circuit.filter((x:any)=>x.type==="source_component"&&x.manufacturer_part_number&&!x.name.startsWith("J_")&&x.name!=="L1"))parts.set(s.manufacturer_part_number,s)
const review:any[]=[]
for(const [mpn,s] of parts){
const file=`supplier-library/${mpn.replace(/[^a-zA-Z0-9_-]/g,"_")}.json`
try{
let json:any[]|undefined
if(existsSync(file)){
const cached=JSON.parse(readFileSync(file,"utf8"))
if(cached.find((x:any)=>x.type==="source_component")?.manufacturer_part_number?.toLowerCase()===mpn.toLowerCase())json=cached
}
if(!json){
json=await engine.fetchPartCircuitJson!({manufacturerPartNumber:mpn,supplierPartNumber:codes[mpn]??s.supplier_part_numbers?.jlcpcb?.[0]})
if(!json?.length)throw new Error("No exact supplier match")
writeFileSync(file,JSON.stringify(json,null,2))
}
const imported=json.find((x:any)=>x.type==="source_component")
if(imported?.manufacturer_part_number?.toLowerCase()!==mpn.toLowerCase())throw new Error(`MPN mismatch: ${imported?.manufacturer_part_number}`)
const pin1=analyzePcbPin1Location(json)
if(!pin1)throw new Error("No supplier pin-1 frame")
review.push({mpn,status:"supplier_frame_retrieved",file,pin1,designators:circuit.filter((x:any)=>x.type==="source_component"&&x.manufacturer_part_number===mpn).map((x:any)=>x.name)})
console.log(mpn,JSON.stringify(pin1))
}catch(e){review.push({mpn,status:"unresolved",reason:String(e)});console.log(mpn,String(e))}
writeFileSync("supplier-orientation-review.json",JSON.stringify(review,null,2))
}