MustafaMulla29/rp2040-bldc-motor-controller-new
73×72 mm 4-layer USB‑C PD (5/9/15/20 V) RP2040 controller PCB with protected power switching, MCT8329A sensorless BLDC three-phase MOSFET bridge, USB data/programming, onboard controls, and three motor outputs feeding a 2212 motor through rigid bullet adapters.
- Version
- 0.3.100
- License
- unset
- Stars
- 0
assembly/full-assembly.test.tsx
import React from "react"
import {test,expect} from "bun:test"
import {Circuit} from "@tscircuit/core"
import FullAssembly from "./full-assembly"
import {selectSocketCad} from "./attachments"
import {usbConnections} from "./usb-connections"
const pcb=await Bun.file(new URL("../dist/index/circuit.json",import.meta.url)).json()
const c=new Circuit();c.add(<FullAssembly includeBoard={false} socketCad={selectSocketCad(pcb)} pcb={pcb}/>);await c.renderUntilSettled()
const json=c.getCircuitJson(), cables=json.filter(x=>x.type==="cad_cable")
test("PD assembly contains both USB cables and original motor leads, without battery parts",()=>{
expect(json.filter(x=>x.type.endsWith("_error"))).toHaveLength(0)
expect(cables).toHaveLength(5)
expect(cables.filter(x=>x.name.startsWith("MOTOR_LEAD_"))).toHaveLength(3)
expect(cables.filter(x=>x.name.startsWith("USB_"))).toHaveLength(2)
expect(json.filter(x=>x.type==="source_component"&& /BATTERY|PROBE|BALANCE/.test(x.name??""))).toHaveLength(0)
expect(json.filter(x=>x.type==="source_component"&&x.name?.startsWith("RIGID_ADAPTER_"))).toHaveLength(3)
const owners=json.filter(x=>x.type==="source_component").map(x=>x.source_component_id)
for(const cable of cables){expect(owners).toContain(cable.from_source_component_id);expect(owners).toContain(cable.to_source_component_id)}
})
test("USB destinations correspond to compiled power and data nets",()=>{
const mapping={"J19":"VBUS_RAW","J1":"PROG_VBUS"}
for(const [ref,net] of Object.entries(mapping)){
const owner=pcb.find((x:any)=>x.type==="source_component"&&x.name===ref)
const port=pcb.find((x:any)=>x.type==="source_port"&&x.source_component_id===owner.source_component_id&&x.pin_number===15)
expect(pcb.find((x:any)=>x.type==="source_net"&&x.subcircuit_connectivity_map_key===port.subcircuit_connectivity_map_key).name).toBe(net)
}
const usb=usbConnections(pcb)
expect(usb[0].from.position.y-usb[1].from.position.y).toBeGreaterThan(12)
for(const connection of usb){
const cable=cables.find(x=>x.name===connection.name)!
expect(cable.cableprinter_string).toBe("usb_c")
expect(connection.from.direction).toEqual({x:-1,y:0,z:0})
expect(connection.from.position.z).toBeCloseTo(2.4)
}
})