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.

enclosure/export_solid.py

"""Evaluate the authored JSCAD CSG plan with Manifold, then export standard STL.

This is a solid-kernel export, not mesh repair. It preserves the original plan's
primitive sizes, transforms and 32-segment JSCAD default cylinders. Unsupported
operations fail instead of approximating them. JSCAD bounds/volume provide an
independent comparison with the native tscircuit geometry.
"""
from pathlib import Path
import json, math, os
import manifold3d as mf
import numpy as np
import trimesh

ROOT=Path(__file__).parent
OUT=ROOT/os.environ.get("ENCLOSURE_OUTPUT_DIR","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'])
    if kind=='extrudeLinear':
        shape=plan['shape'];options=plan['options']
        if shape['type']!='polygon' or set(options)-{'height'}: raise ValueError('Unsupported extrusion')
        return mf.Manifold.extrude(mf.CrossSection([shape['points']]),options['height'])
    raise ValueError('Unsupported JSCAD operation '+kind)

def 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,reference 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=mesh(solid)
        if not m.is_watertight or not m.is_winding_consistent: raise ValueError(f'{name}: invalid mesh')
        if len(solid.decompose())!=1: raise ValueError(f'{name}: disconnected solid')
        bounds_error=float(np.max(np.abs(m.bounds-np.array(reference['bounds']))))
        volume_error=abs(m.volume-reference['volumeMm3'])/reference['volumeMm3']
        if bounds_error>.005 or volume_error>.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 name in ('lid','speed-knob','screen-door'):
            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')
        # Re-read the deliverable itself, not just the pre-export mesh.
        checked=trimesh.load_mesh(OUT/f'{name}.stl')
        assert checked.is_watertight and checked.is_winding_consistent
        result[name]={'watertight':True,'consistentWinding':True,'solidCount':1,'faces':len(m.faces),'volumeMm3':m.volume,'boundsMm':m.bounds.tolist(),'printBoundsMm':checked.bounds.tolist(),'nativeBoundsDifferenceMm':bounds_error,'nativeVolumeRelativeDifference':volume_error}
        print(name,'watertight, one solid; native bounds delta',round(bounds_error,6),'mm')
    (OUT/'mesh-verification.json').write_text(json.dumps(result,indent=2)+'\n')

if __name__=='__main__': main()