MustafaMulla29/usb-pd-motherboard
4-layer USB-C PD hub motherboard with 20 V USB-C input, Linux T113-S3 computer, CH338F USB hub, four individually controlled 5–20 V PD outputs, USB data/camera ports, regulated rails, and hardware watchdog/E-stop safety interlock.
- Version
- 1.0.24
- License
- unset
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone MustafaMulla29/usb-pd-motherboard # download the package files into ./usb-pd-motherboard
tsci add MustafaMulla29/usb-pd-motherboard # add it to your project as @tsci/MustafaMulla29.usb-pd-motherboardIn 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.
enclosure/example/build_bldc_unit.py
"""Make a 3D model of one rp2040-bldc-motor-controller unit for the example-system renders.
Input: the published build of MustafaMulla29/rp2040-bldc-motor-controller (source/bldc-circuit.json, its
dist/index/circuit.json). Its printed enclosure parts are stored there as JSCAD plans; they are evaluated with the
same Manifold kernel as our own parts (../export_solid.py) and written to bldc-unit.glb (one node per part) in
that project's board frame. Part colours and port positions go to bldc-unit.json. Run: ../.venv/bin/python build_bldc_unit.py
"""
from pathlib import Path
import json, sys
import numpy as np, trimesh, manifold3d as mf
HERE = Path(__file__).parent
sys.path.insert(0, str(HERE.parent))
import export_solid # noqa: E402
base_eval = export_solid.evaluate
def evaluate(plan):
if isinstance(plan, dict) and plan.get("type") == "extrudeLinear":
return mf.Manifold.extrude(mf.CrossSection([plan["shape"]["points"]]), plan["options"]["height"])
return base_eval(plan)
export_solid.evaluate = evaluate # nested calls inside export_solid use this too
def find_color(p):
if isinstance(p, dict):
if p.get("type") == "colorize":
return list(p["color"][:3])
if "shape" in p:
c = find_color(p["shape"])
if c:
return c
for s in p.get("shapes", []):
c = find_color(s)
if c:
return c
return None
def main():
cj = json.loads((HERE / "source/bldc-circuit.json").read_text())
src = {e["source_component_id"]: e.get("name") for e in cj if e["type"] == "source_component"}
scene, info = trimesh.Scene(), {"parts": {}}
for e in cj:
name = src.get(e.get("source_component_id"))
if e["type"] != "cad_component" or not e.get("model_jscad") or not name:
continue
if not name.startswith(("CASE_", "PLUNGER_", "SPEED_KNOB", "SCREEN_")):
continue
m = evaluate(e["model_jscad"]).to_mesh()
mesh = trimesh.Trimesh(vertices=m.vert_properties[:, :3], faces=m.tri_verts, process=True)
col = find_color(e["model_jscad"]) or [0.8, 0.8, 0.8]
scene.add_geometry(mesh, node_name=name, geom_name=name)
info["parts"][name] = {"bounds": np.round(mesh.bounds, 2).tolist(), "color": [round(c, 3) for c in col]}
scene.export(HERE / "bldc-unit.glb")
pcb = {src.get(p["source_component_id"]): p for p in cj if p["type"] == "pcb_component"}
info["ports"] = {n: {"x": round(pcb[n]["center"]["x"], 2), "y": round(pcb[n]["center"]["y"], 2), "rotation": pcb[n].get("rotation")}
for n in ("J19", "J1", "J10", "J11", "J12", "J20", "J21", "RV1", "SW3") if n in pcb}
b = next(e for e in cj if e["type"] == "pcb_board")
info["board"] = {"width": b["width"], "height": b["height"], "center": b["center"]}
(HERE / "bldc-unit.json").write_text(json.dumps(info, indent=1) + "\n")
for k, v in info["parts"].items():
print(k, v["bounds"])
print(info["ports"], info["board"])
if __name__ == "__main__":
main()