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/export_solid.py
"""Evaluate the authored JSCAD CSG plans with the Manifold solid kernel and export standard STL.
Same approach as the rp2040-bldc-motor-controller enclosure: no mesh repair; the plan's primitive sizes,
transforms and JSCAD's default 32-segment cylinders are preserved, and unsupported operations fail.
JSCAD's own bounds and volume (build-report.json) are an independent check of the result.
dist/<part>.stl print orientation (lid and cap upside down), sitting on z = 0
dist/<part>-assembled.stl fitted position in the board frame (board top z = 0.8)
dist/<part>.glb fitted position, for the preview renders
"""
from pathlib import Path
import json, math
import manifold3d as mf
import numpy as np
import trimesh
OUT = Path(__file__).parent / "dist"
def evaluate(plan):
if isinstance(plan, list):
return mf.Manifold.batch_boolean([evaluate(p) for p in plan], mf.OpType.Add)
kind = plan["type"]
if kind in ("union", "subtract", "hull"):
shapes = [evaluate(s) for s in plan["shapes"]]
if kind == "hull":
return mf.Manifold.batch_hull(shapes)
return mf.Manifold.batch_boolean(shapes, mf.OpType.Add if kind == "union" else mf.OpType.Subtract)
if kind in ("cuboid", "cube"):
size = plan["size"]
size = [size] * 3 if isinstance(size, (int, float)) else size
return mf.Manifold.cube(size, center=True)
if kind == "cylinder":
return mf.Manifold.cylinder(plan["height"], plan["radius"], circular_segments=plan.get("segments", 32), center=True)
if kind == "translate":
return evaluate(plan["shape"]).translate(plan["vector"])
if kind == "rotate":
return evaluate(plan["shape"]).rotate([math.degrees(a) for a in plan["angles"]])
if kind == "colorize":
return evaluate(plan["shape"])
raise ValueError("Unsupported JSCAD operation " + kind)
def to_mesh(solid):
m = solid.to_mesh()
return trimesh.Trimesh(vertices=m.vert_properties[:, :3], faces=m.tri_verts, process=True)
def main():
report = json.loads((OUT / "build-report.json").read_text())
result = {}
for name, ref in report["parts"].items():
solid = evaluate(json.loads((OUT / f"{name}.jscad.json").read_text()))
if solid.status() != mf.Error.NoError:
raise ValueError((name, solid.status()))
m = to_mesh(solid)
if not m.is_watertight or not m.is_winding_consistent:
raise ValueError(f"{name}: mesh is not a closed solid")
if len(solid.decompose()) != 1:
raise ValueError(f"{name}: more than one separate solid")
bounds_error = float(np.max(np.abs(m.bounds - np.array(ref["bounds"]))))
volume_error = abs(m.volume - ref["volumeMm3"]) / ref["volumeMm3"]
if bounds_error > 0.005 or volume_error > 0.001:
raise ValueError((name, "kernel parity", bounds_error, volume_error))
m.export(OUT / f"{name}-assembled.stl")
m.export(OUT / f"{name}.glb")
printing = m.copy()
if ref["printOrientation"] == "flip":
printing.apply_transform(trimesh.transformations.rotation_matrix(math.pi, [1, 0, 0]))
b = printing.bounds
printing.apply_translation([-(b[0, 0] + b[1, 0]) / 2, -(b[0, 1] + b[1, 1]) / 2, -b[0, 2]])
printing.export(OUT / f"{name}.stl")
checked = trimesh.load_mesh(OUT / f"{name}.stl") # re-read the deliverable itself
assert checked.is_watertight and checked.is_winding_consistent
size = (checked.bounds[1] - checked.bounds[0]).round(2).tolist()
result[name] = {"watertight": True, "oneSolid": True, "faces": len(m.faces), "volumeMm3": round(m.volume, 1),
"printSizeMm": size, "boundsDifferenceFromJscadMm": bounds_error, "volumeRelativeDifference": volume_error}
print(f"{name}: closed single solid, print size {size} mm, JSCAD parity {bounds_error:.4f} mm")
(OUT / "mesh-verification.json").write_text(json.dumps(result, indent=2) + "\n")
if __name__ == "__main__":
main()