MustafaMulla29/rp2040-bldc-motor-controller

Hardware assembly metadata and PCB geometry for a controller board with a snap-off rotary-encoder section, plus four parallel 150 µF/50 V bulk electrolytic capacitors filtering the motor supply.

Version
2.0.40
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone MustafaMulla29/rp2040-bldc-motor-controller  # download the package files into ./rp2040-bldc-motor-controller
tsci add MustafaMulla29/rp2040-bldc-motor-controller    # add it to your project as @tsci/MustafaMulla29.rp2040-bldc-motor-controller

In a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.

scripts/check-integration.mjs

/** Verify the package wrapper adds mechanical CAD without changing the board. */
import assert from "node:assert/strict"
import { createHash } from "node:crypto"
import { readFileSync, writeFileSync } from "node:fs"
import { resolve } from "node:path"
import { hashPcbGeometry } from "./assembly-geometry.ts"
const root = resolve(import.meta.dirname, "..")
const bytes = path => readFileSync(resolve(root, path))
const json = path => JSON.parse(bytes(path))
const sha = value => createHash("sha256").update(value).digest("hex")
const boardBytes = bytes("dist/pcb/circuit.json")
const enclosedEntry = process.argv.includes("--enclosed")
const entry = enclosedEntry ? "enclosed-system" : process.argv.includes("--main") ? "index" : "system"
const board = JSON.parse(boardBytes), system = json(`dist/${entry}/circuit.json`)
const enclosed = system.some(r => r.type === "source_component" && r.name === "CASE_BASE")
const provenance = json("assets/connected-system.provenance.json")
const records = (rows, prefix) => rows.filter(row => row.type.startsWith(prefix))
if (provenance) {
  assert.equal(provenance.pcbGeometrySha256, hashPcbGeometry(board), "Assembly asset is stale; run bun run build:all locally")
  assert.equal(provenance.mechanicalAssetSha256, sha(bytes("assets/connected-system.glb")))
}
// Normalize optional nulls from different native serializer versions, not geometry.
const normalize = rows => JSON.parse(JSON.stringify(rows, (_, v) => v === null ? undefined : v))
assert.deepEqual(normalize(records(system, "pcb_")), normalize(records(board, "pcb_")), "Package changed the PCB")
assert.deepEqual(normalize(records(system, "schematic_")), normalize(records(board, "schematic_")), "Package changed the schematic")
for (const type of ["source_port", "source_net", "source_trace", "source_component_internal_connection"]) {
  assert.deepEqual(system.filter(r => r.type === type), board.filter(r => r.type === type), `Changed ${type}`)
}
assert.equal(system.filter(r => r.type.endsWith("_error")).length, 0)
assert.equal(system.filter(r => r.type === "pcb_board").length, 1)
if (enclosed) {
  const names = ["CASE_BASE", "CASE_LID", "SPEED_KNOB", "SCREEN_HOLDER", "SCREEN_DOOR", ...["SW3", "SW5", "SW6", "SW7", "SW8"].map(ref => `PLUNGER_${ref}`)]
  // BOOT (SW1) and RESET (SW2) sit behind pinholes in the lid and have no printed cap.
  for (const ref of ["SW1", "SW2"]) assert.ok(!system.some(r => r.type === "source_component" && r.name === `PLUNGER_${ref}`), `${ref} must not have a cap`)
  const enclosure = json("enclosure/dist/enclosure.circuit.json")
  assert.ok(!system.some(r => r.type === "source_component" && r.name === "PANEL_STICKER"), "Panel artwork must not float independently of the lid")
  for (const name of names) {
    const part = system.find(r => r.type === "source_component" && r.name === name)
    assert.ok(part, `Missing printed part ${name}`)
    const cad = system.find(r => r.type === "cad_component" && r.source_component_id === part.source_component_id)
    assert.ok(cad?.model_jscad, `Missing native solid for ${name}`)
    assert.ok(!cad.pcb_component_id, `${name} must not create a PCB footprint`)
    const verifiedPart = enclosure.find(r => r.type === "source_component" && r.name === name)
    const verifiedCad = enclosure.find(r => r.type === "cad_component" && r.source_component_id === verifiedPart?.source_component_id)
    assert.deepEqual(cad.model_jscad, verifiedCad?.model_jscad, `${name} differs from the verified enclosure build`)
  }
  assert.equal(system.filter(r => r.type === "cad_component").length, board.filter(r => r.type === "cad_component").length + names.length + 1)
}
{
  const assembly = system.find(r => r.type === "source_component" && r.name === "CONNECTED_EXTERNAL_ASSEMBLY")
  assert.ok(assembly, "Missing mechanical assembly")
  const cad = system.find(r => r.type === "cad_component" && r.source_component_id === assembly.source_component_id)
  assert.ok(cad?.model_glb_url?.endsWith("assets/connected-system.glb"))
  assert.ok(!cad.pcb_component_id, "Off-board assembly must not create a PCB footprint")
  assert.equal(system.filter(r => r.type === "cad_component").length, board.filter(r => r.type === "cad_component").length + (enclosed ? 11 : 1))
}
const result = {
  status: "PASS", pcbUnchanged: true, schematicUnchanged: true, connectivityUnchanged: true,
  nativeErrors: 0, nativePcbBoards: system.filter(r => r.type === "pcb_board").length,
  pcbCircuitSha256: sha(boardBytes), integratedCircuitSha256: sha(bytes(`dist/${entry}/circuit.json`)),
  ...(enclosed ? { nativePrintedParts: 10, mechanicalAssetSha256: provenance.mechanicalAssetSha256 } : {
    mechanicalAssetSha256: provenance.mechanicalAssetSha256,
    nativeMotorLeads: provenance.nativeMotorLeads, rigidAdapters: provenance.rigidAdapters,
    nativeUsbCables: provenance.nativeUsbCables, nativeEncoderWires: provenance.nativeEncoderWires,
    oledSupports: provenance.oledSupports, encoder: provenance.encoder,
  }),
}
writeFileSync(resolve(root, `dist/${entry}/integration-check.json`), JSON.stringify(result, null, 2) + "\n")
console.log(enclosed
  ? "PASS: one native PCB; identical copper, schematic and connectivity; ten native printed enclosure parts and connected assembly; no floating panel artwork"
  : "PASS: one native PCB; identical copper, schematic and connectivity; motor, OLED supports, encoder and all ten cable connections included")