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-controllerIn 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/parts.tsx
import {jscad} from "jscad-fiber/headless"
import {board,body,capButtons,pinholeButtons,design as d,mountingHoles,mountHoles,portOpenings,usbOpening,roofVents,baseVents,buzzerVents} from "./dimensions"
import {EngravedText,lidLabels} from "./labels"
export function Box({x,y,z0,z1,w,h}:{x:number;y:number;z0:number;z1:number;w:number;h:number}){return <jscad.cuboid size={[w,h,z1-z0]} center={[x,y,(z0+z1)/2]}/>}
export function Cylinder({x,y,z0,z1,r}:{x:number;y:number;z0:number;z1:number;r:number}){return <jscad.cylinder radius={r} height={z1-z0} center={[x,y,(z0+z1)/2]}/>}
export function RoundBox({x,y,z0,z1,w,h,r=2}:{x:number;y:number;z0:number;z1:number;w:number;h:number;r?:number}){return <jscad.hull>{[-1,1].flatMap(dx=>[-1,1].map(dy=><Cylinder key={`${dx}:${dy}`} x={x+dx*(w/2-r)} y={y+dy*(h/2-r)} z0={z0} z1={z1} r={r}/>))}</jscad.hull>}
const Outer=({z0,z1}:{z0:number;z1:number})=><RoundBox x={body.x} y={body.y} w={body.width} h={body.depth} r={3} z0={z0} z1={z1}/>
// Cylinder whose axis runs along X (for the rounded POWER finger recess).
function XCylinder({x0,x1,y,z,r}:{x0:number;x1:number;y:number;z:number;r:number}){return <jscad.translate offset={[(x0+x1)/2,y,z]}><jscad.rotate angles={[0,Math.PI/2,0]}><jscad.cylinder radius={r} height={x1-x0}/></jscad.rotate></jscad.translate>}
type Rect={x0:number;x1:number;y0:number;y1:number}
const D=d.door, doorMid=d.roofBottom+D.bevel
const grow=(q:Rect,g:number):Rect=>({x0:q.x0-g,x1:q.x1+g,y0:q.y0-g,y1:q.y1+g})
function Slab({q,z0,z1,r}:{q:Rect;z0:number;z1:number;r:number}){return <RoundBox x={(q.x0+q.x1)/2} y={(q.y0+q.y1)/2} w={q.x1-q.x0} h={q.y1-q.y0} z0={z0} z1={z1} r={r}/>}
// Outline `q` at the roof underside widens by the 45 degree seat, then runs straight to `top`.
// inset shrinks the whole prism (door); extra widens only the straight part (lid opening).
function BevelPrism({q,inset=0,extra=0,top=d.top}:{q:Rect;inset?:number;extra?:number;top?:number}){return <jscad.union>
<jscad.hull><Slab q={grow(q,-inset)} z0={d.roofBottom} z1={d.roofBottom+.01} r={D.corner}/><Slab q={grow(q,D.bevel-inset)} z0={doorMid-.01} z1={doorMid} r={D.corner+D.bevel}/></jscad.hull>
<Slab q={grow(q,D.bevel-inset+extra)} z0={doorMid-.005} z1={top} r={D.corner+D.bevel+extra}/>
</jscad.union>}
const flexFrontEdge=()=>d.screen.panelY-d.screen.panelDepth/2
// Everything removed from the lid for the screen door: bevelled opening, screw-tab recesses
// and a relief in front of the glass edge where the flex turns down.
function DoorOpening(){const s=d.screen;return <jscad.union>
{[D.low,D.ear].map((q,i)=><jscad.union key={i}><Slab q={q} z0={d.roofBottom-.3} z1={d.roofBottom+.01} r={D.corner}/><BevelPrism q={q} extra={D.gap} top={d.top+1}/></jscad.union>)}
{D.tabs.map((t,i)=><Slab key={`tab-${i}`} q={grow(t,D.gap)} z0={d.top-D.tabThickness} z1={d.top+1} r={D.tabCorner+D.gap}/>)}
<Box x={s.x} y={(D.flexFront+D.low.y0+.3)/2} w={D.flexWidth} h={D.low.y0+.3-D.flexFront} z0={D.flexBottom} z1={doorMid}/>
</jscad.union>}
const wallInnerX=()=>body.x-body.innerWidth/2
const wallOuterX=()=>body.x-body.width/2
// Slot through the side wall for the POWER lever, open down to the seam so the
// lid can be lowered over the lever.
function PowerSlot(){const p=d.power,o=wallOuterX(),i=wallInnerX();return <Box x={(o-1+i+.3)/2} y={p.y} w={i+.3-o+1} h={2*p.slotHalfWidth} z0={d.seam-1} z1={p.slotTop}/>}
// Shallow rounded thumb pocket around the lever on the outside of the wall.
function PowerPocket(){const p=d.power,r=p.pocketRadius,o=wallOuterX();return <jscad.hull>{[-1,1].flatMap(sy=>[p.pocketBottom+r,p.pocketTop-r].map(z=><XCylinder key={`${sy}:${z}`} x0={o-1} x1={o+p.pocketDepth} y={p.y+sy*(p.pocketHalfDepth-r)} z={z} r={r}/>))}</jscad.hull>}
// Base tongue filling the wall slot below the lever (follows the pocket floor).
function PowerTongue(){const p=d.power,o=wallOuterX(),i=wallInnerX(),c=p.tongueClearance,w=2*(p.slotHalfWidth-c);return <jscad.union>
<Box x={(o+.1+i-.1)/2} y={p.y} w={i-.1-o-.1} h={w} z0={d.seam-.1} z1={p.pocketBottom}/>
<Box x={(o+p.pocketDepth+.05+i-.1)/2} y={p.y} w={i-.1-o-p.pocketDepth-.05} h={w} z0={p.pocketBottom-.01} z1={p.tongueTop}/>
</jscad.union>}
// One continuous chamfer around the shared USB mouth, cut into both case halves.
// The inner throat remains clear for straight insertion and removal of both bodies.
function UsbLeadIn(){const p=usbOpening;return <jscad.hull>
<Box x={p.x-.05} y={p.y} w={.1} h={p.depth+2*p.leadInFlare} z0={p.bottom-p.leadInFlare} z1={p.top+p.leadInFlare}/>
<Box x={p.x+p.leadInDepth} y={p.y} w={.1} h={p.depth} z0={p.bottom} z1={p.top}/>
</jscad.hull>}
export function Base(){return <jscad.subtract><jscad.union>
{/* Floor plate. It runs past both side walls to form the two mounting flanges. */}
<RoundBox x={body.x} y={body.y} w={body.width+2*d.mount.width} h={body.depth} r={d.mount.corner} z0={d.bottom} z1={d.floorTop}/>
{mountingHoles.map(h=><Cylinder key={h.pcb_hole_id} x={h.x} y={h.y} z0={d.floorTop-.1} z1={-board.thickness/2} r={d.pcbMount.radius}/>)}
{portOpenings.map(p=><Box key={p.name} x={p.along==="y"?body.x-body.width/2+d.wall/2:p.x} y={p.along==="x"?body.y+body.depth/2-d.wall/2:p.y} w={p.along==="y"?d.wall:p.width-.6} h={p.along==="x"?d.wall:p.depth-.6} z0={d.seam-.1} z1={p.bottom}/>)}
<PowerTongue/>
{/* Fill below J20 while leaving the lid open to the seam for assembly. */}
<Box x={body.x+body.width/2-d.wall/2} y={d.encoder.y}
w={d.wall} h={d.encoder.depth-2*d.encoder.tongueClearance}
z0={d.seam-.1} z1={d.encoder.bottom}/>
</jscad.union>
{mountingHoles.map(h=><Cylinder key={h.pcb_hole_id} x={h.x} y={h.y} z0={d.pcbMount.holeBottom} z1={2} r={d.inserts.m3.holeDiameter/2}/>)}
{d.caseBolts.map(([x,y])=><jscad.union key={`${x}:${y}`}><Cylinder x={x} y={y} z0={d.bottom-1} z1={d.floorTop+1} r={d.flange.holeRadius}/><Cylinder x={x} y={y} z0={d.bottom-1} z1={d.flange.headSeat} r={d.flange.headRadius}/></jscad.union>)}
{mountHoles.map(([x,y])=><Cylinder key={`mount-${x}:${y}`} x={x} y={y} z0={d.bottom-1} z1={d.floorTop+1} r={d.mount.holeRadius}/>)}
<UsbLeadIn/>
{baseVents.map((v,i)=><RoundBox key={i} {...v} w={v.width} h={v.depth} z0={d.bottom-1} z1={d.floorTop+1} r={.6}/>)}
</jscad.subtract>}
// Shallow locating pocket and integral ledge (now part of the screen door). Blind inserts
// are accessed from the door's underside.
function ScreenSeat(){const s=d.screen;return <jscad.union>
<jscad.subtract>
<RoundBox x={s.x} y={s.panelY} w={s.locatingWidth} h={s.locatingDepth} r={.5} z0={s.holderTop} z1={d.top}/>
<Box x={s.x} y={s.panelY} w={s.panelWidth+2*s.panelClearance} h={s.panelDepth+2*s.panelClearance} z0={s.holderTop-1} z1={s.seatBottom}/>
<Box x={s.x} y={s.panelY-s.panelDepth/2-1.5} w={s.flexExitWidth} h={6} z0={s.holderTop-1} z1={s.panelBottom+.35}/>
</jscad.subtract>
{s.screws.map(([x,y])=><Cylinder key={`${x}:${y}`} x={x} y={y} z0={s.screwSeat+1.5} z1={d.roofBottom+.1} r={2.7}/>)}
</jscad.union>}
export function Lid(){const b=d.button;return <jscad.subtract>
<jscad.union>
<jscad.subtract>
<jscad.union>
<jscad.subtract>
<Outer z0={d.seam+.15} z1={d.top}/>
<RoundBox x={body.x} y={body.y} w={body.innerWidth} h={body.innerDepth} z0={d.bottom-1} z1={d.roofBottom} r={1.5}/>
</jscad.subtract>
{d.caseBolts.map(([x,y])=><jscad.union key={`${x}:${y}`}><Cylinder x={x} y={y} z0={d.flange.bottom} z1={d.flange.top} r={d.flange.radius}/><jscad.hull><Cylinder x={x} y={y} z0={d.flange.top-.1} z1={d.flange.top} r={d.flange.radius}/><Cylinder x={x} y={y} z0={d.flange.top+3} z1={d.flange.top+3.1} r={1.5}/></jscad.hull></jscad.union>)}
{capButtons.map(q=><Cylinder key={q.ref} x={q.x} y={q.y} z0={b.guideBottom} z1={d.roofBottom+.1} r={b.guideRadius}/>)}
{/* BOOT and RESET: a solid guide under each pinhole, ending above the switch plunger. */}
{pinholeButtons.map(q=><Cylinder key={q.ref} x={q.x} y={q.y} z0={d.pinhole.guideBottom} z1={d.roofBottom+.1} r={d.pinhole.guideRadius}/>)}
</jscad.union>
{/* The display now lives in the removable screen door; see ScreenDoor. */}
<DoorOpening/>
</jscad.subtract>
{/* Insert bosses for the two door screws hang below the 1 mm lid step under each tab. */}
{D.screws.map(([x,y])=><Cylinder key={`door-boss-${x}`} x={x} y={y} z0={D.bossBottom} z1={d.roofBottom+.1} r={D.bossRadius}/>)}
</jscad.union>
{D.screws.map(([x,y])=><Cylinder key={`door-insert-${x}`} x={x} y={y} z0={D.holeBottom} z1={doorMid+.01} r={d.inserts.m2.holeDiameter/2}/>)}
{portOpenings.map(p=><Box key={p.name} x={p.x} y={p.y} w={p.width} h={p.depth} z0={d.seam-1} z1={p.top}/>)}
<Cylinder x={d.knob.x} y={d.knob.y} r={d.knob.openingRadius} z0={d.roofBottom-1} z1={d.top+1}/>
<PowerSlot/>
<PowerPocket/>
<UsbLeadIn/>
<Box x={d.encoder.x} y={d.encoder.y} w={d.encoder.width} h={d.encoder.depth} z0={d.seam-1} z1={d.encoder.top}/>
<Cylinder x={d.led.x} y={d.led.y} r={d.led.radius} z0={.5} z1={d.top+1}/>
{capButtons.map(q=><jscad.union key={q.ref}><Cylinder x={q.x} y={q.y} r={b.boreRadius} z0={b.guideBottom-1} z1={d.top+1}/><Cylinder x={q.x} y={q.y} r={b.pocketRadius} z0={b.guideBottom-1} z1={d.roofBottom}/></jscad.union>)}
{/* Paperclip pinholes with a 45-degree lead-in at the top face. */}
{pinholeButtons.map(q=><jscad.union key={q.ref}>
<Cylinder x={q.x} y={q.y} r={d.pinhole.radius} z0={d.pinhole.guideBottom-1} z1={d.top+1}/>
<jscad.hull><Cylinder x={q.x} y={q.y} r={d.pinhole.radius} z0={d.top-d.pinhole.leadInDepth-.01} z1={d.top-d.pinhole.leadInDepth}/><Cylinder x={q.x} y={q.y} r={d.pinhole.leadInRadius} z0={d.top} z1={d.top+.01}/></jscad.hull>
</jscad.union>)}
{d.caseBolts.map(([x,y])=><Cylinder key={`${x}:${y}`} x={x} y={y} r={d.inserts.m2.holeDiameter/2} z0={d.flange.bottom-1} z1={d.flange.bottom+3.6}/>)}
{[...roofVents,...buzzerVents].map((v,i)=><RoundBox key={i} x={v.x} y={v.y} w={v.width} h={v.depth} r={.4} z0={v.z-3} z1={v.z+1}/>)}
{/* Labels are a separate printed sticker; no tiny lettering in the STL. */}
</jscad.subtract>}
// Removable screen door. It carries the locating pocket, the 0.6 mm window ledge and the
// two blind retainer inserts that used to be part of the lid, so the display and its rear
// frame are assembled on the bench. Fit it last: mate the flex through the opening, lower
// the door straight onto its 45 degree seat and fasten two M2 x 4 screws from the top.
export function ScreenDoor(){const s=d.screen,front=flexFrontEdge();return <jscad.subtract>
<jscad.union>
<BevelPrism q={D.low} inset={D.seatGap}/>
<BevelPrism q={D.ear} inset={D.seatGap}/>
{D.tabs.map((t,i)=><Slab key={i} q={t} z0={d.top-D.tabThickness} z1={d.top} r={D.tabCorner}/>)}
<ScreenSeat/>
</jscad.union>
<Box x={s.x} y={s.panelY} w={s.panelWidth+2*s.panelClearance} h={s.panelDepth+2*s.panelClearance} z0={s.holderTop-1} z1={s.seatBottom}/>
<jscad.hull><RoundBox x={s.x} y={s.y} w={s.width} h={s.depth} r={.5} z0={s.glassTop+.15} z1={s.glassTop+.35}/><RoundBox x={s.upperX} y={s.y} w={s.upperWidth} h={s.upperDepth} r={.5} z0={d.top} z1={d.top+1}/></jscad.hull>
{s.screws.map(([x,y])=><Cylinder key={`oled-${y}`} x={x} y={y} z0={s.insertHoleBottom-.01} z1={s.insertTop+.1} r={d.inserts.m2.holeDiameter/2}/>)}
{/* Flex relief up to the glass seat: the ribbon leaves between the glass sheets and needs
room to curve. Only the 0.6 mm top skin remains above it. */}
<Box x={s.x} y={(D.flexFront-1+front+.15)/2} w={s.flexExitWidth} h={front+.15-(D.flexFront-1)} z0={s.holderTop-2} z1={s.seatBottom}/>
{D.screws.map(([x,y])=><Cylinder key={`door-screw-${x}`} x={x} y={y} r={D.clearRadius} z0={d.top-D.tabThickness-1} z1={d.top+1}/>)}
</jscad.subtract>}
// Captive console-style cap (as on the handheld): a socket in its underside slides
// over the KH-6X6X9.5H plunger and rests on it; flange under the roof; 6 mm
// crowned cap through the lid.
export function ButtonPlunger(){const b=d.button;return <jscad.subtract><jscad.union>
<Cylinder x={0} y={0} r={b.stemRadius} z0={b.tipBottom} z1={b.top-b.domeDrop}/>
<jscad.hull><Cylinder x={0} y={0} r={b.stemRadius} z0={b.top-b.domeDrop-.01} z1={b.top-b.domeDrop}/><Cylinder x={0} y={0} r={b.stemRadius-.6} z0={b.top-.01} z1={b.top}/></jscad.hull>
<jscad.hull><Cylinder x={0} y={0} r={b.stemRadius} z0={b.flangeBottom-1} z1={b.flangeBottom-.99}/><Cylinder x={0} y={0} r={b.flangeRadius} z0={b.flangeBottom} z1={b.flangeBottom+.1}/></jscad.hull>
<Cylinder x={0} y={0} r={b.flangeRadius} z0={b.flangeBottom} z1={b.flangeTop}/>
</jscad.union>
<Cylinder x={0} y={0} r={b.socketRadius} z0={b.tipBottom-1} z1={b.switchTop}/>
</jscad.subtract>}
// Push-on SPEED knob for the RK09D1130C2P flat (D-cut) shaft. It seats on the shaft tip;
// the stem passes through the roof opening and the ribbed cap sits above the lid.
// The bore flat faces -Y in the modelled shaft orientation; fit it in any rotation.
/**
* SPEED knob. The print file (fitted=false) has crush ribs at gripRibRadius, 0.045-0.07 mm
* inside the Alps shaft. Pressing the knob on flattens them, so the product assembly uses
* fitted=true: ribs end just outside the 6.00 mm shaft, as installed. This keeps the CAD
* explosion collision check from flagging the intended press fit as a collision.
*/
export function SpeedKnob({fitted=false}:{fitted?:boolean}={}){const k=d.knob,boreTop=k.shaftTop+.05
const ribs=Array.from({length:k.ribs},(_,i)=>i*2*Math.PI/k.ribs)
// Crush rib: radial bar from gripRibRadius out into the bore wall, with a 45 deg lead-in at its lower end.
const ribR=fitted?k.shaftRadius+.005:k.gripRibRadius
const ribLen=k.boreRadius+.3-ribR, ribMid=(ribR+k.boreRadius+.3)/2
const rib=(deg:number)=><jscad.rotate key={deg} angles={[0,0,deg*Math.PI/180]}><jscad.hull>
<Box x={k.boreRadius+.15} y={0} w={.3} h={k.gripRibWidth} z0={k.stemBottom+k.gripRibStart-ribLen} z1={k.stemBottom+k.gripRibStart-ribLen+.01}/>
<Box x={ribMid} y={0} w={ribLen} h={k.gripRibWidth} z0={k.stemBottom+k.gripRibStart} z1={k.gripRibEnd}/>
</jscad.hull></jscad.rotate>
return <jscad.translate offset={[k.x,k.y,0]}><jscad.union><jscad.subtract>
<jscad.union>
<Cylinder x={0} y={0} r={k.stemRadius} z0={k.stemBottom} z1={k.capBottom+.5}/>
<Cylinder x={0} y={0} r={k.capRadius} z0={k.capBottom} z1={k.capTop-.6}/>
<jscad.hull><Cylinder x={0} y={0} r={k.capRadius} z0={k.capTop-.61} z1={k.capTop-.6}/><Cylinder x={0} y={0} r={k.capRadius-.6} z0={k.capTop-.01} z1={k.capTop}/></jscad.hull>
</jscad.union>
{/* D bore: round, minus the flat side (flat at -Y), with a conical lead-in at the mouth. */}
<jscad.subtract>
<jscad.union>
<Cylinder x={0} y={0} r={k.boreRadius} z0={k.stemBottom-1} z1={boreTop}/>
<jscad.hull><Cylinder x={0} y={0} r={k.leadInRadius} z0={k.stemBottom-.01} z1={k.stemBottom}/><Cylinder x={0} y={0} r={k.boreRadius} z0={k.stemBottom+k.leadInDepth} z1={k.stemBottom+k.leadInDepth+.01}/></jscad.hull>
</jscad.union>
<Box x={0} y={-k.boreFlat-2} w={2*k.leadInRadius+1} h={4} z0={k.stemBottom-2} z1={boreTop+1}/>
</jscad.subtract>
{ribs.map(a=><jscad.translate key={a} offset={[k.capRadius*Math.cos(a),k.capRadius*Math.sin(a),0]}><jscad.rotate angles={[0,0,a]}><Box x={0} y={0} w={2*k.ribDepth} h={.8} z0={k.capBottom+.6} z1={k.capTop-.9}/></jscad.rotate></jscad.translate>)}
{/* Pointer groove on top, aligned with the flat. */}
<Box x={0} y={-k.capRadius/2-.3} w={k.pointerWidth} h={k.capRadius-.4} z0={k.capTop-.5} z1={k.capTop+1}/>
</jscad.subtract>
{k.gripRibs.map(rib)}
</jscad.union></jscad.translate>}
// Removable rear frame with upper-left and lower-right screw ears. M2 screws enter upward into blind
// lid inserts; the screws and clamping load never pass through the display glass.
export function ScreenHolder(){const s=d.screen;return <jscad.subtract>
<jscad.union>
<jscad.subtract>
<RoundBox x={s.x} y={s.panelY} w={s.holderWidth} h={s.holderDepth} r={.5} z0={s.holderBottom} z1={s.holderTop}/>
<Box x={s.x} y={s.panelY} w={s.rearOpeningWidth} h={s.rearOpeningDepth} z0={s.holderBottom-1} z1={s.holderTop+1}/>
</jscad.subtract>
{s.screws.map(([x,y])=><jscad.hull key={`${x}:${y}`}>
<Cylinder x={x} y={y} z0={s.screwSeat} z1={s.screwSeat+1.5} r={2.7}/>
<Cylinder x={x<s.x?s.x-s.holderWidth/2+1:s.x+s.holderWidth/2-1} y={y} z0={s.holderBottom} z1={s.holderTop} r={1}/>
</jscad.hull>)}
</jscad.union>
<Box x={s.x} y={s.panelY-s.panelDepth/2-1.5} w={s.flexExitWidth} h={7} z0={s.holderBottom-1} z1={s.holderTop+1}/>
{s.screws.map(([x,y])=><Cylinder key={`boss-clear-${x}`} x={x} y={y} z0={s.screwSeat+1.5} z1={s.holderTop+1} r={2.85}/>)}
{s.screws.map(([x,y])=><Cylinder key={x} x={x} y={y} z0={s.screwSeat-1} z1={s.holderTop+1} r={1.15}/>)}
</jscad.subtract>}
export const printableParts={base:Base,lid:Lid,"button-plunger":ButtonPlunger,"speed-knob":SpeedKnob,"screen-holder":ScreenHolder,"screen-door":ScreenDoor}