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/api-probe.test.tsx

import React from "react"
import { expect, test } from "bun:test"
import { Circuit, assembly } from "@tscircuit/core"
import { assemblyCableProps, assemblyMotorProps } from "@tscircuit/props"

// Capability test only: the NEMA/JST example is not our motor or production PCB.
test("the documented motor-to-board cable resolves to real endpoints", async () => {
  const circuit = new Circuit()
  circuit.add(
    <assembly.device name="API_PROBE">
      <assembly.motor name="MOTOR" standard="nema17" wireConnection="jst-ph-6" />
      <board name="CONTROLLER" width={44} height={34} pcbX={85} routingDisabled>
        <connector name="J_MOTOR" standard="jst_ph" pinCount={6}
          footprint="jst6_ph" pcbX={-18} pcbRotation={90} />
      </board>
      <assembly.cable name="MOTOR_CABLE" from="MOTOR.wireside"
        to=".CONTROLLER > .J_MOTOR" />
    </assembly.device>,
  )
  await circuit.renderUntilSettled()
  const json = circuit.getCircuitJson()
  const cable = json.find((x) => x.type === "cad_cable")!
  expect(cable).toBeDefined()
  expect(cable.cableprinter_string).toBe("jst_ph_pins6")
  expect(cable.path.length).toBeGreaterThan(2)
  for (const key of ["from_source_component_id", "to_source_component_id"] as const) {
    expect(json.some((x) => x.type === "source_component" &&
      x.source_component_id === cable[key])).toBe(true)
  }
  await Bun.write(new URL("./dist/results/native-cable-probe.circuit.json", import.meta.url),
    JSON.stringify(json, null, 2))
})

test("released explicit cable models support independent bullet diameters and genders", async () => {
  // A capability fixture, not a replacement for the real motor or its rigid adapters.
  const circuit = new Circuit({platform:{partsEngineDisabled:true,schematicDisabled:true}})
  const model = "adaptercable_a(bullet1_d3.5mm_gfemale)_b(bullet1_d4mm_gmale)"
  circuit.add(<assembly.device name="BULLET_API_FIXTURE">
    <board width={60} height={25} routingDisabled>
      <connector name="A" pinCount={1} footprint="pinrow1" pcbX={-20} />
      <connector name="B" pinCount={1} footprint="pinrow1" pcbX={20} />
    </board>
    <assembly.cable name="CABLE" from=".A" to=".B" model={model} />
  </assembly.device>)
  await circuit.renderUntilSettled()
  const json = circuit.getCircuitJson()
  const cables = json.filter(x => x.type === "cad_cable")
  expect(cables).toHaveLength(1)
  expect(cables[0].cableprinter_string).toBe(model)
  expect(cables[0].path.length).toBeGreaterThan(2)
  expect(json.filter(x=>x.type.endsWith("_error"))).toHaveLength(0)
  await Bun.write(new URL("./dist/results/released-bullet-cable-probe.circuit.json",import.meta.url),JSON.stringify(json,null,2))
})

test("the assembly motor schema still has no 2212 BLDC preset", () => {
  expect(assemblyCableProps.safeParse({name:"CABLE",from:".A",to:".B",model:"adaptercable_a(bullet1_d3.5mm_gfemale)_b(bullet1_d4mm_gmale)"}).success).toBe(true)
  expect(assemblyMotorProps.safeParse({ name: "MOTOR", standard: "bldc2212" }).success).toBe(false)
})

test("an imported motor model URL is rejected rather than silently rendering a NEMA", async () => {
  const circuit = new Circuit()
  circuit.add(<assembly.device>
    <assembly.motor name="MOTOR" model="./readytosky-2212.glb" />
  </assembly.device>)
  await expect(circuit.renderUntilSettled()).rejects.toThrow("requires a NEMA modelprinter model")
})