Pluggable parametric CAD and URDF robotics component library in MoonBit

./test-all.sh
./build-part.sh 02
./run-example.sh 02 --view///|
test {
let layer = @cad.ExplodeLayer::new(label="bearing", patterns=["bearing"]).exact()
let stack = @cad.ExplodeStack::z_axis(anchor="base", gap_mm=10.0).group(layer)
let design = @step_cad.Design::new(name="es")
.add(@step_cad.Cylinder::new(10.0, 5.0).with_name("base").translate(z=0.0))
.add(
@step_cad.Cylinder::new(8.0, 4.0).with_name("bearing").translate(z=7.0),
)
inspect(stack.diagnostics(design).is_ok(), content="true")
}| Command | Purpose |
|---|---|
| ./build-part.sh <n> | Complete build package under build/<n>/. |
| ./run-example.sh <n> --view | Open one example in SolidCraft. |
| ./run-example.sh <n> -o model.step | Write a STEP assembly for one example. |
| ./run-example.sh <n> --package <dir> | Write the full build package to a directory of your choice. |
| ./test-all.sh | moon fmt, moon info, and the full unit suite. |
| ./customize.sh <n> | Local parameter editor for one example. |
| ./train-rl.sh <n> | Train a policy for examples with an RlTaskSpec. |
| scripts/new-example.sh <name> | Scaffold a new example. |
| scripts/validate_step.py --no-mesh <file.step> | STEP topology and OCCT checkshape checks. |
| scripts/validate_urdf.py --check-meshes <file.urdf> | URDF structural and mesh checks. |
| scripts/check_interferences.py --parts-dir <dir> | OCCT solid-solid interference. |
| scripts/make_drawings.py build/<n> | A3 drawing sheets. |
| scripts/fea_check.py build/<n> | Optional gmsh/CalculiX structural check. |
| ./view-md.sh <file.md> | Render Markdown to a self-contained HTML page. |
moon doc # static site into _build/doc/
moon doc --serve # ... served locally
moon ide doc 'Component::add_body' # signature + doc for one symbol
moon ide doc 'Component' # a type and its methods
moon ide doc '' # every symbol in the package$ moon version --all
moon 0.1.20261126 (ccd306a 2026-11-26) ~/.moon/bin/moon
moonc v1.0.0-rc1+3c0520448 (2026-11-26) ~/.moon/bin/moonc
moonrun 0.1.20261126 (ccd306a 2026-11-26) ~/.moon/bin/moonrun
pub suberror ExplodeError {
ExplodeError(String)
}impl Show for ExplodeErrorpub(all) enum ActuatorKind {
Stepper
Bldc
Servo
Hub
}pub(all) struct ActuatorSpec {
kind : ActuatorKind
model : String
voltage_v : Double
current_rated_a : Double
current_stall_a : Double
torque_rated_nm : Double
driver : String
interface : String
encoder : String
}fn ActuatorSpec::new(kind : ActuatorKind, model? : String, voltage_v? : Double, current_rated_a? : Double, current_stall_a? : Double, torque_rated_nm? : Double, driver? : String, interface? : String, encoder? : String) -> ActuatorSpecfn AssemblyStep::new(sequence : Int, title : String, component~ : String, joint? : String?, fasteners? : Array[String], tools? : Array[String], notes? : String) -> AssemblySteppub(all) struct Attachment {
joint_name : String
child : Component
spec : JointSpec
bom_external : Bool
explode : ExplodeSpec?
}pub(all) struct BomLine {
part_number : String
description : String
quantity : Int
supplier : String
supplier_url : String
material : String
process : String
finish : String
unit_cost_usd : Double
total_cost_usd : Double
notes : String
}pub(all) enum BoundaryRegion {
CylinderBore(center_mm~ : (Double, Double, Double), axis~ : (Double, Double, Double), radius_mm~ : Double, z_min_mm~ : Double, z_max_mm~ : Double, tol_mm~ : Double)
PlaneFace(axis~ : (Double, Double, Double), offset_mm~ : Double, tol_mm~ : Double)
BoxRegion(min_mm~ : (Double, Double, Double), max_mm~ : (Double, Double, Double))
BoltCircle(center_mm~ : (Double, Double, Double), bcd_mm~ : Double, hole_diam_mm~ : Double, count~ : Int, start_angle_deg~ : Double, z_min_mm~ : Double, z_max_mm~ : Double, tol_mm~ : Double)
}pub(all) struct BuildFile {
path : String
content : String
}fn CableRoute::new(name : String, points? : Array[(Double, Double, Double)], jacket_diameter_mm? : Double, wire_names? : Array[String], material? : String, from_component? : String, from_port? : String, to_component? : String, to_port? : String) -> CableRoutepub(all) struct Component {
name : String
description : String
parameters : Map[String, String]
bodies : Array[BodyPart]
mates : Map[String, MateConnector]
attachments : Array[Attachment]
robot_name : String?
part : PartMeta?
ports : Array[Port]
fasteners : Array[Fastener]
fits : Array[Fit]
actuator : ActuatorSpec?
sensor : SensorSpec?
pcb : PcbSpec?
wiring : Array[WireRun]
control : Array[ControlBinding]
cables : Array[CableRoute]
loops : Array[LoopConstraint]
rl_task : RlTaskSpec?
fea_load_cases : Array[FeaLoadCase]
analysis_poses : Array[(String, Map[String, Double])]
}fn Component::attach_rect(self : Component, prefix : String, width_mm~ : Double, height_mm~ : Double, make_child : (Int) -> Component, center_x? : Double, center_y? : Double, z_mm? : Double, axis? : (Double, Double, Double), child_mate? : String, spec? : JointSpec, bom_external? : Bool, explode? : ExplodeSpec) -> Componentfn Component::attach_ring(self : Component, prefix : String, count~ : Int, diam_mm~ : Double, make_child : (Int) -> Component, phase_deg? : Double, center_x? : Double, center_y? : Double, z_mm? : Double, axis? : (Double, Double, Double), child_mate? : String, spec? : JointSpec, bom_external? : Bool, explode? : ExplodeSpec) -> Componentfn Component::collision_checks(self : Component, joint_positions? : Map[String, Double], tol? : TolerancePolicy, policy? : ContactPolicy) -> Array[String]fn Component::collision_report_text(self : Component, joint_positions? : Map[String, Double], tol? : TolerancePolicy, policy? : ContactPolicy) -> Stringfn Component::collision_reports(self : Component, joint_positions? : Map[String, Double], tol? : TolerancePolicy, policy? : ContactPolicy) -> Array[CollisionReport]fn Component::compile_links(self : Component, package_name? : String?) -> (Array[CompiledLink], Array[Joint], Array[Transmission])fn Component::control_constants(self : Component, joint_positions? : Map[String, Double]) -> ControlConstantsfn Component::explode_diagnostics(self : Component, joint_positions? : Map[String, Double], scale? : Double) -> ExplodeTreeDiagnosticsfn Component::from_step_layer(name : String, step_comp : Component, layer_name : String, density? : Density, part? : PartMeta?, connector_prefix? : String, include_connectors? : Bool, apply_placement? : Bool, x_mm? : Double, y_mm? : Double, z_mm? : Double, rx_deg? : Double, ry_deg? : Double, rz_deg? : Double) -> Componentfn Component::from_step_layers(name : String, step_comp : Component, layer_names : Array[String], label? : String, density? : Density, part? : PartMeta?, connector_prefix? : String, include_connectors? : Bool, apply_placement? : Bool, x_mm? : Double, y_mm? : Double, z_mm? : Double, rx_deg? : Double, ry_deg? : Double, rz_deg? : Double) -> Componentfn Component::inspect_json(self : Component, bed? : PrintBedSpec, joint_positions? : Map[String, Double]) -> Stringfn Component::placed_shapes(self : Component, joint_positions? : Map[String, Double]) -> Array[PlacedShape]fn Component::to_assembly_step(self : Component, joint_positions? : Map[String, Double], cap? : DetailLevel?) -> Stringfn Component::to_blender_python(self : Component, joint_positions? : Map[String, Double], segments? : Int, cap? : DetailLevel?) -> Stringfn Component::to_design(self : Component, joint_positions? : Map[String, Double], cap? : DetailLevel?) -> Designfn Component::to_exploded_design(self : Component, joint_positions? : Map[String, Double], scale? : Double, trace_lines? : Bool, cap? : DetailLevel?) -> Designfn Component::to_gltf(self : Component, joint_positions? : Map[String, Double], cap? : DetailLevel?) -> Stringfn Component::to_step_file(self : Component, joint_positions? : Map[String, Double], cap? : DetailLevel?) -> Stringfn Component::to_urdf_bundle(self : Component, package_name? : String, include_step_parts? : Bool, joint_positions? : Map[String, Double]) -> UrdfBundlepub(all) enum ConnectionKind {
MergeRigid
Fixed
Revolute(JointLimit)
Continuous(JointLimit?)
Prismatic(JointLimit)
} derive(Debug)pub(all) struct ControlBinding {
joint : String
actuator : String
channel : String
mcu_pins : String
direction : String
gear_ratio : Double
soft_lower : Double?
soft_upper : Double?
homing_input : String?
limit_input : String?
}fn ControlBinding::new(joint : String, actuator? : String, channel? : String, mcu_pins? : String, direction? : String, gear_ratio? : Double, soft_lower? : Double?, soft_upper? : Double?, homing_input? : String?, limit_input? : String?) -> ControlBindingpub(all) struct ControlConstants {
robot_name : String
total_mass_kg : Double
com_x_m : Double
com_y_m : Double
com_z_m : Double
ixx_kgm2 : Double
iyy_kgm2 : Double
izz_kgm2 : Double
ground_z_m : Double
joints : Array[ControlJointConstants]
} derive(Eq, Debug)fn DomainRandSpec::new(mass_scale_range? : (Double, Double), friction_range? : (Double, Double), kp_scale_range? : (Double, Double), push_impulse_ns? : Double, obs_noise_std? : Double) -> DomainRandSpecpub struct ExplodeLayer {
patterns : Array[String]
gap_override_mm : Double?
predicate : (SceneNode) -> Bool?
match_mode : MatchMode
label : String
reason : String
slide_mm : (Double, Double, Double)
color : Rgb?
host : String?
side : ExplodeSide
}test {
let l = @cad.ExplodeLayer::new(label="fan", patterns=["krc_cover_fan"])
inspect(l.label, content="fan")
}fn ExplodeLayer::with_predicate(self : ExplodeLayer, predicate : (SceneNode) -> Bool) -> ExplodeLayerfn ExplodeLayer::with_slide(self : ExplodeLayer, slide_mm : (Double, Double, Double)) -> ExplodeLayerpub struct ExplodeOffsetNode {
name : String
offset_mm : (Double, Double, Double)
assembled_center_mm : (Double, Double, Double)?
color : Rgb?
}fn ExplodeOffsetNode::new(name~ : String, offset_mm~ : (Double, Double, Double), assembled_center_mm? : (Double, Double, Double), color? : Rgb) -> ExplodeOffsetNodepub struct ExplodeOffsets {
layout : String
source : String
nodes : Array[ExplodeOffsetNode]
layers : Array[LayerPlacement]
}fn ExplodeOffsets::coaxial(nodes : Array[ExplodeOffsetNode], layers? : Array[LayerPlacement]) -> ExplodeOffsetstest {
let o = @cad.ExplodeOffsets::coaxial([
@cad.ExplodeOffsetNode::new(name="a", offset_mm=(0.0, 0.0, 10.0)),
])
inspect(o.layout, content="coaxial")
inspect(o.source, content="declared")
inspect(o.nodes.length(), content="1")
}fn ExplodeOffsets::freeform(nodes : Array[ExplodeOffsetNode], layers? : Array[LayerPlacement]) -> ExplodeOffsetstest {
let o = @cad.ExplodeOffsets::freeform([
@cad.ExplodeOffsetNode::new(name="screw", offset_mm=(24.0, 0.0, 475.0)),
])
inspect(o.layout, content="freeform")
inspect(o.to_json().contains("explode-offsets@1"), content="true")
}pub(all) enum ExplodeSide {
Above
Below
}pub struct ExplodeStack {
anchor_patterns : Array[String]
above_layers : Array[ExplodeLayer]
below_layers : Array[ExplodeLayer]
default_gap_mm : Double
allowed_unmatched : Array[String]
}test {
let d = @step_cad.Design::new(name="es")
.add(@step_cad.Cylinder::new(10.0, 5.0).with_name("base").translate(z=0.0))
.add(
@step_cad.Cylinder::new(8.0, 4.0).with_name("bearing").translate(z=7.0),
)
let s = @cad.ExplodeStack::z_axis(anchor="base", gap_mm=10.0).group(
@cad.ExplodeLayer::new(label="bearing", patterns=["bearing"]),
)
inspect(s.diagnostics(d).is_ok(), content="true")
}fn ExplodeStack::offsets(self : ExplodeStack, design : Design) -> Array[(String, (Double, Double, Double))] raise ExplodeErrorfn ExplodeStack::to_offsets(self : ExplodeStack, design : Design) -> ExplodeOffsets raise ExplodeErrorpub(all) struct Fastener {
name : String
kind : FastenerKind
thread : String
length_mm : Double
engagement_mm : Double
quantity : Int
torque_nm : Double
references : Array[String]
part : PartMeta?
host : String
}fn Fastener::new(name : String, kind : FastenerKind, thread? : String, length_mm? : Double, engagement_mm? : Double, quantity? : Int, torque_nm? : Double, references? : Array[String], part? : PartMeta?, host? : String) -> Fastenerpub(all) enum FastenerKind {
Bolt
Screw
Nut
Washer
Insert
}pub(all) enum FeaLoad {
Force(region~ : BoundaryRegion, force_n~ : (Double, Double, Double))
Torque(region~ : BoundaryRegion, origin_mm~ : (Double, Double, Double), axis~ : (Double, Double, Double), torque_nm~ : Double)
Pressure(region~ : BoundaryRegion, pressure_mpa~ : Double)
}pub(all) struct FeaLoadCase {
name : String
part_number : String
material : MaterialProperties
constraints : Array[BoundaryRegion]
loads : Array[FeaLoad]
mesh_size_mm : Double
print_z_axis : (Double, Double, Double)
safety_factor_target : Double
}fn FeaLoadCase::with_force(self : FeaLoadCase, region : BoundaryRegion, force_n : (Double, Double, Double)) -> FeaLoadCasefn FeaLoadCase::with_pressure(self : FeaLoadCase, region : BoundaryRegion, pressure_mpa : Double) -> FeaLoadCasefn FeaLoadCase::with_print_z_axis(self : FeaLoadCase, print_z_axis : (Double, Double, Double)) -> FeaLoadCasefn FeaLoadCase::with_safety_factor_target(self : FeaLoadCase, safety_factor_target : Double) -> FeaLoadCasefn FeaLoadCase::with_torque(self : FeaLoadCase, region : BoundaryRegion, origin_mm~ : (Double, Double, Double), axis~ : (Double, Double, Double), torque_nm~ : Double) -> FeaLoadCasepub(all) struct Fit {
name : String
fit_class : FitClass
nominal_mm : Double
min_mm : Double
max_mm : Double
}pub(all) enum FitClass {
Nominal
Clearance
Transition
Interference
}pub struct HostViolation {
layer_index : Int
label : String
host : String
message : String
}pub(all) struct JointSpec {
kind : ConnectionKind
pair : MatePair
dynamics : JointDynamics?
mimic : JointMimic?
transmission_reduction : Double?
} derive(Debug)fn JointSpec::continuous(limit? : JointLimit?, offset_mm? : Double, angle_deg? : Double, flip_axis? : Bool, dynamics? : JointDynamics?, mimic? : JointMimic?, transmission_reduction? : Double?) -> JointSpecfn JointSpec::prismatic(limit : JointLimit, offset_mm? : Double, angle_deg? : Double, flip_axis? : Bool, dynamics? : JointDynamics?, mimic? : JointMimic?, transmission_reduction? : Double?) -> JointSpecfn JointSpec::revolute(limit : JointLimit, offset_mm? : Double, angle_deg? : Double, flip_axis? : Bool, dynamics? : JointDynamics?, mimic? : JointMimic?, transmission_reduction? : Double?) -> JointSpecpub struct LayerPlacement {
index : Int
side : Int
label : String
reason : String
matched_names : Array[String]
assembled_span_mm : (Double, Double)
final_span_mm : (Double, Double)
offset_mm : (Double, Double, Double)
declared_gap_mm : Double
host : String?
slide_mm : (Double, Double, Double)
color : Rgb?
}pub(all) enum MatchMode {
Contains
Exact
Glob
}pub(all) struct MaterialProperties {
e_mpa : Double
nu : Double
yield_xy_mpa : Double
interlayer_z_mpa : Double
density_kg_m3 : Double
}fn MaterialProperties::new(e_mpa~ : Double, nu~ : Double, yield_xy_mpa~ : Double, interlayer_z_mpa~ : Double, density_kg_m3~ : Double) -> MaterialPropertiespub(all) struct PartMeta {
part_number : String
description : String
supplier : String
supplier_url : String
material : String
process : String
finish : String
unit_cost_usd : Double
notes : String
print_bed_orient : PrintBedOrient
single_body_print : Bool
bom_quantity : Int
detail : DetailLevel?
}fn PartMeta::new(part_number : String, description? : String, supplier? : String, supplier_url? : String, material? : String, process? : String, finish? : String, unit_cost_usd? : Double, notes? : String, print_bed_orient? : PrintBedOrient, single_body_print? : Bool, bom_quantity? : Int, detail? : DetailLevel?) -> PartMetapub(all) struct PcbPlacement {
reference : String
value : String
footprint : String
x_mm : Double
y_mm : Double
rotation_deg : Double
side : String
}fn PcbPlacement::new(reference? : String, value? : String, footprint? : String, x_mm? : Double, y_mm? : Double, rotation_deg? : Double, side? : String) -> PcbPlacementpub(all) struct PcbSpec {
model : String
length_mm : Double
width_mm : Double
thickness_mm : Double
mounting_holes : Int
mounting_hole_diam_mm : Double
max_component_height_mm : Double
connectors : Array[String]
placements : Array[PcbPlacement]
}fn PcbSpec::new(model? : String, length_mm? : Double, width_mm? : Double, thickness_mm? : Double, mounting_holes? : Int, mounting_hole_diam_mm? : Double, max_component_height_mm? : Double, connectors? : Array[String], placements? : Array[PcbPlacement]) -> PcbSpecpub(all) enum PortKind {
Mechanical
Power
Signal
Bus
Fluid
Sensor
Ground
}pub(all) struct PortLine {
path : String
name : String
kind : String
spec : String
}pub(all) struct PoseAnalysis {
name : String
total_mass_kg : Double
com_m : (Double, Double, Double)
inertia : Inertia
joints : Array[JointTorque]
contacts : Array[ContactAlignment]
contact_misalignment_m : Double
} derive(Eq, Debug)pub(all) struct PowerBudget {
actuators : Array[ActuatorLine]
sensors : Array[SensorLine]
ports : Array[PortLine]
wires : Array[WireLine]
routes : Array[RouteLine]
}fn PrintBedSpec::fits(self : PrintBedSpec, width_mm : Double, depth_mm : Double, height_mm : Double) -> Boolfn RewardWeights::new(forward_vel? : Double, target_height? : Double, upright? : Double, energy? : Double, smoothness? : Double, alive? : Double) -> RewardWeightspub(all) struct RlTaskSpec {
kind : RlTaskKind
control_dt_s : Double
episode_len_s : Double
target_base_height_m : Double
target_vel_x_mps : Double
termination_tilt_deg : Double
termination_min_z_m : Double
imu_link : String
wheel_links : Array[String]
hip_joints : Array[String]
wheel_joints : Array[String]
action_scales : Map[String, Double]
rewards : RewardWeights
domain_rand : DomainRandSpec
} derive(Eq, Debug)fn RlTaskSpec::new(kind? : RlTaskKind, control_dt_s? : Double, episode_len_s? : Double, target_base_height_m? : Double, target_vel_x_mps? : Double, termination_tilt_deg? : Double, termination_min_z_m? : Double, imu_link? : String, wheel_links? : Array[String], hip_joints? : Array[String], wheel_joints? : Array[String], action_scales? : Map[String, Double], rewards? : RewardWeights, domain_rand? : DomainRandSpec) -> RlTaskSpecpub(all) struct RobotAnalysis {
total_mass_kg : Double
poses : Array[PoseAnalysis]
warnings : Array[String]
} derive(Eq, Debug)pub(all) enum SensorKind {
LimitSwitch
Encoder
Imu
Camera
Force
}pub(all) struct SensorSpec {
kind : SensorKind
model : String
interface : String
voltage_v : Double
current_ma : Double
range : String
resolution : String
}fn SensorSpec::new(kind : SensorKind, model? : String, interface? : String, voltage_v? : Double, current_ma? : Double, range? : String, resolution? : String) -> SensorSpecpub(all) struct SupplierLink {
part_number : String
supplier : String
supplier_url : String
notes : String
unit_cost_usd : Double?
}fn SupplierLink::new(part_number~ : String, supplier? : String, supplier_url? : String, notes? : String, unit_cost_usd? : Double) -> SupplierLinkpub(all) enum VisualMode {
Primitives
MeshPackage(String)
}pub(all) struct WireRun {
name : String
from_component : String
from_port : String
to_component : String
to_port : String
gauge_awg : Int
length_mm : Double
notes : String
}let DEFAULT_ELEPHANT_FOOT_CHAMFER_MM : Doublefn analyze_robot(component : Component, poses : Array[(String, Map[String, Double])]) -> RobotAnalysisfn get_version() -> Stringfn merge_supplier_links(defaults : Array[SupplierLink], overrides : Array[SupplierLink]) -> Array[SupplierLink]fn pattern_grid_mm(cols : Int, rows : Int, pitch_x_mm : Double, pitch_y_mm : Double, center_x? : Double, center_y? : Double) -> Array[(Double, Double)]fn pattern_line_mm(count : Int, pitch_mm : Double, angle_deg? : Double, center_x? : Double, center_y? : Double) -> Array[(Double, Double)]fn pattern_rect_mm(width_mm : Double, height_mm : Double, center_x? : Double, center_y? : Double) -> Array[(Double, Double)]fn pattern_ring_mm(count : Int, diam_mm~ : Double, phase_deg? : Double, center_x? : Double, center_y? : Double) -> Array[(Double, Double)]fn sanitize_part_number(part_number : String) -> StringInstall
Download zipPluggable parametric CAD and URDF robotics component library in MoonBit