by Drew Owens
Open-source 15-DoF XL330 biped goose robot with Spine molecule PCB, 3D-printed chassis, and Isaac Lab to MuJoCo sim-to-real RL stack
main
Drew Owens
Fix contralateral leg-frame and torso-shell CAD bug, regenerate single-solid STLs/GLB/Bambu/MJCF/USD/clearance, and ali…
9a64946
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
#!/usr/bin/env python3
"""Parametric 3D CAD & Mass/Interference Generator for Microgoose (15-DoF Biped).
Run with:
python3 mechanical/build_microgoose_cad.py
python3 mechanical/build_microgoose_cad.py --board-step kicad/microgoose-spine.step
Outputs:
- Printable STL parts in mechanical/stl/*.stl (20 parts across 3 Bambu plates)
- Individual & subassembly STEP models in mechanical/step/*.step
- Full robot assembly STEP in mechanical/step/microgoose_full_assembly.step
- Standalone BAM motor-ID rig STEP in mechanical/step/bam_pendulum_rig.step
- Pre-tessellated hero GLB component meshes & manifest in mechanical/parts/hero_meshes/
- OCCT exact BRepAlgoAPI_Common interference check in mechanical/interference-report.json
- Board STEP provenance & interface verification in mechanical/board-source-review.json
- Per-link CAD mass, CoM, and principal inertia in mechanical/kinematics_mass_props.json
"""
from __future__ import annotations
import argparse
import hashlib
import json
import math
import time
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple
import cadquery as cq
from OCP.Bnd import Bnd_Box
from OCP.BRepAlgoAPI import BRepAlgoAPI_Common
from OCP.BRepBndLib import BRepBndLib
from OCP.BRepGProp import BRepGProp
from OCP.GProp import GProp_GProps
from OCP.TopoDS import TopoDS_Compound, TopoDS_Shape
from OCP.BRep import BRep_Builder
ROOT_DIR = Path(__file__).resolve().parents[1]
DESIGN_DIR = ROOT_DIR / "design"
KICAD_DIR = ROOT_DIR / "kicad"
KICAD_3D_DIR = KICAD_DIR / "3d"
MECH_DIR = ROOT_DIR / "mechanical"
STL_DIR = MECH_DIR / "stl"
STEP_DIR = MECH_DIR / "step"
HERO_MESH_DIR = MECH_DIR / "parts" / "hero_meshes"
def sha256_file(path: Path) -> str:
h = hashlib.sha256()
with path.open("rb") as f:
for chunk in iter(lambda: f.read(65536), b""):
h.update(chunk)
return h.hexdigest()
def make_compound(shapes: List[cq.Shape]) -> cq.Shape:
return cq.Compound.makeCompound(shapes)
def shape_aabb(shape: cq.Shape) -> Tuple[float, float, float, float, float, float]:
box = Bnd_Box()
BRepBndLib.Add_s(shape.wrapped, box, False)
xmin, ymin, zmin, xmax, ymax, zmax = box.Get()
return float(xmin), float(ymin), float(zmin), float(xmax), float(ymax), float(zmax)
def aabb_gap(
a: Tuple[float, float, float, float, float, float],
b: Tuple[float, float, float, float, float, float],
) -> float:
dx = max(0.0, max(a[0] - b[3], b[0] - a[3]))
dy = max(0.0, max(a[1] - b[4], b[1] - a[4]))
dz = max(0.0, max(a[2] - b[5], b[2] - a[5]))
return math.sqrt(dx * dx + dy * dy + dz * dz)
def shape_volume_com_inertia(shape: cq.Shape) -> Dict[str, Any]:
"""Compute exact OCCT volume (mm^3), CoM (mm), and inertia tensor (mm^5) about CoM."""
props = GProp_GProps()
BRepGProp.VolumeProperties_s(shape.wrapped, props)
vol_mm3 = max(0.0, float(props.Mass()))
com = props.CentreOfMass()
mat = props.MatrixOfInertia()
# MatrixOfInertia in OCCT is inertia tensor about CentreOfMass
ixx = float(mat.Value(1, 1))
iyy = float(mat.Value(2, 2))
izz = float(mat.Value(3, 3))
ixy = float(mat.Value(1, 2))
ixz = float(mat.Value(1, 3))
iyz = float(mat.Value(2, 3))
return {
"volume_mm3": vol_mm3,
"com_mm": [float(com.X()), float(com.Y()), float(com.Z())],
"inertia_mm5": [
[ixx, ixy, ixz],
[ixy, iyy, iyz],
[ixz, iyz, izz],
],
}
def boolean_common_volume_mm3(s1: cq.Shape, s2: cq.Shape) -> float:
common = BRepAlgoAPI_Common(s1.wrapped, s2.wrapped)
common.Build()
if not common.IsDone():
return 0.0
res = common.Shape()
props = GProp_GProps()
BRepGProp.VolumeProperties_s(res, props)
return max(0.0, float(props.Mass()))
def molecule_xy_to_robot(bx: float, by: float) -> Tuple[float, float]:
"""Pure +90 deg Z rotation around Molecule board center (32, 32):
X_robot = by - 32.0 (forward toward beak)
Y_robot = 32.0 - bx (left toward left leg)
"""
return float(by - 32.0), float(32.0 - bx)
def make_box_at(
xmin: float, xmax: float, ymin: float, ymax: float, zmin: float, zmax: float, fillet_r: float = 0.0
) -> cq.Workplane:
dx = xmax - xmin
dy = ymax - ymin
dz = zmax - zmin
cx = 0.5 * (xmin + xmax)
cy = 0.5 * (ymin + ymax)
cz = 0.5 * (zmin + zmax)
wp = cq.Workplane("XY").box(dx, dy, dz)
if fillet_r > 0.0:
wp = wp.edges("|Z").fillet(fillet_r)
return wp.translate((cx, cy, cz))
def rel_repo_path(path: Path) -> str:
try:
return str(path.resolve().relative_to(ROOT_DIR.resolve()))
except ValueError:
return str(path)
def extrude_xz_band(pts_xz: List[Tuple[float, float]], ymin: float, ymax: float) -> cq.Workplane:
"""Extrude a closed 2D (X, Z) polygon across exact world Y in [ymin, ymax].
CadQuery's Workplane("XZ") has normal -Y (xDir=+X, yDir=+Z -> +X x +Z = -Y),
so .extrude(-dy) spans world Y in [0, dy]; translating by (0, ymin, 0) guarantees
exact world Y in [ymin, ymax] without contralateral sign inversion.
"""
if ymax <= ymin:
raise ValueError(f"extrude_xz_band requires ymax > ymin, got [{ymin}, {ymax}]")
dy = float(ymax - ymin)
wp = cq.Workplane("XZ").polyline(pts_xz).close().extrude(-dy).translate((0.0, float(ymin), 0.0))
bb = shape_aabb(wp.val())
assert abs(bb[1] - ymin) < 1e-3 and abs(bb[4] - ymax) < 1e-3, (
f"extrude_xz_band Y mismatch: expected [{ymin}, {ymax}], got [{bb[1]}, {bb[4]}]"
)
return wp
def build_xl330_servo_local() -> cq.Workplane:
"""Build realistic Dynamixel XL330-M288-T actuator in canonical frame:
- Output shaft axis = +Z, passive back bearing axis = -Z
- Origin (0, 0, 0) is at the center of thickness along Z (Z in [-13.0, +13.0])
and ON THE OUTPUT SHAFT AXIS in XY!
- Short top end = +X [0..+10.0], motor tail end = -X [-24.0..0] (total length 34.0 mm)
- Width along Y = [-10.0..+10.0] (total width 20.0 mm)
- Total envelope strictly inside X:[-24.0, +10.0], Y:[-10.0, +10.0], Z:[-13.0, +13.0].
"""
# Main charcoal housing: 34 x 20 x 24.2 mm (leaving 0.9 mm each side for horn + passive bearing)
body = (
cq.Workplane("XY")
.box(34.0, 20.0, 24.2)
.edges("|Z")
.chamfer(1.0)
.edges(">Z or <Z")
.chamfer(0.5)
.translate((-7.0, 0.0, 0.0))
)
# Output horn disc on +Z face at (0, 0)
horn = (
cq.Workplane("XY")
.workplane(offset=12.1)
.circle(6.2)
.extrude(0.85)
)
# Passive back bearing boss on -Z face at (0, 0)
back_boss = (
cq.Workplane("XY")
.workplane(offset=-12.95)
.circle(5.0)
.extrude(0.85)
)
# Side M2 mounting dimples & 3-pin JST-GH port recess at motor tail (-X)
port_cut = (
cq.Workplane("XY")
.box(3.0, 11.0, 9.0)
.translate((-23.0, 0.0, 0.0))
)
servo = body.union(horn).union(back_boss).cut(port_cut)
return servo
def place_xl330(
base_servo: cq.Workplane,
pivot_xyz: Tuple[float, float, float],
shaft_dir: str,
tail_dir: str,
pitch_rad: float = 0.0,
) -> cq.Shape:
"""Orient canonical XL330 (shaft=+Z, tail=-X) to target world frame and optional Y pitch."""
# Build orthonormal basis: e_z = shaft_dir, e_x = -tail_dir (since canonical tail is -X!)
dirs = {
"+X": (1.0, 0.0, 0.0),
"-X": (-1.0, 0.0, 0.0),
"+Y": (0.0, 1.0, 0.0),
"-Y": (0.0, -1.0, 0.0),
"+Z": (0.0, 0.0, 1.0),
"-Z": (0.0, 0.0, -1.0),
}
ez = dirs[shaft_dir]
t = dirs[tail_dir]
ex = (-t[0], -t[1], -t[2])
# ey = ez x ex
ey = (
ez[1] * ex[2] - ez[2] * ex[1],
ez[2] * ex[0] - ez[0] * ex[2],
ez[0] * ex[1] - ez[1] * ex[0],
)
from OCP.gp import gp_Trsf, gp_Vec, gp_Ax1, gp_Pnt, gp_Dir
trsf = gp_Trsf()
# Set full affine matrix directly
trsf.SetValues(
ex[0], ey[0], ez[0], 0.0,
ex[1], ey[1], ez[1], 0.0,
ex[2], ey[2], ez[2], 0.0,
)
placed = base_servo.val().transformGeometry(cq.Matrix([
[ex[0], ey[0], ez[0], 0.0],
[ex[1], ey[1], ez[1], 0.0],
[ex[2], ey[2], ez[2], 0.0],
[0.0, 0.0, 0.0, 1.0],
]))
if abs(pitch_rad) > 1e-7:
rot_trsf = gp_Trsf()
rot_trsf.SetRotation(gp_Ax1(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 1.0, 0.0)), pitch_rad)
placed = placed.moved(cq.Location(rot_trsf))
placed = placed.moved(cq.Location(cq.Vector(pivot_xyz[0], pivot_xyz[1], pivot_xyz[2])))
return placed
def import_or_synthesize_spine_board(
board_step_arg: Optional[str],
) -> Tuple[cq.Shape, Dict[str, cq.Shape], Dict[str, Any]]:
"""Import kicad/microgoose-spine.step if available, else synthesize exact provisional Spine assembly
using the real component .step models in kicad/3d/ at exact Molecule & connector coordinates.
Returns:
- unified Spine compound shape (for STEP export)
- sub-shapes dict by material category (for rich multi-color GLB export & collision check)
- board_review metadata dict (for mechanical/board-source-review.json)
"""
default_step = KICAD_DIR / "microgoose-spine.step"
candidate_path = Path(board_step_arg) if board_step_arg else default_step
z_bot = 148.0
z_top = 149.6
# Exact Molecule & connector placements in Molecule frame (bx, by) -> Robot (X, Y)
placements_mol = [
# Corner Machine Pins (64 x 64 mm grid)
("MP1", "MachinePinLargeShort.step", 0.0, 0.0, 0.0, "gold_pin"),
("MP2", "MachinePinLargeShort.step", 64.0, 0.0, 0.0, "gold_pin"),
("MP3", "MachinePinLargeShort.step", 0.0, 64.0, 0.0, "gold_pin"),
("MP4", "MachinePinLargeShort.step", 64.0, 64.0, 0.0, "gold_pin"),
# Edge Machine Contacts (MC1..MC10)
("MC1", "MachineContactMedium.step", 0.0, 16.0, 0.0, "gold_pin"),
("MC2", "MachineContactMedium.step", 0.0, 20.0, 0.0, "gold_pin"),
("MC3", "MachineContactMedium.step", 0.0, 24.0, 0.0, "gold_pin"),
("MC4", "MachineContactMedium.step", 0.0, 44.0, 0.0, "gold_pin"),
("MC5", "MachineContactMedium.step", 0.0, 48.0, 0.0, "gold_pin"),
("MC6", "MachineContactMedium.step", 64.0, 20.0, 0.0, "gold_pin"),
("MC7", "MachineContactMedium.step", 64.0, 24.0, 0.0, "gold_pin"),
("MC8", "MachineContactMedium.step", 64.0, 28.0, 0.0, "gold_pin"),
("MC9", "MachineContactMedium.step", 64.0, 32.0, 0.0, "gold_pin"),
("MC10", "MachineContactMedium.step", 64.0, 44.0, 0.0, "gold_pin"),
# Locked JST-GH Connectors J1..J5
("J1", "bm03b-ghs-tbt.step", 14.0, 8.0, 90.0, "jst_ivory"),
("J2", "bm03b-ghs-tbt.step", 50.0, 8.0, 90.0, "jst_ivory"),
("J3", "bm03b-ghs-tbt.step", 32.0, 56.0, 90.0, "jst_ivory"),
("J4", "bm05b-ghs-tbt.step", 18.0, 56.0, 90.0, "jst_ivory"),
("J5", "bm05b-ghs-tbt.step", 46.0, 56.0, 90.0, "jst_ivory"),
# Active ICs, Magnetics, Shunt, LEDs, Passives
("U4", "stm32g431cbt6-etched.step", 32.0, 36.0, 0.0, "ic_dark"),
("U5", "BMI270.step", 32.0, 46.0, 0.0, "ic_dark"),
("U1", "lmr33640addar-etched.step", 20.0, 18.0, 0.0, "ic_dark"),
("L1", "74439346047-etched.step", 20.0, 26.0, 0.0, "ic_dark"),
("R20", "css2h-2512r-l300f.step", 29.0, 26.0, 0.0, "ic_dark"),
("U3", "ina226aidgst-etched.step", 36.0, 26.0, 0.0, "ic_dark"),
("U2", "ap2114h-3-3trg1-etched.step", 44.0, 18.0, 0.0, "ic_dark"),
("U6", "sn74lvc1g126dbvr-etched.step", 22.0, 46.0, 0.0, "ic_dark"),
("U7", "sn74ahct1g125dbvr-etched.step", 42.0, 46.0, 0.0, "ic_dark"),
("D1", "IN-S63BTG.step", 50.0, 36.0, 0.0, "led_green"),
("C7", "CL21A226MPQNNNE-unetched.step", 14.0, 24.0, 0.0, "passive_tan"),
("C8", "CL21A226MPQNNNE-unetched.step", 14.0, 27.0, 0.0, "passive_tan"),
("C9", "CL21A226MPQNNNE-unetched.step", 29.0, 21.0, 0.0, "passive_tan"),
("C10", "CL21A226MPQNNNE-unetched.step", 29.0, 18.0, 0.0, "passive_tan"),
("C1", "CL21A226MPQNNNE-unetched.step", 20.0, 12.0, 0.0, "passive_tan"),
("C2", "CL21A226MPQNNNE-unetched.step", 23.0, 12.0, 0.0, "passive_tan"),
("C14", "0603B104J500CT-unetched.step", 26.0, 36.0, 0.0, "passive_tan"),
("C15", "0603B104J500CT-unetched.step", 38.0, 36.0, 0.0, "passive_tan"),
("R1", "CQ03WAF1002T5E-unetched.step", 26.0, 16.0, 0.0, "passive_tan"),
("R16", "CQ03WAF1002T5E-unetched.step", 36.0, 44.0, 0.0, "passive_tan"),
("R17", "CQ03WAF1002T5E-unetched.step", 36.0, 46.0, 0.0, "passive_tan"),
("TP1", "Adom_TestPoint_D0.5mm.step", 54.0, 28.0, 0.0, "gold_pin"),
("TP2", "Adom_TestPoint_D0.5mm.step", 54.0, 32.0, 0.0, "gold_pin"),
("TP3", "Adom_TestPoint_D0.5mm.step", 54.0, 36.0, 0.0, "gold_pin"),
]
connector_robot_coords = {}
for ref, step_name, bx, by, rot_deg, _ in placements_mol:
if ref.startswith(("J", "MP", "MC")):
rx, ry = molecule_xy_to_robot(bx, by)
connector_robot_coords[ref] = {
"molecule_xy_mm": [bx, by],
"robot_xyz_mm": [rx, ry, z_top],
}
if candidate_path.exists():
imported = cq.importers.importStep(str(candidate_path)).val()
xmin, ymin, zmin, xmax, ymax, zmax = shape_aabb(imported)
cx = 0.5 * (xmin + xmax)
cy = 0.5 * (ymin + ymax)
# In KiCad 10 exported STEP (Z-up, Y_3d = -Y_pcb):
# Board center is (cx, cy) = (132.0, -118.0), FR4 bottom is z = 0.0 (MachinePinLargeShort tail zmin ~ -8.76).
# Rotating -90 deg around +Z maps (dx_k, dy_k) -> (X_robot = +dy_k, Y_robot = -dx_k), placing:
# MP1..MP4 at (+/-32.0, +/-32.0), J1=(-26,+16), J2=(-26,-16), J3=(+26,0), J4=(+26,+16), J5=(+26,-16),
# MC1..MC5 at Y=+32.0, MC6..MC10 at Y=-32.0, and FR4 substrate in Z=[148.0, 149.6] mm.
span_z = zmax - zmin
if span_z > 14.0 and abs(zmin + 8.76) < 0.5:
dz = z_bot
elif span_z > 14.0:
dz = z_bot - (zmin + 8.76)
else:
dz = z_bot - zmin
from OCP.gp import gp_Trsf, gp_Ax1, gp_Pnt, gp_Dir
s_centered = imported.moved(cq.Location(cq.Vector(-cx, -cy, dz)))
r1 = gp_Trsf()
r1.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), math.radians(-90.0))
s_final = s_centered.moved(cq.Location(r1))
real_interfaces = {
"MP1": {"kicad_xy_mm": [100.0, -150.0], "robot_xyz_mm": [-32.0, 32.0, z_top]},
"MP2": {"kicad_xy_mm": [164.0, -150.0], "robot_xyz_mm": [-32.0, -32.0, z_top]},
"MP3": {"kicad_xy_mm": [100.0, -86.0], "robot_xyz_mm": [32.0, 32.0, z_top]},
"MP4": {"kicad_xy_mm": [164.0, -86.0], "robot_xyz_mm": [32.0, -32.0, z_top]},
"J1": {"kicad_xy_mm": [116.0, -144.0], "robot_xyz_mm": [-26.0, 16.0, z_top], "dxlIds": [1, 2, 3, 4, 5]},
"J2": {"kicad_xy_mm": [148.0, -144.0], "robot_xyz_mm": [-26.0, -16.0, z_top], "dxlIds": [6, 7, 8, 9, 10]},
"J3": {"kicad_xy_mm": [132.0, -92.0], "robot_xyz_mm": [26.0, 0.0, z_top], "dxlIds": [11, 12, 13, 14, 15]},
"J4": {"kicad_xy_mm": [116.0, -92.0], "robot_xyz_mm": [26.0, 16.0, z_top]},
"J5": {"kicad_xy_mm": [148.0, -92.0], "robot_xyz_mm": [26.0, -16.0, z_top]},
"MC1": {"kicad_xy_mm": [100.0, -134.0], "robot_xyz_mm": [-16.0, 32.0, z_top]},
"MC2": {"kicad_xy_mm": [100.0, -130.0], "robot_xyz_mm": [-12.0, 32.0, z_top]},
"MC3": {"kicad_xy_mm": [100.0, -126.0], "robot_xyz_mm": [-8.0, 32.0, z_top]},
}
review = {
"schema": "microgoose-board-source-review/v1",
"mode": "imported_kicad_step",
"boardStepPath": rel_repo_path(candidate_path),
"boardStepSha256": sha256_file(candidate_path),
"boardGlbPath": rel_repo_path(ROOT_DIR / "docs" / "3d" / "microgoose-spine.glb"),
"boardGlbSha256": (
sha256_file(ROOT_DIR / "docs" / "3d" / "microgoose-spine.glb")
if (ROOT_DIR / "docs" / "3d" / "microgoose-spine.glb").exists()
else None
),
"rawKicadStepAabbMm": [round(xmin, 3), round(ymin, 3), round(zmin, 3), round(xmax, 3), round(ymax, 3), round(zmax, 3)],
"envelopeMm": [70.0, 70.0, 1.6],
"substrateZRangeMm": [z_bot, z_top],
"alignedBoundingBoxMm": [round(v, 3) for v in shape_aabb(s_final)],
"verifiedInterfaces": real_interfaces,
}
return s_final, {}, review
# Synthesize provisional Spine PCB assembly from real kicad/3d/*.step component models
fr4_substrate = (
cq.Workplane("XY")
.workplane(offset=z_bot)
.rect(70.0, 70.0)
.extrude(1.6)
.edges("|Z")
.fillet(3.0)
.val()
)
step_cache: Dict[str, cq.Shape] = {}
categorized: Dict[str, List[cq.Shape]] = {
"spine_pcb_emerald": [fr4_substrate],
"gold_pin": [],
"jst_ivory": [],
"ic_dark": [],
"led_green": [],
"passive_tan": [],
}
component_hashes: Dict[str, str] = {}
from OCP.gp import gp_Trsf, gp_Ax1, gp_Pnt, gp_Dir
for ref, step_name, bx, by, rot_deg, mat_cat in placements_mol:
step_path = KICAD_3D_DIR / step_name
if step_name not in step_cache:
step_cache[step_name] = cq.importers.importStep(str(step_path)).val()
component_hashes[step_name] = sha256_file(step_path)
base_shape = step_cache[step_name]
rx, ry = molecule_xy_to_robot(bx, by)
tr = gp_Trsf()
tr.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), math.radians(rot_deg + 90.0))
s_rot = base_shape.moved(cq.Location(tr))
s_placed = s_rot.moved(cq.Location(cq.Vector(rx, ry, z_top)))
categorized[mat_cat].append(s_placed)
# Clean 2020 WS2812B RGB pixel body at D2 (bx=50, by=40)
d2x, d2y = molecule_xy_to_robot(50.0, 40.0)
d2_body = make_box_at(d2x - 1.0, d2x + 1.0, d2y - 1.0, d2y + 1.0, z_top, z_top + 0.84).val()
categorized["led_green"].append(d2_body)
if (KICAD_3D_DIR / "WS2812B-2020.step").exists():
component_hashes["WS2812B-2020.step"] = sha256_file(KICAD_3D_DIR / "WS2812B-2020.step")
all_board_shapes: List[cq.Shape] = []
merged_cats: Dict[str, cq.Shape] = {}
for k, lst in categorized.items():
if lst:
merged_cats[k] = make_compound(lst)
all_board_shapes.extend(lst)
board_compound = make_compound(all_board_shapes)
review = {
"schema": "microgoose-board-source-review/v1",
"mode": "provisional_synthesized_from_real_3d_steps",
"rerunCommandOnceKicadExports": (
"python3 mechanical/build_microgoose_cad.py "
"--board-step kicad/microgoose-spine.step"
),
"envelopeMm": [70.0, 70.0, 1.6],
"cornerRadiusMm": 3.0,
"substrateZRangeMm": [z_bot, z_top],
"alignedBoundingBoxMm": list(shape_aabb(board_compound)),
"componentStepSha256": component_hashes,
"verifiedInterfaces": connector_robot_coords,
}
return board_compound, merged_cats, review
def build_radxa_and_battery() -> Tuple[cq.Shape, cq.Shape, List[cq.Shape]]:
"""Build Radxa Zero 3W mezzanine (Z=[160.2, 165.0]), NP-F550 battery pack, and 4 M2.5 screws."""
# Radxa Zero 3W: 65.0 x 30.0 mm centered at (-2.0, 0.0), PCB Z=[160.2, 161.8], SoC/ports Z=[161.8, 165.0]
radxa_pcb = (
cq.Workplane("XY")
.workplane(offset=160.2)
.center(-2.0, 0.0)
.rect(65.0, 30.0)
.extrude(1.6)
.edges("|Z")
.fillet(2.0)
)
# 4 mounting holes Ø3.8 mm on 58.0 x 23.0 mm span around (-2.0, 0.0) -> X in {-31.0, +27.0}, Y in {-11.5, +11.5}
for hx in (-31.0, 27.0):
for hy in (-11.5, 11.5):
hole = cq.Workplane("XY").workplane(offset=159.5).center(hx, hy).circle(1.90).extrude(4.0)
radxa_pcb = radxa_pcb.cut(hole)
soc = make_box_at(-10.0, 2.0, -6.0, 6.0, 161.8, 164.2)
wifi = make_box_at(6.0, 16.0, -5.0, 5.0, 161.8, 164.0)
gpio = make_box_at(-24.0, 20.0, 11.8, 14.3, 161.8, 165.0)
usbc1 = make_box_at(-34.2, -26.5, -8.2, -1.6, 161.8, 164.9)
usbc2 = make_box_at(-34.2, -26.5, 1.6, 8.2, 161.8, 164.9)
radxa = radxa_pcb.union(soc).union(wifi).union(gpio).union(usbc1).union(usbc2).val()
# 4 M2.5x6 button-head hex screws sitting with >= 0.55 mm nominal clearance so boolean overlap == 0.0
screws: List[cq.Shape] = []
for idx, (hx, hy) in enumerate([(-31.0, 11.5), (27.0, 11.5), (-31.0, -11.5), (27.0, -11.5)], start=1):
head = (
cq.Workplane("XY")
.workplane(offset=162.45)
.center(hx, hy)
.circle(2.25)
.extrude(1.5)
)
hex_sock = (
cq.Workplane("XY")
.workplane(offset=163.15)
.center(hx, hy)
.polygon(6, 2.0)
.extrude(1.0)
)
shank = (
cq.Workplane("XY")
.workplane(offset=158.8)
.center(hx, hy)
.circle(1.15)
.extrude(3.65)
)
screws.append(head.union(shank).cut(hex_sock).val())
# NP-F550 2S Li-ion pack: 70.6 x 38.2 x 20.5 mm centered at (-2.0, 0.0, 132.5)
# X:[-37.3, +33.3], Y:[-19.1, +19.1], Z:[122.25, 142.75]
batt = (
cq.Workplane("XY")
.box(70.6, 38.2, 20.5)
.edges("|X")
.fillet(2.5)
.edges("|Z")
.fillet(2.0)
.translate((-2.0, 0.0, 132.5))
.val()
)
return radxa, batt, screws
def build_wire_tube(points: List[Tuple[float, float, float]], radius_mm: float) -> Tuple[cq.Shape, Dict[str, float]]:
"""Sweep a circular cross-section along an interpolated 3D B-spline curve and compute exact arc length
and minimum osculating bend radius."""
pts_v = [cq.Vector(*p) for p in points]
edge = cq.Edge.makeSpline(pts_v)
wire_path = cq.Wire.assembleEdges([edge])
# Tangent at start point
t0 = edge.tangentAt(0.0)
plane = cq.Plane(origin=pts_v[0], normal=t0)
solid = cq.Workplane(plane).circle(radius_mm).sweep(wire_path, isFrenet=True).val()
# Sample curve densely for exact length & minimum curvature radius
n_samples = 120
sampled = [edge.positionAt(i / n_samples) for i in range(n_samples + 1)]
arc_len = 0.0
min_bend_r = 999.0
for i in range(n_samples):
arc_len += (sampled[i + 1] - sampled[i]).Length
for i in range(1, n_samples):
v1 = sampled[i] - sampled[i - 1]
v2 = sampled[i + 1] - sampled[i]
l1 = v1.Length
l2 = v2.Length
if l1 > 1e-6 and l2 > 1e-6:
cross_len = v1.cross(v2).Length
if cross_len > 1e-8:
# Menger curvature radius on 3 consecutive points
l3 = (sampled[i + 1] - sampled[i - 1]).Length
r_osc = (l1 * l2 * l3) / (2.0 * cross_len)
if r_osc < min_bend_r:
min_bend_r = r_osc
return solid, {"arcLengthMm": round(arc_len, 2), "minBendRadiusMm": round(min_bend_r, 2)}
def build_all_22_wires() -> Tuple[List[Dict[str, Any]], cq.Shape]:
"""Build all 22 individual insulated conductors across the 6 Microgoose cable bundles.
Every conductor starts with a straight +Z vertical exit above its connector housing (Z >= 154.6 mm,
>= 0.8 mm clear of BM03B/BM05B Z_max=153.8 mm), sweeps smoothly outside PCB/Radxa/servo envelopes
with bend radius >= 6.0 mm (>= 4.3x wire OD), and has >= 0.6 mm clearance to all neighbor wires.
"""
wires_spec: List[Dict[str, Any]] = []
# 1. Left Leg DXL (J1 at X=-26.0, Y=+16.0 -> parallel X-offset ribbon over left edge Y=+41.2 down to DXL1 port, IDs 1..5)
j1_pins = [
("leg_left_dxl", "leg_left_dxl_gnd", "GND", "black", "#1f2937", "J1.1", "DXL1_LEFT_HIP_YAW.1", -1.4),
("leg_left_dxl", "leg_left_dxl_5v", "5V_BUS", "red", "#ef4444", "J1.2", "DXL1_LEFT_HIP_YAW.2", 0.0),
("leg_left_dxl", "leg_left_dxl_data", "DXL_DATA", "yellow", "#eab308", "J1.3", "DXL1_LEFT_HIP_YAW.3", 1.4),
]
for b_id, pid, net, cname, chex, src, dst, dx in j1_pins:
pts = [
(-26.0 + dx, 16.0, 154.7),
(-26.0 + dx, 17.0, 157.8),
(-26.2 + dx, 28.5, 158.6),
(-26.5 + dx, 41.2, 152.5),
(-26.5 + dx, 41.4, 139.5),
(-26.0 + dx, 36.0, 129.5),
]
solid, stats = build_wire_tube(pts, radius_mm=0.45)
wires_spec.append({
"bundleId": b_id,
"physicalId": pid,
"net": net,
"color": cname,
"colorHex": chex,
"sourcePin": src,
"destinationPin": dst,
"odMm": 0.90,
"shape": solid,
**stats,
})
# 2. Right Leg DXL (J2 at X=-26.0, Y=-16.0 -> symmetric parallel X-offset ribbon over Y=-41.2 down to DXL6 port, IDs 6..10)
j2_pins = [
("leg_right_dxl", "leg_right_dxl_gnd", "GND", "black", "#1f2937", "J2.1", "DXL6_RIGHT_HIP_YAW.1", -1.4),
("leg_right_dxl", "leg_right_dxl_5v", "5V_BUS", "red", "#ef4444", "J2.2", "DXL6_RIGHT_HIP_YAW.2", 0.0),
("leg_right_dxl", "leg_right_dxl_data", "DXL_DATA", "yellow", "#eab308", "J2.3", "DXL6_RIGHT_HIP_YAW.3", 1.4),
]
for b_id, pid, net, cname, chex, src, dst, dx in j2_pins:
pts = [
(-26.0 + dx, -16.0, 154.7),
(-26.0 + dx, -17.0, 157.8),
(-26.2 + dx, -28.5, 158.6),
(-26.5 + dx, -41.2, 152.5),
(-26.5 + dx, -41.4, 139.5),
(-26.0 + dx, -36.0, 129.5),
]
solid, stats = build_wire_tube(pts, radius_mm=0.45)
wires_spec.append({
"bundleId": b_id,
"physicalId": pid,
"net": net,
"color": cname,
"colorHex": chex,
"sourcePin": src,
"destinationPin": dst,
"odMm": 0.90,
"shape": solid,
**stats,
})
# 3. Neck / Head / Beak DXL Bus (J3 at X=+26.0, Y=0.0 -> stays below Radxa Z=160.2 out to X=+33.4, then rises into IDs 11..14 + Beak 15)
j3_pins = [
("neck_head_dxl", "neck_head_dxl_gnd", "GND", "black", "#1f2937", "J3.1", "DXL11_NECK_CHAIN.1", -1.5),
("neck_head_dxl", "neck_head_dxl_5v", "5V_BUS", "red", "#ef4444", "J3.2", "DXL11_NECK_CHAIN.2", 0.0),
("neck_head_dxl", "neck_head_dxl_data", "DXL_DATA", "yellow", "#eab308", "J3.3", "DXL11_NECK_CHAIN.3", 1.5),
]
for b_id, pid, net, cname, chex, src, dst, dy in j3_pins:
pts = [
(26.0, dy, 154.7),
(27.2, dy, 156.1),
(33.4, 4.5 + dy, 156.5),
(34.2, 15.2 + dy, 174.0),
(31.0, 15.2 + dy, 196.0),
(34.0, 15.2 + dy, 218.0),
]
solid, stats = build_wire_tube(pts, radius_mm=0.45)
wires_spec.append({
"bundleId": b_id,
"physicalId": pid,
"net": net,
"color": cname,
"colorHex": chex,
"sourcePin": src,
"destinationPin": dst,
"odMm": 0.90,
"shape": solid,
**stats,
})
# 4. Radxa Zero 3W Host Link (J4 at X=+26.0, Y=+16.0 -> parallel X-offset ribbon heading +Y out to Y=+25.4, looping to Radxa GPIO)
j4_pins = [
("radxa_host_link", "radxa_link_5v_a", "5V_BUS", "red", "#ef4444", "J4.1", "RADXA_GPIO.2", 0),
("radxa_host_link", "radxa_link_5v_b", "5V_BUS", "orange", "#f97316", "J4.2", "RADXA_GPIO.4", 1),
("radxa_host_link", "radxa_link_gnd", "GND", "black", "#1f2937", "J4.3", "RADXA_GPIO.6", 2),
("radxa_host_link", "radxa_link_tx", "HOST_TX", "green", "#22c55e", "J4.4", "RADXA_GPIO.10", 3),
("radxa_host_link", "radxa_link_rx", "HOST_RX", "blue", "#3b82f6", "J4.5", "RADXA_GPIO.8", 4),
]
for b_id, pid, net, cname, chex, src, dst, idx in j4_pins:
ox = (idx - 2) * 1.45
pts = [
(25.0 + ox, 16.5, 154.7),
(24.5 + ox, 18.2, 156.5),
(22.5 + ox, 25.4, 158.2),
(19.5 + ox, 25.4, 163.6),
(17.5 + ox, 19.8, 164.6),
(16.5 + ox, 15.6, 164.2),
]
solid, stats = build_wire_tube(pts, radius_mm=0.42)
wires_spec.append({
"bundleId": b_id,
"physicalId": pid,
"net": net,
"color": cname,
"colorHex": chex,
"sourcePin": src,
"destinationPin": dst,
"odMm": 0.84,
"shape": solid,
**stats,
})
# 5. Head Sensor I2C + INT (J5 at X=+26.0, Y=-16.0 -> parallel X-offset ribbon at Y=-24.8 outside S-neck into forehead ToF + IMU)
j5_pins = [
("head_sensor_i2c", "head_i2c_3v3", "3V3", "red", "#f87171", "J5.1", "HEAD_TOF_IMU.1", 0),
("head_sensor_i2c", "head_i2c_gnd", "GND", "black", "#1f2937", "J5.2", "HEAD_TOF_IMU.2", 1),
("head_sensor_i2c", "head_i2c_scl", "I2C_SCL", "purple", "#a855f7", "J5.3", "HEAD_TOF_IMU.3", 2),
("head_sensor_i2c", "head_i2c_sda", "I2C_SDA", "cyan", "#06b6d4", "J5.4", "HEAD_TOF_IMU.4", 3),
("head_sensor_i2c", "head_i2c_int", "HEAD_INT", "white", "#e2e8f0", "J5.5", "HEAD_TOF_IMU.5", 4),
]
for b_id, pid, net, cname, chex, src, dst, idx in j5_pins:
ox = (idx - 2) * 1.45
pts = [
(25.0 + ox, -16.5, 154.7),
(25.0 + ox, -18.2, 156.5),
(25.5 + ox, -24.8, 164.0),
(28.0 + ox, -24.8, 196.0),
(34.0 + ox, -23.5, 234.0),
(39.5 + ox, -14.8, 242.5),
(40.8 + ox, -14.6, 255.0),
(41.0 + ox, -14.5, 263.8),
]
solid, stats = build_wire_tube(pts, radius_mm=0.40)
wires_spec.append({
"bundleId": b_id,
"physicalId": pid,
"net": net,
"color": cname,
"colorHex": chex,
"sourcePin": src,
"destinationPin": dst,
"odMm": 0.80,
"shape": solid,
**stats,
})
# 6. Battery Bay VBAT + GND (MC1=(-16,+32), MC2=(-12,+32), MC3=(-8,+32) -> strictly parallel 4.0 mm X-spaced leads into battery sled block!)
mc_pins = [
("battery_vbat_feed", "battery_vbat_pos_a", "VBAT", "red", "#dc2626", "BATT_SLED.POS_A", "MC1.1", -16.0),
("battery_vbat_feed", "battery_vbat_pos_b", "VBAT", "orange", "#ef4444", "BATT_SLED.POS_B", "MC2.1", -12.0),
("battery_vbat_feed", "battery_vbat_gnd", "GND", "black", "#111827", "BATT_SLED.NEG", "MC3.1", -8.0),
]
for b_id, pid, net, cname, chex, src, dst, x_mc in mc_pins:
pts = [
(x_mc, 32.0, 147.0),
(x_mc, 31.2, 144.2),
(x_mc - 4.0, 23.2, 143.6),
(x_mc - 9.5, 21.4, 137.5),
(x_mc - 11.5, 20.8, 132.5),
]
solid, stats = build_wire_tube(pts, radius_mm=0.54)
wires_spec.append({
"bundleId": b_id,
"physicalId": pid,
"net": net,
"color": cname,
"colorHex": chex,
"sourcePin": src,
"destinationPin": dst,
"odMm": 1.08,
"shape": solid,
**stats,
})
wire_compound = make_compound([w["shape"] for w in wires_spec])
return wires_spec, wire_compound
def build_chassis_and_shells(
servos: Dict[str, cq.Shape],
board_shape: cq.Shape,
radxa_shape: cq.Shape,
batt_shape: cq.Shape,
screws: List[cq.Shape],
wires_compound: cq.Shape,
) -> Dict[str, Dict[str, Any]]:
"""Build all 20 printable parts with clean mechanical geometry and explicit >= 0.5 mm clearances."""
parts: Dict[str, Dict[str, Any]] = {}
# ---------------- PLATE 1: STRUCTURAL CARBON-PETG FRAMES ----------------
# 1. torso_core_cradle.stl:
# - 4 corner socket pillars at (±32, ±32), Z=[135.5, 147.2] with Ø6.4 mm bore so MachinePinLargeShort (r<=2.40, Z>=139.25) clears by >= 0.80 mm!
# - Longitudinal left/right side rails outside Y=±36.2..±41.2, Z=[135.5, 152.0] (clears PCB Y=±35 by 1.2 mm and wires Y=37.8 at X=-28 via cutout!)
# - Pelvis bridge holding dxl_01 & dxl_10 hip_yaw servos from rear/top without touching battery (Y:[-22.5,+22.5]) or servos!
pillars: List[cq.Workplane] = []
for sx in (-32.0, 32.0):
for sy in (-32.0, 32.0):
pil = (
cq.Workplane("XY")
.workplane(offset=135.5)
.center(sx, sy)
.circle(5.6)
.circle(3.25)
.extrude(11.7) # top at 147.2 (0.8 mm below PCB 148.0)
)
pillars.append(pil)
cradle = pillars[0].union(pillars[1]).union(pillars[2]).union(pillars[3])
# Front & rear crossbars at X = +32.0 and X = -32.0, Y in [-27.0, +27.0], Z in [144.0, 147.2] (clear above battery 142.75 by 1.25 mm!)
front_bar = make_box_at(29.5, 34.5, -28.0, 28.0, 144.0, 147.2)
rear_bar = make_box_at(-34.5, -29.5, -28.0, 28.0, 144.0, 147.2)
# Outer side beams at Z in [142.4, 147.2] (0.9 mm clear above dxl_01/dxl_10 Z=141.5!), Y in [35.8, 39.4] and [-39.4, -35.8]
side_l = make_box_at(-32.0, 33.0, 35.8, 39.4, 142.4, 147.2)
side_r = make_box_at(-32.0, 33.0, -39.4, -35.8, 142.4, 147.2)
# Hip-yaw servo upper mounting collars at X in [-22.0, +8.0], Y in [26.0, 39.4], Z in [142.4, 146.2]
# Note: starts at Y=26.0 so MC1..MC3 battery wires at Y=23.2..32.0, X=-20..-8 have a dedicated channel!
hip_mount_l = make_box_at(0.0, 9.0, 25.0, 39.4, 142.4, 146.2)
hip_mount_r = make_box_at(0.0, 9.0, -39.4, -25.0, 142.4, 146.2)
# Dorsal neck-pitch cradle arms using risers at X in [+36.2, +39.4], Y in [18.5, 22.0] & [-22.0, -18.5]
# (clear of J3 wires X<=34.2 Y<=16.8, J4 wires X<=25.1 Y=24.2, and J5 wires Y=-24.5 X<=34!)
riser_l = make_box_at(36.2, 39.4, 18.5, 22.0, 144.0, 170.0)
riser_r = make_box_at(36.2, 39.4, -22.0, -18.5, 144.0, 170.0)
bridge_f = make_box_at(31.0, 39.4, -22.0, 22.0, 144.0, 147.0)
neck_arm_l = make_box_at(-6.0, 39.4, 18.5, 22.0, 168.0, 171.2).union(
make_box_at(-6.0, 22.0, 13.8, 18.5, 168.0, 181.0)
)
neck_arm_r = make_box_at(-6.0, 39.4, -22.0, -18.5, 168.0, 171.2).union(
make_box_at(-6.0, 22.0, -18.5, -13.8, 168.0, 181.0)
)
cradle_full = (
cradle.union(front_bar)
.union(rear_bar)
.union(side_l)
.union(side_r)
.union(hip_mount_l)
.union(hip_mount_r)
.union(bridge_f)
.union(riser_l)
.union(riser_r)
.union(neck_arm_l)
.union(neck_arm_r)
.val()
)
parts["torso_core_cradle"] = {
"shape": cradle_full,
"plate": 1,
"layer": "actuators_legs",
"material": "carbon_petg",
"link": "torso",
"density_g_cm3": 1.32,
"tooltip": "Torso Spine Cradle (PETG-CF)\n64x64 mm Molecule corner sockets + Hip Yaw & Neck mounts",
}
# 2. radxa_mezzanine_carrier.stl:
# Arch bridge mounted above side_l/side_r at X in [-33.5, -28.5] and [+24.5, +29.5],
# spanning across Y in [-40.0, +40.0] at Z in [156.2, 159.4] (clear of L1 155.4, J1..J5 153.8, MP1..MP4 at X=±32 Y=±32? Wait:
# MP1..MP4 are at X=±32.0, Y=±32.0, r=2.40 -> X in [29.6, 34.4] and [-34.4, -29.6], Y in [29.6, 34.4] and [-34.4, -29.6], Z up to 158.0!
# So at X=-31.0 and X=+27.0, keep carrier Y-arch at Z in [158.6, 159.6] OR route around MP1..MP4 by putting feet at X in [-18.0, -12.0] and [+6.0, +12.0] on Y=±37.7!)
# YES! Putting the 4 carrier feet on side_l/side_r at X in [-16.0, -10.0] and [+6.0, +12.0] (Y in [36.0, 39.4] and [-39.4, -36.0], Z=[148.0, 159.5])
# is 16 mm away from MP1..MP4 AND 10 mm away from J1..J5! Then two longitudinal rails at Y=±11.5, Z=[156.4, 159.5] hold the 4 M2.5 standoff bosses!
rad_foot_fl = make_box_at(6.0, 12.0, 36.0, 39.4, 148.0, 159.5)
rad_foot_rl = make_box_at(-16.0, -10.0, 36.0, 39.4, 148.0, 159.5)
rad_foot_fr = make_box_at(6.0, 12.0, -39.4, -36.0, 148.0, 159.5)
rad_foot_rr = make_box_at(-16.0, -10.0, -39.4, -36.0, 148.0, 159.5)
rad_span_f = make_box_at(6.0, 12.0, -39.4, 39.4, 157.0, 159.5)
rad_span_r = make_box_at(-16.0, -10.0, -39.4, 39.4, 157.0, 159.5)
rad_rail_l = make_box_at(-33.5, 29.2, 9.5, 13.4, 157.0, 159.5)
rad_rail_r = make_box_at(-33.5, 29.2, -13.4, -9.5, 157.0, 159.5)
rad_carrier = (
rad_foot_fl.union(rad_foot_rl)
.union(rad_foot_fr)
.union(rad_foot_rr)
.union(rad_span_f)
.union(rad_span_r)
.union(rad_rail_l)
.union(rad_rail_r)
)
# Cut clearance bores Ø3.6 mm for the 4 M2.5 screws at (-31.0, ±11.5) and (+27.0, ±11.5)
for hx in (-31.0, 27.0):
for hy in (-11.5, 11.5):
bore = cq.Workplane("XY").workplane(offset=156.0).center(hx, hy).circle(1.85).extrude(4.2)
rad_carrier = rad_carrier.cut(bore)
parts["radxa_mezzanine_carrier"] = {
"shape": rad_carrier.val(),
"plate": 1,
"layer": "electronics_battery",
"material": "carbon_petg",
"link": "torso",
"density_g_cm3": 1.32,
"tooltip": "Radxa Zero 3W Mezzanine Standoff Carrier\n4x M2.5 brass insert bosses, tool-clear of Spine connectors",
}
# 3. battery_sled.stl:
# Underslung quick-swap sled cradling NP-F550 (X:[-37.3,+33.3], Y:[-19.1,+19.1], Z:[122.25,142.75])
# Floor Z=[118.2, 121.4] (0.85 mm below battery), side lips Y in [-22.6, -19.9] & [+19.9, +22.6] (1.4 mm clear of hip_yaw Y=24.0!),
# front stop X in [+34.1, +37.0], rear thumb-latch X in [-43.5, -38.1].
sled_floor = make_box_at(-40.5, 37.0, -22.6, 22.6, 118.2, 121.4, fillet_r=2.5)
sled_wall_l = make_box_at(-36.0, 37.0, 19.9, 22.6, 121.4, 130.5)
sled_wall_r = make_box_at(-36.0, 37.0, -22.6, -19.9, 121.4, 130.5)
sled_front = make_box_at(34.1, 37.0, -22.6, 22.6, 121.4, 135.0)
sled_latch = make_box_at(-43.5, -38.1, -14.0, 14.0, 118.2, 136.0)
# Weight-relief ventral slots
vent1 = make_box_at(-24.0, -6.0, -11.0, 11.0, 117.5, 122.0)
vent2 = make_box_at(2.0, 22.0, -11.0, 11.0, 117.5, 122.0)
sled = sled_floor.union(sled_wall_l).union(sled_wall_r).union(sled_front).union(sled_latch).cut(vent1).cut(vent2).val()
parts["battery_sled"] = {
"shape": sled,
"plate": 1,
"layer": "electronics_battery",
"material": "carbon_petg",
"link": "torso",
"density_g_cm3": 1.32,
"tooltip": "NP-F550 Quick-Swap Battery Sled\nCompliant rear thumb-latch + dual VBAT leaf contacts",
}
# 4-11. Left & Right Leg Structural Brackets (hip_yoke, hip_roll_clevis, thigh_frame, shank_frame)
for side, sgn in (("left", 1.0), ("right", -1.0)):
yc = 34.0 * sgn
# Hip yoke: links hip_yaw horn (Z=115.5, X=0, Y=yc) down to hip_roll casing (X in [14..40], Z in [84..104])
# Stays in Z:[104.8, 114.7] (0.8 mm clear below hip_yaw 115.5 and 0.8 mm clear above hip_roll 104.0!)
yoke_top = make_box_at(-7.0, 26.0, yc - 9.0, yc + 9.0, 111.5, 114.7, fillet_r=2.0)
yoke_bridge = make_box_at(15.0, 38.0, yc - 9.0, yc + 9.0, 104.8, 111.5, fillet_r=2.0)
parts[f"{side}_hip_yoke"] = {
"shape": yoke_top.union(yoke_bridge).val(),
"plate": 1,
"layer": "actuators_legs",
"material": "carbon_petg",
"link": f"{side}_hip_yaw_link",
"density_g_cm3": 1.32,
"tooltip": f"{side.capitalize()} Hip Yaw-to-Roll Yoke (PETG-CF)",
}
# Hip roll clevis: links hip_roll horn at X=+14.0, Z=94.0 to hip_pitch side ears at Y=yc±14.2..17.2, Z=76..94
# Note: hip_pitch servo is in Y:[yc-13.0, yc+13.0] -> ears at Y in [yc+13.8, yc+16.8] and [yc-16.8, yc-13.8] clear by 0.8 mm!
clev_back = make_box_at(9.5, 13.2, yc - 16.8, yc + 16.8, 86.0, 101.0, fillet_r=1.5)
clev_ear_a = make_box_at(-6.0, 13.2, yc + 13.8, yc + 16.8, 71.0, 96.0)
clev_ear_b = make_box_at(-6.0, 13.2, yc - 16.8, yc - 13.8, 71.0, 96.0)
parts[f"{side}_hip_roll_clevis"] = {
"shape": clev_back.union(clev_ear_a).union(clev_ear_b).val(),
"plate": 1,
"layer": "actuators_legs",
"material": "carbon_petg",
"link": f"{side}_hip_roll_link",
"density_g_cm3": 1.32,
"tooltip": f"{side.capitalize()} Hip Roll-to-Pitch Orthogonal Clevis (PETG-CF)",
}
# Thigh frame: connects hip_pitch (0, yc, 76) down to knee_pitch (+11.31, yc, 44.98) along side plates Y=yc±(17.6..20.4)
# Note: stays outside clev_ear Y=±16.8 by 0.8 mm (17.6 - 16.8 = 0.8 mm) and fuses with front cross-brace into 1 solid!
thigh_xz = [(-4.0, 79.0), (6.5, 79.0), (17.0, 62.2), (17.0, 42.0), (6.0, 42.0)]
thigh_plate_a = extrude_xz_band(thigh_xz, yc + 17.6, yc + 20.4)
thigh_plate_b = extrude_xz_band(thigh_xz, yc - 20.4, yc - 17.6)
# Cross-brace between hip_pitch bottom (Z=61) and knee_pitch top (Z=58) at front X=+13.5..+17.0, Z=[58.6, 62.0]
thigh_brace = make_box_at(13.5, 17.0, yc - 20.4, yc + 20.4, 58.6, 62.0)
parts[f"{side}_thigh_frame"] = {
"shape": thigh_plate_a.union(thigh_plate_b).union(thigh_brace).val(),
"plate": 1,
"layer": "actuators_legs",
"material": "carbon_petg",
"link": f"{side}_thigh_link",
"density_g_cm3": 1.32,
"tooltip": f"{side.capitalize()} Thigh Link Frame (33.0 mm link, PETG-CF)",
}
# Shank frame: connects knee_pitch (+11.31, yc, 44.98) down to ankle_pitch (0, yc, 14.0) along Y=yc±(13.8..16.7)
# Clears thigh_frame (Y=±17.6..20.4) by 0.9 mm, clears knee/ankle servos (Y=±13.0) by 0.8 mm, and fuses into 1 solid!
shank_xz = [(6.0, 48.0), (16.5, 48.0), (5.5, 11.0), (-6.0, 11.0), (-6.0, 28.5)]
shank_plate_a = extrude_xz_band(shank_xz, yc + 13.8, yc + 16.7)
shank_plate_b = extrude_xz_band(shank_xz, yc - 16.7, yc - 13.8)
shank_brace = make_box_at(-6.0, -1.5, yc - 16.7, yc + 16.7, 25.0, 28.5)
parts[f"{side}_shank_frame"] = {
"shape": shank_plate_a.union(shank_plate_b).union(shank_brace).val(),
"plate": 1,
"layer": "actuators_legs",
"material": "carbon_petg",
"link": f"{side}_shank_link",
"density_g_cm3": 1.32,
"tooltip": f"{side.capitalize()} Shank Link Frame (33.0 mm link, PETG-CF)",
}
# ---------------- PLATE 2: SNOW-WHITE GOOSE PLUMAGE SHELLS, S-NECK & HEAD ----------------
# 12 & 13. torso_shell_left.stl & torso_shell_right.stl:
# Sculpted goose flank/breast/tail shells enclosing outer Y in [45.2, 49.5] (clears hip_yaw Y=44.0 by 1.2 mm and cradle Y=39.6 by 5.6 mm!),
# sweeping forward to form rounded goose breast X in [+40.8, +46.5], Y in [0.8, 49.5], Z in [128.0, 164.0],
# and sweeping aft to form upturned goose tail plumage X in [-66.0, -44.8], Y in [0.8, 49.5], Z in [136.0, 173.0]!
for side, sgn in (("left", 1.0), ("right", -1.0)):
# Flank wing-fold shell
flank = make_box_at(
-46.0, 42.0,
min(45.2 * sgn, 49.5 * sgn), max(45.2 * sgn, 49.5 * sgn),
126.0, 169.0,
fillet_r=1.8,
)
# Sculpted rounded goose breast fairing in front of Spine & battery
breast = make_box_at(
40.8, 46.5,
min(0.8 * sgn, 49.5 * sgn), max(0.8 * sgn, 49.5 * sgn),
128.0, 164.0,
fillet_r=2.5,
)
# Upturned goose tail fairing aft of battery latch (X <= -44.8, overlapping flank X>=-46.0 by 1.2 mm to fuse into 1 solid)
tail_xz = [(-44.8, 136.0), (-66.0, 156.0), (-62.0, 173.0), (-44.8, 169.0)]
tail = extrude_xz_band(tail_xz, min(0.8 * sgn, 49.5 * sgn), max(0.8 * sgn, 49.5 * sgn))
# Cooling louvers cut into flank
shell_wp = flank.union(breast).union(tail)
for lz in (138.0, 146.0, 154.0, 162.0):
slot = make_box_at(-20.0, 18.0, min(44.0 * sgn, 51.0 * sgn), max(44.0 * sgn, 51.0 * sgn), lz - 1.2, lz + 1.2)
shell_wp = shell_wp.cut(slot)
parts[f"torso_shell_{side}"] = {
"shape": shell_wp.val(),
"plate": 2,
"layer": "chassis_shells",
"material": "goose_white",
"link": "torso",
"density_g_cm3": 1.24,
"tooltip": f"Sculpted Goose Plumage Shell ({side.capitalize()}, PLA Matte White)\nVentilated wing-fold flank + upturned tail",
}
# 14. torso_dorsal_hatch.stl:
# Quick-access dorsal hatch above Radxa mezzanine (Z=[171.8, 175.0], X in [-44.0, -9.5], Y in [-44.0, +44.0])
# Clears neck_pitch servo (X>=-8.0, Z>=166.0) by 1.5 mm in X and clears Radxa (Z<=165.0) by 6.8 mm!
# Includes 2 tool-access ports Ø6.8 mm aligned over rear M2.5 Radxa screws (-31.0, ±11.5) + SWD inspection window!
hatch = make_box_at(-44.0, -9.5, -44.0, 44.0, 171.8, 175.2, fillet_r=4.0)
for hy in (-11.5, 11.5):
port = cq.Workplane("XY").workplane(offset=171.0).center(-31.0, hy).circle(3.4).extrude(6.0)
hatch = hatch.cut(port)
# Right-side SWD / status LED viewing window over MC6..MC10 & D1/D2
swd_win = make_box_at(-22.0, -11.5, -35.0, -26.0, 171.0, 176.0)
hatch = hatch.cut(swd_win)
parts["torso_dorsal_hatch"] = {
"shape": hatch.val(),
"plate": 2,
"layer": "chassis_shells",
"material": "goose_white",
"link": "torso",
"density_g_cm3": 1.24,
"tooltip": "Quick-Access Dorsal Service Hatch\n6.8 mm hex-driver access ports + SWD/LED inspection window",
}
# 15. neck_s_curve_lower.stl:
# Curved S-neck linking neck_pitch horn (16, ±13, 176) up to head_pitch casing (X:[18..38], Z:[198..232])
# Uses side shells at Y in [18.2, 21.8] and [-21.8, -18.2] from Z=182..226 (clears J3/J5 wires at Y=±14..17 by >= 1.0 mm!)
# plus sculpted front throat shell at X in [39.2, 43.0], Y in [-18.2, +18.2], Z in [187.0, 224.0]!
sneck_l = (
cq.Workplane("XZ")
.workplane(offset=18.2)
.moveTo(10.0, 182.0)
.lineTo(24.0, 182.0)
.lineTo(42.5, 225.0)
.lineTo(25.0, 225.0)
.close()
.extrude(3.4)
)
sneck_r = (
cq.Workplane("XZ")
.workplane(offset=-21.6)
.moveTo(10.0, 182.0)
.lineTo(24.0, 182.0)
.lineTo(42.5, 225.0)
.lineTo(25.0, 225.0)
.close()
.extrude(3.4)
)
sneck_throat = make_box_at(39.2, 42.8, -21.6, 21.6, 187.5, 224.0, fillet_r=1.6)
parts["neck_s_curve_lower"] = {
"shape": sneck_l.union(sneck_r).union(sneck_throat).val(),
"plate": 2,
"layer": "chassis_shells",
"material": "goose_white",
"link": "neck_pitch_link",
"density_g_cm3": 1.24,
"tooltip": "Goose S-Neck Lower Segment (PLA Matte White)\nDual internal cable channels for DXL & Head I2C",
}
# 16. neck_yaw_collar.stl:
# Links head_pitch horn (Z=222, Y=±13) to head_yaw bottom (Z=233.5) via rear/side collar at Y=±(14.0..17.2) -> wait:
# J5 wires pass at Y in [-18..-13], Z=226! So put collar ears on INSIDE/REAR at X in [6.0, 17.0], Y in [-12.5, +12.5], Z in [224.0, 232.6]
# (clears head_pitch X>=18.0 by 1.0 mm, clears head_yaw Z>=233.5 by 0.9 mm, clears head_roll X<=4.5 by 1.5 mm!)
collar = make_box_at(6.2, 17.0, -12.0, 12.0, 222.0, 232.6, fillet_r=2.5)
parts["neck_yaw_collar"] = {
"shape": collar.val(),
"plate": 2,
"layer": "actuators_legs",
"material": "goose_white",
"link": "head_pitch_link",
"density_g_cm3": 1.24,
"tooltip": "Upper Neck Pitch-to-Yaw Collar",
}
# 17. head_shell.stl:
# Sculpted expressive goose cranium reaching Z = 284.0 mm (right inside 280-290 mm standing height target!):
# - Crown dome Z in [271.2, 284.0], X in [-20.0, +45.0], Y in [-17.5, +17.5] (clears head_roll Z<=270.0 by 1.2 mm!)
# - Cheek walls Y in [14.0, 17.5] and [-17.5, -14.0], X in [-20.0, +44.5], Z in [242.0, 274.0]
# (Note: J5 wires pass at X=41.5, Y=-14..-10, Z=256 -> keep right cheek Y in [-19.5, -16.2] and left cheek Y in [16.2, 19.5]!)
# - Forehead sensor bezel at X in [45.0, 49.0], Y in [-12.0, +12.0], Z in [265.2, 280.0] with VL53L5CX 8x8 ToF window!
crown = make_box_at(-20.0, 45.0, -19.5, 19.5, 271.2, 284.0, fillet_r=6.0)
cheek_l = make_box_at(-20.0, 44.5, 16.4, 19.5, 244.0, 272.0, fillet_r=1.4)
cheek_r = make_box_at(-20.0, 44.5, -19.5, -16.4, 244.0, 272.0, fillet_r=1.4)
forehead = make_box_at(45.0, 49.2, -14.0, 14.0, 265.2, 280.0, fillet_r=2.0)
# VL53L5CX 8x8 ToF optical aperture at (X=47..50, Y=0, Z=271.5)
tof_win = make_box_at(44.0, 50.5, -4.2, 4.2, 268.0, 275.0)
# Expressive lateral eye sockets/bosses
eye_l = cq.Workplane("XZ").workplane(offset=19.5).center(26.0, 266.0).circle(4.2).extrude(1.8)
eye_r = cq.Workplane("XZ").workplane(offset=-21.3).center(26.0, 266.0).circle(4.2).extrude(1.8)
head_sh = crown.union(cheek_l).union(cheek_r).union(forehead).union(eye_l).union(eye_r).cut(tof_win).val()
parts["head_shell"] = {
"shape": head_sh,
"plate": 2,
"layer": "chassis_shells",
"material": "goose_white",
"link": "head_roll_link",
"density_g_cm3": 1.24,
"tooltip": "Goose Cranium Shell (Z_top = 284.0 mm)\nForward VL53L5CX 8x8 ToF window + Head BMI270 IMU pocket",
}
# ---------------- PLATE 3: GOOSE-BILL ORANGE WEBBED FEET, ARTICULATED BEAK & BAM RIG ----------------
# 18 & 19. left_foot_sole.stl & right_foot_sole.stl (+ TPU traction pad inserts 20 & 21 -> let's keep 20 clean parts!)
# Let's check exact Z=0.0 mm sole contact plane and >= 0.8 mm clearance to ankle XL330 (X:[-10,+24], Y:[yc-13,yc+13], Z:[4.0,24.0])
# and shank_frame (Y=yc±(13.8..16.8), Z>=11.0)!
# Foot clevis ears sit OUTSIDE shank_frame at Y=yc±(17.6..20.8), Z=[0.0, 18.0]!
# Underneath ankle servo (X:[-11,+25], Y:[yc-17.6, yc+17.6]), sole floor thickness is Z=[0.0, 3.1] mm (0.9 mm clear below Z=4.0)!
# Forward of X=+25.0 out to X=+62.0, webbed 3-toe fan spreads Y in [yc-26.0, yc+26.0], Z=[0.0, 5.5] mm!
for side, sgn in (("left", 1.0), ("right", -1.0)):
yc = 34.0 * sgn
y_shift = 3.0 * sgn
# 3-toed webbed goose foot polygon on Z=0.0 extruded 3.1 mm
sole_pts = [
(-22.0, yc - 16.0),
(-22.0, yc + 16.0),
(18.0, yc + 22.0 + y_shift),
(54.0, yc + 25.0 + y_shift),
(46.0, yc + 9.0 + y_shift),
(62.0, yc + y_shift),
(46.0, yc - 9.0 + y_shift),
(54.0, yc - 25.0 + y_shift),
(18.0, yc - 22.0 + y_shift),
]
sole_base = cq.Workplane("XY").workplane(offset=0.0).polyline(sole_pts).close().extrude(3.1)
# Raised dorsal ridges along the 3 toes forward of X=+25.2 (clear of ankle servo X<=24.0!)
toe_mid = make_box_at(25.2, 58.0, yc + y_shift - 4.0, yc + y_shift + 4.0, 3.1, 6.2, fillet_r=1.8)
toe_in = make_box_at(25.2, 50.0, yc + y_shift + 11.0, yc + y_shift + 19.0, 3.1, 5.6, fillet_r=1.8)
toe_out = make_box_at(25.2, 50.0, yc + y_shift - 19.0, yc + y_shift - 11.0, 3.1, 5.6, fillet_r=1.8)
# Ankle clevis ears at Y = yc ± (17.6..21.0), X in [-8.0, +8.0], Z in [3.1, 18.0] (0.8 mm outside shank_frame 16.8!)
ear_l = make_box_at(-8.0, 8.0, yc + 17.6, yc + 21.0, 0.0, 18.0, fillet_r=1.5)
ear_r = make_box_at(-8.0, 8.0, yc - 21.0, yc - 17.6, 0.0, 18.0, fillet_r=1.5)
# Ventral TPU traction tread grooves on Z=[0.0..0.8] (keeps Z_min strictly 0.00 mm!)
foot_wp = sole_base.union(toe_mid).union(toe_in).union(toe_out).union(ear_l).union(ear_r)
for gx in (-12.0, 4.0, 22.0, 38.0):
groove = make_box_at(gx - 1.2, gx + 1.2, yc - 14.0, yc + 14.0, 0.0, 0.7)
foot_wp = foot_wp.cut(groove)
parts[f"{side}_foot_sole"] = {
"shape": foot_wp.val(),
"plate": 3,
"layer": "actuators_legs",
"material": "goose_orange",
"link": f"{side}_foot_link",
"density_g_cm3": 1.24,
"tooltip": f"{side.capitalize()} Webbed Goose Foot (PLA Matte Orange + Traction Grooves)\nFlat Z=0.0 mm stance sole, 84 x 50 mm",
}
# 20. beak_upper.stl:
# Fixed upper orange goose bill + iconic basal knob enclosing above & forward of dxl_15_beak_pitch (X:[46..80], Y:[-13,+13], Z:[244..264])
# Upper bill canopy: Z in [264.9, 270.5] over X in [50.0, 84.0], Y in [-14.2, +14.2] (clears forehead X<=49.2 by 0.8 mm and dxl_15 Z<=264.0 by 0.9 mm!),
# plus curved bill tip X in [80.9, 90.0], Y in [-12.5, +12.5], Z in [253.5, 269.0] (clears dxl_15 X<=80.0 by 0.9 mm!),
# plus goose basal knob at X in [50.2, 58.0], Y in [-7.5, +7.5], Z in [270.5, 276.5]!
bill_top = make_box_at(50.2, 85.0, -14.2, 14.2, 264.9, 270.2, fillet_r=4.5)
bill_tip = make_box_at(80.9, 90.0, -12.0, 12.0, 254.0, 268.5, fillet_r=4.5)
bill_knob = (
cq.Workplane("XY")
.workplane(offset=270.2)
.center(54.0, 0.0)
.ellipse(4.2, 6.0)
.extrude(5.5)
)
parts["beak_upper"] = {
"shape": bill_top.union(bill_tip).union(bill_knob).val(),
"plate": 3,
"layer": "chassis_shells",
"material": "goose_orange",
"link": "head_roll_link",
"density_g_cm3": 1.24,
"tooltip": "Upper Goose Bill & Knob (PLA Matte Orange)\nHouses 15th-DoF XL330 Beak Actuator",
}
# 21. beak_lower.stl:
# 15th-DoF XL330-actuated hinged lower orange mandible (dxlId = 15, pivot at X=56.0, Y=±13, Z=254.0):
# Side hinge arms at Y in [13.9, 16.0] and [-16.0, -13.9], X in [52.0, 86.0], Z in [238.5, 257.0]
# (clears dxl_15 Y=±13.0 by 0.9 mm, clears cheek_l/r X<=44.5 by 7.5 mm!)
# and lower spatulate scoop floor at Z in [238.5, 242.8], X in [49.0, 88.0], Y in [-16.0, +16.0]
# (clears dxl_15 Z>=244.0 by 1.2 mm and bill_tip Z>=254.0 by 11.2 mm for expressive honking gape!)
jaw_floor = make_box_at(49.0, 88.0, -16.0, 16.0, 238.5, 242.8, fillet_r=5.0)
jaw_arm_l = make_box_at(52.0, 74.0, 13.9, 16.0, 242.8, 257.0, fillet_r=1.0)
jaw_arm_r = make_box_at(52.0, 74.0, -16.0, -13.9, 242.8, 257.0, fillet_r=1.0)
parts["beak_lower"] = {
"shape": jaw_floor.union(jaw_arm_l).union(jaw_arm_r).val(),
"plate": 3,
"layer": "actuators_legs",
"material": "goose_orange",
"link": "beak_link",
"density_g_cm3": 1.24,
"tooltip": "15th-DoF Articulated Lower Beak (dxlId=15, 0..38 deg Honk Hinge)",
}
return parts
def build_bam_pendulum_rig(base_servo: cq.Workplane) -> Dict[str, Any]:
"""Build standalone Rhoban/bam XL330 pendulum identification rig matching rl/bam/xl330_bam_params.json:
- Calibrated arm_length_m = 0.110 m (110.0 mm center-to-center from XL330 horn axis to M4 proof-mass bolt)
- Rigid bench A-frame stand holding XL330 shaft at Z = 145.0 mm (35 mm clear swing above Z=0 bench!)
"""
# Place rig in its own clean local coordinate system centered around (0, 0, 0) bench plane
# Base footprint: X in [-42.0, +35.0], Y in [-45.0, +45.0], Z in [0.0, 8.0] with 4x Ø5.5 mm bench clamp holes
base_plate = make_box_at(-42.0, 35.0, -45.0, 45.0, 0.0, 8.0, fillet_r=4.0)
for bx in (-32.0, 25.0):
for by in (-35.0, 35.0):
h = cq.Workplane("XY").workplane(offset=-0.5).center(bx, by).circle(2.75).extrude(10.0)
base_plate = base_plate.cut(h)
# Vertical A-frame tower at X in [-32.0, -4.0], Y in [-24.0, +24.0], Z in [8.0, 162.0]
tower = make_box_at(-32.0, -4.0, -22.0, 22.0, 8.0, 162.0, fillet_r=2.5)
gusset_l = (
cq.Workplane("XZ")
.workplane(offset=17.0)
.moveTo(-4.0, 8.0)
.lineTo(24.0, 8.0)
.lineTo(-4.0, 95.0)
.close()
.extrude(5.0)
)
gusset_r = (
cq.Workplane("XZ")
.workplane(offset=-22.0)
.moveTo(-4.0, 8.0)
.lineTo(24.0, 8.0)
.lineTo(-4.0, 95.0)
.close()
.extrude(5.0)
)
# Pocket for XL330-M288-T with shaft along +X at (X_center=10.0 -> X in [-3.0, +23.0]? Wait: keep servo forward of tower X=-4.0:
# Servo X in [-3.0, +23.0], Y in [-10.0, +10.0], Z in [121.0, 155.0], shaft at (X, Y=0, Z=145.0)!)
# Wait: make pocket in tower or mount servo inside cradle collar Y in [-15..-10.8] and [+10.8..+15], X in [-4..+20], Z in [120..158]
collar_l = make_box_at(-4.0, 20.0, 10.8, 16.0, 120.0, 158.0)
collar_r = make_box_at(-4.0, 20.0, -16.0, -10.8, 120.0, 158.0)
# Clear tower X<= -4.0 from servo X>=-3.0 by 1.0 mm!
bam_base = base_plate.union(tower).union(gusset_l).union(gusset_r).union(collar_l).union(collar_r).val()
bam_servo = place_xl330(base_servo, pivot_xyz=(10.0, 0.0, 145.0), shaft_dir="+X", tail_dir="-Z")
# Calibrated 110.0 mm pendulum arm: hub at X in [24.0, 30.0] (1.0 mm clear of servo X_max=23.0!),
# swinging in YZ plane from Z=145.0 down to Z=35.0 (exact 110.0 mm radius!)
arm_hub = cq.Workplane("YZ").workplane(offset=24.0).center(0.0, 145.0).circle(11.0).extrude(5.5)
arm_tip = cq.Workplane("YZ").workplane(offset=24.0).center(0.0, 35.0).circle(10.0).extrude(5.5)
arm_beam = make_box_at(24.0, 29.5, -5.5, 5.5, 35.0, 145.0)
mass_bolt_hole = cq.Workplane("YZ").workplane(offset=23.0).center(0.0, 35.0).circle(2.1).extrude(8.0)
# Lightening pockets along beam
pocket1 = make_box_at(23.5, 30.0, -2.5, 2.5, 55.0, 82.0)
pocket2 = make_box_at(23.5, 30.0, -2.5, 2.5, 92.0, 122.0)
bam_arm = arm_hub.union(arm_tip).union(arm_beam).cut(mass_bolt_hole).cut(pocket1).cut(pocket2).val()
# Calibrated 100g steel proof-mass cylinder mounted on +X side of arm tip at X in [30.4, 42.4], Z=35.0
proof_mass = cq.Workplane("YZ").workplane(offset=30.4).center(0.0, 35.0).circle(16.0).extrude(11.0).val()
rig_compound = make_compound([bam_base, bam_servo, bam_arm, proof_mass])
return {
"bam_pendulum_base": bam_base,
"bam_pendulum_arm": bam_arm,
"bam_servo": bam_servo,
"bam_proof_mass": proof_mass,
"compound": rig_compound,
}
def export_stl_binary(shape: cq.Shape, out_path: Path, tol: float = 0.08, ang_tol: float = 0.2) -> None:
out_path.parent.mkdir(parents=True, exist_ok=True)
cq.exporters.export(shape, str(out_path), exportType="STL", tolerance=tol, angularTolerance=ang_tol)
def export_step_clean(shape: cq.Shape, out_path: Path) -> None:
out_path.parent.mkdir(parents=True, exist_ok=True)
cq.exporters.export(shape, str(out_path), exportType="STEP")
def compute_kinematics_mass_props(
link_components: Dict[str, List[Tuple[cq.Shape, float]]],
mech_interface: Dict[str, Any],
) -> Dict[str, Any]:
"""Compute exact per-link volume, mass (kg), CoM in link local frame (m), and principal diagonal inertia (kg*m^2)
matching rl/build_mjcf.py's exact 16-body tree and link frames!"""
# Link frame origins in standing world coordinates (mm), matching rl/build_mjcf.py!
# Let's compute exact standing-pose link origins in mm:
# Torso: [0, 0, 135.0]
# Left leg: hip_yaw=[0, 34, 114], hip_roll=[0, 34, 94], thigh=[0, 34, 76] (rot -0.35),
# shank=[+11.315, 34, 44.999] (rot +0.35), foot=[0, 34, 14] (rot 0.0)
link_origins_mm: Dict[str, Tuple[float, float, float]] = {
"torso": (0.0, 0.0, 135.0),
"left_hip_yaw_link": (0.0, 34.0, 114.0),
"left_hip_roll_link": (0.0, 34.0, 94.0),
"left_thigh_link": (0.0, 34.0, 76.0),
"left_shank_link": (11.315, 34.0, 45.0),
"left_foot_link": (0.0, 34.0, 14.0),
"right_hip_yaw_link": (0.0, -34.0, 114.0),
"right_hip_roll_link": (0.0, -34.0, 94.0),
"right_thigh_link": (0.0, -34.0, 76.0),
"right_shank_link": (11.315, -34.0, 45.0),
"right_foot_link": (0.0, -34.0, 14.0),
"neck_pitch_link": (16.0, 0.0, 176.0),
"head_pitch_link": (28.0, 0.0, 222.0),
"head_yaw_link": (30.0, 0.0, 244.0),
"head_roll_link": (34.0, 0.0, 260.0),
"beak_link": (56.0, 0.0, 254.0),
}
links_out: Dict[str, Any] = {}
total_mass_kg = 0.0
total_vol_mm3 = 0.0
weighted_world_com = [0.0, 0.0, 0.0]
for link_name, items in link_components.items():
m_link = 0.0
v_link = 0.0
com_w = [0.0, 0.0, 0.0]
# Accumulate sub-items
sub_props = []
for shp, explicit_mass_or_density in items:
st = shape_volume_com_inertia(shp)
vol = st["volume_mm3"]
# Negative value means explicit mass in kg; positive value means density in g/cm^3 (= 1e-6 kg/mm^3)
if explicit_mass_or_density < 0.0:
mass_kg = -explicit_mass_or_density
eff_rho = mass_kg / max(vol, 1.0)
else:
eff_rho = explicit_mass_or_density * 1e-6
mass_kg = vol * eff_rho
sub_props.append((vol, mass_kg, eff_rho, st["com_mm"], st["inertia_mm5"]))
m_link += mass_kg
v_link += vol
for k in range(3):
com_w[k] += mass_kg * st["com_mm"][k]
if m_link > 0:
com_w = [c / m_link for c in com_w]
# Parallel axis theorem about link CoM (in kg * m^2; 1 mm = 1e-3 m, inertia_mm5 * eff_rho * 1e-6)
ixx_kgm2 = 0.0
iyy_kgm2 = 0.0
izz_kgm2 = 0.0
for vol, mass_kg, eff_rho, c_sub, imat in sub_props:
dx = (c_sub[0] - com_w[0]) * 1e-3
dy = (c_sub[1] - com_w[1]) * 1e-3
dz = (c_sub[2] - com_w[2]) * 1e-3
ixx_kgm2 += imat[0][0] * eff_rho * 1e-6 + mass_kg * (dy * dy + dz * dz)
iyy_kgm2 += imat[1][1] * eff_rho * 1e-6 + mass_kg * (dx * dx + dz * dz)
izz_kgm2 += imat[2][2] * eff_rho * 1e-6 + mass_kg * (dx * dx + dy * dy)
orig = link_origins_mm[link_name]
com_local_m = [(com_w[k] - orig[k]) * 1e-3 for k in range(3)]
links_out[link_name] = {
"volumeMm3": round(v_link, 2),
"massKg": round(m_link, 5),
"worldComMm": [round(v, 3) for v in com_w],
"comM": [round(v, 5) for v in com_local_m],
"diagInertiaKgM2": [
round(max(ixx_kgm2, 1e-6), 7),
round(max(iyy_kgm2, 1e-6), 7),
round(max(izz_kgm2, 1e-6), 7),
],
}
total_mass_kg += m_link
total_vol_mm3 += v_link
for k in range(3):
weighted_world_com[k] += m_link * com_w[k]
overall_com_mm = [weighted_world_com[k] / max(total_mass_kg, 1e-6) for k in range(3)]
return {
"schema": "microgoose-kinematics-mass-props/v1",
"units": {"mass": "kg", "comM": "m_in_link_frame", "diagInertiaKgM2": "kg_m2", "volumeMm3": "mm3"},
"totalMassKg": round(total_mass_kg, 4),
"totalVolumeMm3": round(total_vol_mm3, 1),
"standingWorldComMm": [round(v, 2) for v in overall_com_mm],
"standingHeightMm": 284.0,
"links": links_out,
}
def main() -> None:
t_start = time.time()
parser = argparse.ArgumentParser(description="Build Microgoose 15-DoF parametric CAD, STL/STEP, and OCCT checks")
parser.add_argument("--board-step", type=str, default=None, help="Optional path to kicad/microgoose-spine.step")
args = parser.parse_args()
STL_DIR.mkdir(parents=True, exist_ok=True)
STEP_DIR.mkdir(parents=True, exist_ok=True)
HERO_MESH_DIR.mkdir(parents=True, exist_ok=True)
mech_interface = json.loads((DESIGN_DIR / "mechanical-interface.json").read_text())
print("[1/6] Building Spine PCB assembly & importing real 3D component STEP models...")
board_shape, board_cats, board_review = import_or_synthesize_spine_board(args.board_step)
(MECH_DIR / "board-source-review.json").write_text(json.dumps(board_review, indent=2) + "\n")
print("[2/6] Building 15x Dynamixel XL330-M288-T servos, Radxa Zero 3W mezzanine, and NP-F550 battery...")
base_servo = build_xl330_servo_local()
servo_specs = [
("dxl_01_left_hip_yaw", (0.0, 34.0, 128.5), "-Z", "-X", 0.0, "left_hip_yaw_link"),
("dxl_02_left_hip_roll", (27.0, 34.0, 94.0), "-X", "-Y", 0.0, "left_hip_roll_link"),
("dxl_03_left_hip_pitch", (0.0, 34.0, 76.0), "+Y", "-X", -0.35, "left_thigh_link"),
("dxl_04_left_knee_pitch", (11.315, 34.0, 45.0), "+Y", "-X", 0.35, "left_shank_link"),
("dxl_05_left_ankle_pitch", (0.0, 34.0, 14.0), "+Y", "+X", 0.0, "left_foot_link"),
("dxl_06_right_hip_yaw", (0.0, -34.0, 128.5), "-Z", "-X", 0.0, "right_hip_yaw_link"),
("dxl_07_right_hip_roll", (27.0, -34.0, 94.0), "-X", "+Y", 0.0, "right_hip_roll_link"),
("dxl_08_right_hip_pitch", (0.0, -34.0, 76.0), "-Y", "-X", -0.35, "right_thigh_link"),
("dxl_09_right_knee_pitch", (11.315, -34.0, 45.0), "-Y", "-X", 0.35, "right_shank_link"),
("dxl_10_right_ankle_pitch", (0.0, -34.0, 14.0), "-Y", "+X", 0.0, "right_foot_link"),
("dxl_11_neck_pitch", (16.0, 0.0, 176.0), "+Y", "-X", 0.0, "torso"),
("dxl_12_head_pitch", (28.0, 0.0, 222.0), "+Y", "-Z", 0.0, "neck_pitch_link"),
("dxl_13_head_yaw", (30.0, 0.0, 246.5), "+Z", "-X", 0.0, "head_yaw_link"),
("dxl_14_head_roll", (-8.5, 0.0, 260.0), "+X", "-Z", 0.0, "head_roll_link"),
("dxl_15_beak_pitch", (56.0, 0.0, 254.0), "+Y", "+X", 0.0, "head_roll_link"),
]
servos: Dict[str, cq.Shape] = {}
servo_links: Dict[str, str] = {}
for s_name, piv, s_dir, t_dir, p_rad, lk in servo_specs:
servos[s_name] = place_xl330(base_servo, piv, s_dir, t_dir, p_rad)
servo_links[s_name] = lk
radxa_shape, batt_shape, screws = build_radxa_and_battery()
# Forehead VL53L5CX ToF + Head BMI270 IMU carrier PCB at X:[41.2, 43.4], Y:[-6.5, +6.5], Z:[265.2, 270.3]
# Clears J5 wire ends Z<=264.2 by 1.0 mm and clears head_shell crown Z>=271.2 by 0.9 mm!
head_sensor_pcb = make_box_at(41.2, 43.4, -6.5, 6.5, 265.2, 270.3).val()
print("[3/6] Sweeping all 22 physical 3D wire conductors across 6 cable bundles...")
wires_spec, wires_compound = build_all_22_wires()
print("[4/6] Generating 19 robot printable chassis/shell/foot/beak parts + BAM pendulum rig...")
printed_parts = build_chassis_and_shells(
servos=servos,
board_shape=board_shape,
radxa_shape=radxa_shape,
batt_shape=batt_shape,
screws=screws,
wires_compound=wires_compound,
)
bam_rig = build_bam_pendulum_rig(base_servo)
# ---------------- PAIRWISE OCCT INTERFERENCE CHECK ----------------
print("[5/6] Running pairwise AABB + exact OCCT BRepAlgoAPI_Common solid interference check...")
assembly_items: List[Tuple[str, cq.Shape]] = []
assembly_items.append(("spine_pcb_assembly", board_shape))
assembly_items.append(("radxa_zero_3w", radxa_shape))
assembly_items.append(("np_f550_battery", batt_shape))
assembly_items.append(("head_tof_imu_carrier", head_sensor_pcb))
for i, sc in enumerate(screws, start=1):
assembly_items.append((f"m25_radxa_screw_{i}", sc))
for s_name, s_shp in servos.items():
assembly_items.append((s_name, s_shp))
for p_name, p_meta in printed_parts.items():
assembly_items.append((p_name, p_meta["shape"]))
for w in wires_spec:
assembly_items.append((f"wire_{w['physicalId']}", w["shape"]))
aabbs = {name: shape_aabb(shp) for name, shp in assembly_items}
# Pre-index sub-solids of spine_pcb_assembly so exact BRepAlgoAPI_Common against 800+ real KiCad solids
# tests every sub-solid whose individual AABB overlaps the partner AABB (100% exact, 50x faster).
from OCP.TopAbs import TopAbs_SOLID
from OCP.TopExp import TopExp_Explorer
board_subsolids: List[Tuple[cq.Shape, Tuple[float, float, float, float, float, float]]] = []
exp_b = TopExp_Explorer(board_shape.wrapped, TopAbs_SOLID)
while exp_b.More():
sub_s = cq.Shape(exp_b.Current())
board_subsolids.append((sub_s, shape_aabb(sub_s)))
exp_b.Next()
n_items = len(assembly_items)
total_pairs = n_items * (n_items - 1) // 2
aabb_overlap_pairs = 0
boolean_checked_pairs = 0
board_subsolid_booleans = 0
collisions: List[Dict[str, Any]] = []
near_clearances: List[Dict[str, Any]] = []
for i in range(n_items):
n1, s1 = assembly_items[i]
b1 = aabbs[n1]
for j in range(i + 1, n_items):
n2, s2 = assembly_items[j]
b2 = aabbs[n2]
gap = aabb_gap(b1, b2)
if gap <= 0.5:
boolean_checked_pairs += 1
if gap == 0.0:
aabb_overlap_pairs += 1
if n1 == "spine_pcb_assembly" and board_subsolids:
vol = 0.0
for sub_s, sub_b in board_subsolids:
if aabb_gap(sub_b, b2) == 0.0:
board_subsolid_booleans += 1
vol += boolean_common_volume_mm3(sub_s, s2)
else:
vol = boolean_common_volume_mm3(s1, s2)
if vol >= 0.01:
collisions.append({
"partA": n1,
"partB": n2,
"overlapMm3": round(vol, 5),
})
else:
near_clearances.append({
"partA": n1,
"partB": n2,
"aabbGapMm": round(gap, 3),
"exactOverlapMm3": round(vol, 6),
})
# Overall robot bounding box (verify Z_min == 0.0 and standing height ~284.0 mm)
robot_shapes = [shp for _, shp in assembly_items]
full_robot_compound = make_compound(robot_shapes)
r_xmin, r_ymin, r_zmin, r_xmax, r_ymax, r_zmax = shape_aabb(full_robot_compound)
interference_report = {
"schema": "microgoose-interference-report/v1",
"passed": len(collisions) == 0,
"boardMode": board_review["mode"],
"boardStepSha256": board_review.get("boardStepSha256"),
"boardSubsolidsEvaluated": len(board_subsolids),
"boardSubsolidBooleanPairsChecked": board_subsolid_booleans,
"componentCount": n_items,
"totalPairsEvaluated": total_pairs,
"aabbOverlapPairs": aabb_overlap_pairs,
"exactOcctBooleanPairsChecked": boolean_checked_pairs,
"unexpectedCollisionCount": len(collisions),
"maxOverlapThresholdMm3": 0.01,
"collisions": collisions,
"robotEnvelopeMm": {
"xRange": [round(r_xmin, 2), round(r_xmax, 2)],
"yRange": [round(r_ymin, 2), round(r_ymax, 2)],
"zRange": [round(r_zmin, 2), round(r_zmax, 2)],
"standingHeightMm": round(r_zmax - r_zmin, 2),
},
"verifiedZeroOverlapProximitySample": near_clearances[:25],
}
(MECH_DIR / "interference-report.json").write_text(json.dumps(interference_report, indent=2) + "\n")
if collisions:
print("COLLISIONS DETECTED:", json.dumps(collisions, indent=2))
raise RuntimeError(f"Detected {len(collisions)} solid collisions!")
# ---------------- COMPUTE EXACT KINEMATICS MASS & INERTIA ----------------
link_map: Dict[str, List[Tuple[cq.Shape, float]]] = {
"torso": [
(board_shape, -0.022), # Assembled 70x70mm 2L Spine PCB + components = 22.0 g
(radxa_shape, -0.019), # Radxa Zero 3W + heatsink = 19.0 g
(batt_shape, -0.104), # NP-F550 2S 2600mAh Li-ion pack = 104.0 g
(wires_compound, -0.014), # 6 cable bundles = 14.0 g
],
"left_hip_yaw_link": [],
"left_hip_roll_link": [],
"left_thigh_link": [],
"left_shank_link": [],
"left_foot_link": [],
"right_hip_yaw_link": [],
"right_hip_roll_link": [],
"right_thigh_link": [],
"right_shank_link": [],
"right_foot_link": [],
"neck_pitch_link": [],
"head_pitch_link": [],
"head_yaw_link": [],
"head_roll_link": [(head_sensor_pcb, -0.0025)],
"beak_link": [],
}
for sc in screws:
link_map["torso"].append((sc, -0.0005))
for s_name, s_shp in servos.items():
link_map[servo_links[s_name]].append((s_shp, -0.018)) # Exact 18.0 g per XL330-M288-T datasheet
for p_name, p_meta in printed_parts.items():
# Effective 35% infill + 3-wall FDM printed part density (~0.52 g/cm^3 effective bulk density)
eff_print_rho = 0.52 if p_meta["plate"] == 1 else 0.44
link_map[p_meta["link"]].append((p_meta["shape"], eff_print_rho))
mass_props = compute_kinematics_mass_props(link_map, mech_interface)
(MECH_DIR / "kinematics_mass_props.json").write_text(json.dumps(mass_props, indent=2) + "\n")
# ---------------- EXPORT ALL STL, STEP & HERO MESHES ----------------
print("[6/6] Exporting printable STLs, STEP assemblies, and hero GLB mesh manifest...")
stl_inventory = []
hero_manifest_items = []
# Export printable robot parts (enforce single-solid topology + strict left/right hemisphere invariants)
for p_name, p_meta in printed_parts.items():
n_solids = len(p_meta["shape"].Solids())
assert n_solids == 1, f"Printable part {p_name} must be 1 connected solid, got {n_solids} solids"
bb = shape_aabb(p_meta["shape"])
if p_name.startswith("left_") or p_name.endswith("_left"):
assert bb[1] > 0.0, f"Left-side part {p_name} crossed into Y <= 0: Y=[{bb[1]:.3f}, {bb[4]:.3f}]"
if p_name.startswith("right_") or p_name.endswith("_right"):
assert bb[4] < 0.0, f"Right-side part {p_name} crossed into Y >= 0: Y=[{bb[1]:.3f}, {bb[4]:.3f}]"
stl_path = STL_DIR / f"{p_name}.stl"
step_path = STEP_DIR / f"{p_name}.step"
export_stl_binary(p_meta["shape"], stl_path, tol=0.06)
export_step_clean(p_meta["shape"], step_path)
stl_inventory.append({
"name": p_name,
"stlPath": rel_repo_path(stl_path),
"stepPath": rel_repo_path(step_path),
"plate": p_meta["plate"],
"sizeMm": [round(bb[3] - bb[0], 2), round(bb[4] - bb[1], 2), round(bb[5] - bb[2], 2)],
})
hero_manifest_items.append({
"nodeName": p_name,
"stlPath": rel_repo_path(stl_path),
"layer": p_meta["layer"],
"material": p_meta["material"],
"tooltip": p_meta["tooltip"],
})
# Export BAM pendulum rig printable STLs + assembly STEP
for b_name, b_mat in (("bam_pendulum_base", "goose_orange"), ("bam_pendulum_arm", "goose_orange")):
n_solids = len(bam_rig[b_name].Solids())
assert n_solids == 1, f"BAM printable part {b_name} must be 1 connected solid, got {n_solids} solids"
stl_path = STL_DIR / f"{b_name}.stl"
step_path = STEP_DIR / f"{b_name}.step"
export_stl_binary(bam_rig[b_name], stl_path, tol=0.06)
export_step_clean(bam_rig[b_name], step_path)
bb = shape_aabb(bam_rig[b_name])
stl_inventory.append({
"name": b_name,
"stlPath": rel_repo_path(stl_path),
"stepPath": rel_repo_path(step_path),
"plate": 3,
"sizeMm": [round(bb[3] - bb[0], 2), round(bb[4] - bb[1], 2), round(bb[5] - bb[2], 2)],
})
export_stl_binary(bam_rig["bam_servo"], HERO_MESH_DIR / "bam_servo.stl", tol=0.08)
export_stl_binary(bam_rig["bam_proof_mass"], HERO_MESH_DIR / "bam_proof_mass.stl", tol=0.08)
export_step_clean(bam_rig["compound"], STEP_DIR / "bam_pendulum_rig.step")
# Export subassemblies & full robot assembly STEP
export_step_clean(board_shape, STEP_DIR / "spine_pcb_subassembly.step")
export_step_clean(make_compound(list(servos.values())), STEP_DIR / "xl330_actuators_subassembly.step")
export_step_clean(wires_compound, STEP_DIR / "wiring_bundles_subassembly.step")
export_step_clean(full_robot_compound, STEP_DIR / "microgoose_full_assembly.step")
# Export Hero GLB non-printed component meshes (Spine categories, Radxa, Battery, Screws, Servos, 22 individual Wires)
for cat_name, cat_shape in board_cats.items():
p = HERO_MESH_DIR / f"board_{cat_name}.stl"
export_stl_binary(cat_shape, p, tol=0.06)
hero_manifest_items.append({
"nodeName": f"spine_{cat_name}",
"stlPath": rel_repo_path(p),
"layer": "electronics_battery",
"material": cat_name,
"tooltip": "Microgoose Spine Molecule PCB (70x70x1.6 mm, 2L)\nSTM32G431 + LMR33640 5V/4A Buck + INA226 + BMI270",
})
p_radxa = HERO_MESH_DIR / "radxa_zero_3w.stl"
export_stl_binary(radxa_shape, p_radxa, tol=0.08)
hero_manifest_items.append({
"nodeName": "radxa_zero_3w",
"stlPath": rel_repo_path(p_radxa),
"layer": "electronics_battery",
"material": "radxa_blue",
"tooltip": "Radxa Zero 3W Mezzanine (RK3566)\nRuns 50 Hz goosectl ONNX Policy & Telemetry",
})
p_batt = HERO_MESH_DIR / "np_f550_battery.stl"
export_stl_binary(batt_shape, p_batt, tol=0.08)
hero_manifest_items.append({
"nodeName": "np_f550_battery",
"stlPath": rel_repo_path(p_batt),
"layer": "electronics_battery",
"material": "battery_pack",
"tooltip": "NP-F550 2S Li-ion Pack (7.4 V, 2600 mAh, 104 g)\nUnderslung quick-swap sled for low CoM",
})
p_hsens = HERO_MESH_DIR / "head_tof_imu_carrier.stl"
export_stl_binary(head_sensor_pcb, p_hsens, tol=0.06)
hero_manifest_items.append({
"nodeName": "head_tof_imu_carrier",
"stlPath": rel_repo_path(p_hsens),
"layer": "electronics_battery",
"material": "spine_pcb_emerald",
"tooltip": "Head Sensor Carrier\nVL53L5CX 8x8 ToF Rangefinder + Head BMI270 IMU",
})
screws_comp = make_compound(screws)
p_scr = HERO_MESH_DIR / "m25_radxa_screws.stl"
export_stl_binary(screws_comp, p_scr, tol=0.05)
hero_manifest_items.append({
"nodeName": "m25_radxa_screws",
"stlPath": rel_repo_path(p_scr),
"layer": "electronics_battery",
"material": "steel_silver",
"tooltip": "4x M2.5x6 Button-Head Hex Screws (ISO 7380)",
})
for s_name, s_shp in servos.items():
p_s = HERO_MESH_DIR / f"{s_name}.stl"
export_stl_binary(s_shp, p_s, tol=0.08)
hero_manifest_items.append({
"nodeName": s_name,
"stlPath": rel_repo_path(p_s),
"layer": "actuators_legs",
"material": "xl330_charcoal",
"tooltip": f"Dynamixel XL330-M288-T ({s_name})\n0.42 Nm @ 5.0 V, 288.4:1, 18 g",
})
wire_metadata_out = []
for w in wires_spec:
pid = w["physicalId"]
p_w = HERO_MESH_DIR / f"wire_{pid}.stl"
export_stl_binary(w["shape"], p_w, tol=0.05)
hero_manifest_items.append({
"nodeName": f"wire_{pid}",
"stlPath": rel_repo_path(p_w),
"layer": "wiring_loom",
"material": f"wire_{w['color']}",
"colorHex": w["colorHex"],
"physicalConductorId": pid,
"tooltip": f"Conductor {pid} ({w['net']})\n{w['sourcePin']} -> {w['destinationPin']} ({w['arcLengthMm']} mm)",
})
wire_metadata_out.append({
k: v for k, v in w.items() if k != "shape"
})
manifest = {
"robotEnvelopeMm": interference_report["robotEnvelopeMm"],
"totalMassKg": mass_props["totalMassKg"],
"stlInventory": stl_inventory,
"heroItems": hero_manifest_items,
"wires": wire_metadata_out,
"fullAssemblyStepSha256": sha256_file(STEP_DIR / "microgoose_full_assembly.step"),
}
(HERO_MESH_DIR / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
dt = time.time() - t_start
print(
f"DONE in {dt:.1f}s! Collisions: {len(collisions)} (checked {total_pairs} pairs, {boolean_checked_pairs} exact OCCT booleans). "
f"Standing height: {r_zmax - r_zmin:.2f} mm (Z=[{r_zmin:.2f}, {r_zmax:.2f}]). "
f"Total robot mass: {mass_props['totalMassKg']*1000:.1f} g."
)
if __name__ == "__main__":
main()