Robots
For joint timing, pose sampling and the boundary with dynamics, see Robot motion.
An assembly whose mates leave motion free is a mechanism. The Joints card reads it as a robot: links, joints and their limits. You can move it, check it and export it for simulators.
The joint tree
Each pair of parts with mates between them is one joint. The kind of joint is read from the motion the mates leave free, not from the mates' names:
| Free motion | Joint |
|---|---|
| none | fixed |
| one turn | revolute, or continuous without limits |
| one slide | prismatic |
| a turn and the slide along its axis (cylindrical), a plane's two slides and a turn, a ball's three turns | a chain of one-degree joints through extra links |
Anything else, such as a screw motion or two turns about different axes, is refused with a typed reason. A part joined twice round the graph closes a loop; the tree keeps one path and lists the loop, which the Loop line shows.
Some joints follow another instead of moving on their own:
- Gears. Two spur gears meshing on one carrier's joints are coupled: the second follows the first at the gear ratio. A joint's gears are those of its part and of the parts fixed to it, so a gear locked to its shaft turns with the shaft's joint. A locked gear off the joint's axis is noted
GEAR_NOT_COUPLEDrather than left out. - Cams. A Cam mate, from a face of the cam part to the follower's flat face, makes the follower ride the lobe. The mate holds nothing itself: the follower's own mates place it in its guide, and its slide follows the cam's joint by the lobe's lift. A cam mate from the follower to another sliding part, such as a valve it pushes, moves that part with it, so chains like crank → gear → cam → follower → valve work. The Joints card says "follows joint on its cam (mate)".
- The lobe is read from the cam's faces at the follower's face: flats and arcs along the cam's axis, such as an arc-and-line profile. Anything else is refused,
CAM_PROFILE_UNSUPPORTED. - Nothing is coupled, and
CAM_NOT_SEATEDsays why, when the cam has no joint to drive it, the follower doesn't slide, its face isn't flat or isn't across the cam's axis, the two are on different links, or the face is off the lobe at the solved pose (by how much). - The follower's face is taken as an infinite plane, so a face narrower than its contact's travel isn't caught.
- The lobe is read from the cam's faces at the follower's face: flats and arcs along the cam's axis, such as an arc-and-line profile. Anything else is refused,
- One leader each. A joint follows one leader: a second cam or push on it is refused,
COUPLED_TWICE. Couplings that lead back round to their own joint are cut where the cycle closes,COUPLING_CYCLE.
Base link chooses which link stays put. Angles are in degrees and lengths in millimetres in the card; exports write metres and radians.
Moving it

Sliders. Each joint's slider poses the robot, within its limits. Home returns every joint to zero, the pose the mates solve to.
Numeric pose. For an independent moving joint, enter turns in degrees or slides in mm. Choose Apply or press Enter to apply the value. Typing alone does not change the pose. Choose Cancel or press Escape to discard the edit and restore the displayed value. A value outside the joint's set lower or upper limit is refused; the previous pose stays unchanged. The slider's input window does not add physical joint limits.
A pose is a preview. It isn't saved, and it doesn't add undo steps.
Links. Link masses lists each link's mass and centre of mass, from its bodies and their materials. The card shows the gravity torques at the current pose. Right after an edit, these wait until the masses are worked out.
Paths. Add waypoint records poses. Check path sweeps the robot along them and reports the first collision, with continuous collision between samples.
- A sweep can run out of its sample budget. The path is then neither clear nor in contact: Check path and the agent's
sweep_pathandcheck_pathsay "not certified" with how far the sweep got and the least clearance met (exhaustedin the reply), and never report a collision or a time of impact for it. The default budget is 20,000 samples per sweep. For an open timed path,maxSamplesapplies to each timed segment. A closed-loop motion divides each timed segment into chords of at most 1° of rotation or 1 mm of travel. Each chord has its ownmaxSamplesbudget. The closed-loop budget is not shared across the timed segment or the whole motion. The returnedsamplesis the total used; it can exceedmaxSamples.exhausted.samplesis the count in the segment, or closed-loop chord, that ran out of budget. - Designed contact isn't a collision. Some faces touch by design, and the sweep leaves those to the design while it still checks the rest of the same links. Each pair it skips says why.
- Two meshing gears' teeth are the coupling's to hold.
- Two links pinned in a planar loop can't cross where they're stacked.
- A cam follower's face rides the lobe. The rest of the follower is checked against the cam.
- A running fit: the two round faces of a concentric mate, such as a piston in its bore. The display meshes' facets cut inside a true circle, so a 0.1 mm clearance would read as contact. Within the facets' depth, plus 0.05 mm, the fit's faces don't count as touching; a boss past the bore still does.
- The cam's and the fit's faces are checked at the sweep's steps, at most 1/90 of the move apart, not certified between them as the rest of the sweep is.
- Closed loops along a motion. The agent's
play_motionandcheck_pathclose a looped robot's loop at every pose: the motion names the driving joints, and the passive ones are solved.check_pathcuts each segment into chords at most 1° (or 1 mm) of the drivers apart and certifies each one. A chord's middle isn't closed exactly, and the reply says by how much, asloops: {chords, chordResidual}, withchordResidualin mm. A waypoint that gives a passive joint is refused,LOOP_PASSIVE. In Studio, Play motion and the time scrubber close supported looped motions too. Studio's Check path still refuses a looped motion withLOOP_OPEN.
- A sweep can run out of its sample budget. The path is then neither clear nor in contact: Check path and the agent's
Playing a motion. Play motion plays the motion chosen in Motion choice in time. Its length shows before it plays.
- The draft is the path above: from home, through the waypoints, to the pose shown. Each joint moves at its velocity limit, or at 180/π deg/s (about 57.3 deg/s) for a turn and 100 mm/s for a slide when it has none.
- A saved motion plays as the document keeps it: its waypoints, profile and limits.
- Pause motion holds it. The Motion time scrubber sets the pose at a time, Loop motion repeats it, and Motion speed plays it at 0.25× to 2×.
- For a supported looped motion, the driving joints follow the path and the passive joints are solved. Seeking forward or backward keeps the assembled branch through earlier segment joins. A refused seek leaves the pose and time unchanged. Playing a single joint's preview on a looped robot is still refused with
LOOP_OPEN; choose a supported motion in Motion choice instead. - For an open-chain motion, the first contact on the way is reported as "Contact link – link at t … s". From then on the two links are marked: outlined on WebGPU, tinted on WebGL2.
- Playing saves nothing. Moving a slider, Home, a change to the waypoints or another choice stops it.

Saving a motion. With the draft chosen, name it in Motion name and Save as motion keeps it in the document, in degrees and millimetres, and chooses it. A motion of the same name is replaced. Saving is an undo step; the pose shown and the play state are never saved. For a supported looped motion, Add waypoint and Save as motion keep only driving-joint values. The solved passive-joint values stay in the preview and are worked out again when the motion plays.
Workspace. Workspace (Map workspace) samples the reachable space and draws it as voxels, with a summary and the samples. Download workspace saves it.
Limits and sizing
Revolute and prismatic joints need their lower and upper limits, effort and velocity before they export. The agent and cad-cli can also run two checks:
- robot-check works through the arm's duty: limits, sweeps, the torques at every pose, and the actuators against their ratings. It lists every margin.
- robot-size raises actuators and ratings, or slows the profile, round by round until every margin is above zero, or stops with a typed reason when no sizing can fix the brief.
Duty files and public reports
A public duty file has moves. Each move supplies from, to, profile and limits. Turning values use degrees; sliding values use mm. Use joint_limits by joint key when a move mixes turns and slides. Velocity, acceleration and jerk use the corresponding units per second, second squared and second cubed. dwell and serviceLife use seconds, clearance uses mm, and g uses mm/s². inertia_ratio_max is dimensionless. The actuators map names catalogue motor and reducer ids by joint key. It does not supply new sourced hardware data.
The CLI passes canonical PublicDuty directly to robotCheckOfDoc; sizing uses robotSizeOfDoc. Public serviceLife and dwell remain in seconds. The sample also uses the explicitly importable robot/native/duty.readDuty to decode the same public input into native operands, then calls nativeRobotCheckOfDoc and nativeRobotSizeOfDoc for comparison. Those native operands use radians, existing SI quantities and life_h in hours. The shared dutyJson adapter writes public values back. The sample compares the shared projections with the canonical results on the shipped SCARA document, including its turn and slide:
const output = dutyJson(tree, duty);
assert.deepEqual(output.moves[0].to, { 'base~arm1': 10, 'arm2~quill': -5 }); // degrees, mm
near(output.moves[0].joint_limits['base~arm1'].velocity, 60); // degree/s
near(output.moves[0].joint_limits['arm2~quill'].velocity, 5); // mm/s
assert.equal(output.moves[0].dwell, 0.5); // seconds
assert.equal(output.serviceLife, 7200); // seconds
assert.equal(output.clearance, 0.25); // mm
assert.deepEqual(output.g, [0, 0, -9810]); // mm/s²robot-check publishes the original harness result through harnessJson. A margin contains value, limit, unit, its dimensionless margin, its source and ok. Angles use degree or degree/s; turning effort uses N·mm and slide effort uses N. The adapter converts the original quantities before rounding. A non-finite quantity is null, not an invented finite measurement. Decisions, unknowns and sources keep their meaning.
Project the original report before cloning or serializing it. A cloned margin has no raw quantity identity. Changing a margin's value, limit or unit also invalidates that identity. Projection then refuses with HARNESS_RAW_PROVENANCE_UNAVAILABLE:
const original = await nativeRobotCheckOfDoc(doc, bodies, evaluate, duty);
const before = JSON.stringify(original);
const report = harnessJson(tree, original); // project the original before cloning or serializing it
assert.deepEqual(await canonicalRobotCheckOfDoc(doc, bodies, evaluate, input), report);
const range = report.margins.find(m => m.check === 'joint range' && m.joint === 'base~arm1' && m.detail === 'to');
near(range.value, 10); // degrees
near(range.limit, 130); // degrees, the sample's upper limit
assert.equal(range.unit, 'degree');Consistency checks use dimensionless errorRatio and limitRatio: 1, and retain their original ok decision. Two zero quantities give an error ratio of 0. A positive error with a zero limit gives null and reason: "zero-limit". Non-finite quantities or ratio overflow give null and reason: "non-finite-ratio". The old mixed-unit value and tol fields are not public consistency fields.
The scripted sizer's sizedJson result uses the same public boundaries for tree, duty and report. It retains ok, rounds, trace and any stopped reason. Trace text keeps its explicitly stated original units. The CLI writes the robot document and a public .duty.json file, and prints a summary. It does not print that whole result. These are the CLI's shared adapters, not new Robot facade methods. This sample limits sizing to zero rounds and checks the actual returned contract; it does not demonstrate a successful search for a hardware design:
const { sized } = await nativeRobotSizeOfDoc(doc, bodies, evaluate, duty, { maxRounds: 0 });
const output = sizedJson(sized); // actual producer output, using the same public projectors
const canonical = await canonicalRobotSizeOfDoc(doc, bodies, evaluate, input, { maxRounds: 0 });
assert.ok(!('error' in canonical));
assert.deepEqual(canonical.sized, output);
assert.equal(output.ok, sized.ok);
assert.equal(output.rounds, sized.rounds);
assert.deepEqual(output.trace, sized.trace);
assert.equal(output.duty.serviceLife, 7200);
near(output.tree.joints.find(j => j.key === 'base~arm1').limit.velocity, 180);
near(output.tree.joints.find(j => j.key === 'base~arm1').limit.effort, 2000); // N·mm
near(output.tree.joints.find(j => j.key === 'arm2~quill').limit.velocity, 100); // mm/s
near(output.tree.joints.find(j => j.key === 'arm2~quill').limit.effort, 50); // NGravity torques, the sweep and inverse kinematics follow a cam's coupling. A move's torques through a cam are refused, CAM_UNSUPPORTED: the lift's second derivative isn't worked out yet.
Exporting
Export URDF, Export MJCF, Export SDF and Export USD write the robot with:
- one link per part, the joint at the child;
- the visual mesh and a convex hull for collision;
- each link's mass in kg, centre of mass in m, and inertia tensor in kg·m². Rotations follow the file format.
No format holds a cam coupling, so a robot with a cam follower is refused, CAM_UNSUPPORTED. The agent's export_urdf and export_mjcf take leave_out: ["cam"], which writes the follower as a free joint and notes it.
Every export is checked against its format's rules by our own reader before it is written. The URDF and MJCF outputs have also been read back by external tools — urdfdom's check_urdf and MuJoCo — and their kinematics match the studio's.
Tool and sensor frames
A frame is a named pose on a link: a tool's centre point, or a camera. It is kept with the robot's settings, beside the joints.
In the viewport. Each frame is drawn where the pose puts it, as an axis triad (X red, Y green, Z blue) with its name on a chip: a tool's in the accent colour, a sensor's in cyan. It moves with the joint sliders, and keeps its size as the arm moves.
In the Joints card. Each frame's origin (mm) and its Z axis at the pose shown, in the assembly's coordinates.
Setting them. The agent sets frames; the studio has no editor for them yet.
Where a frame sits. On a link, posed in that link's part's own coordinates: a position in mm, and a rotation in degrees about X, then Y, then Z, as a placed part's rotation. A frame may be a
toolor asensor.What uses it.
- Forward kinematics moves a frame with its link.
- Inverse kinematics can reach a frame's pose, or only its position.
- The workspace map of a frame is its link's, taken at the frame's origin.
How each export writes it. As a fixed child of its link, at its pose. A frame adds no mass, and with no frames every export is byte for byte as before.
Format A frame is URDF A massless link on a fixed joint ( <name>_fixed), as ROS-Industrial'stool0SDF A link with a tiny inertial (an SDF link without one would weigh 1 kg), fixed to its link MJCF A body welded to its link, with no joint and no mass, and a <site>of its name at its originUSD An Xformbeneath its link's primWhat is refused.
[FRAME_NAME]: a name that isn't letters, digits and_, or that one of the export's own links or joints already uses.[FRAME_LINK_MISSING]: a frame on a part that isn't in the assembly.[FRAME_LINK_STALE]: a frame on a part that isn't a link of the robot as it stands.[FRAME_POSE]: a pose that isn't three numbers.
A frame is refused this way, never dropped. See Refusal codes.
The agent's action.
assembly.framessets, changes or removes frames. Frames are part of the robot's settings, so the agent proposes every change, at any autonomy level.How it was checked.
- Read back with our own readers, each frame is where forward kinematics puts it, at 21 poses.
- External tools read the frames too: MuJoCo 3.3.0 as sites, usd-core as prims beneath their links, and urdfdom's
check_urdf. - SDF is checked only by our own reader.
Sample robots
@barocss/cad-model ships eight sample robots under samples/robots/, each a .bcad file you can open, with index.json listing them. They're built from blocks joined by the studio's mates. Each joint has an estimated rating, so every sample exports, and each carries one demo motion in its robot settings, in degrees and millimetres.
| Sample | What it is | Joints |
|---|---|---|
arm-2r | A planar arm | Two turns about parallel vertical axes, 40 mm apart, ±150° |
scara | A SCARA arm | Turn (±130°), turn (±145°), a slide of ±40 mm, turn (±360°) |
arm-6r | An industrial arm's chain | Six turns about Z, Y, Y, Z, Y and Z: waist, shoulder, elbow and a three-axis wrist, each with its limits |
gantry-ppp | A Cartesian gantry | Slides along X (0–200 mm), Y (0–120 mm) and Z (±40 mm) |
pan-tilt | A camera head | Pan about Z (±170°), tilt about X (±60°), and a camera sensor frame |
gripper | A gear-coupled gripper | The left finger turns ±30°; the right one follows on meshing 20-tooth gears, the other way |
four-bar | A four-bar linkage | Crank, coupler and rocker, closed in one loop |
gear-joint | A gear-driven joint | A 20-tooth gear driving a 30-tooth one, which turns two thirds as far, the other way |
Open one from Templates, under Samples · Robots. It opens as Open would open its file, with its joints in the Joints card and its demo motion in Motion choice.

Set a pose with the sliders, and Play motion plays the draft from home to it. Here three samples are paused half-way:



In code
The object API reads an assembly as a robot: assembly(…).robot(). It exposes joints(), pose(values), path(waypoints).check(), inertia(), gravity(values), and the robot export methods. The public contract below applies to the facade, agent replies and stored robot settings.
For Robot.pose(values), turning-joint inputs and the returned values are in degrees. Sliding-joint values are in millimetres. RobotPath.waypoints and RobotPath.poseAt(t) use the same units. Link and frame placements keep positions in mm and rotations in degrees.
Robot unit boundaries
R7 contract preparation
This section records the confirmed R7 public contract. Focused samples check angular metadata, B1 mass/gravity and the shared B2 duty/harness/sized boundaries. Further evaluation, orientation, print, CAM and material field changes and the final combined checks are pending. The full R7 contract is not yet product-qualified.
Use degrees for turning joints and mm for sliding joints. Resolve the joint type before you convert a value.
| Interface or field | Turning joint | Sliding joint |
|---|---|---|
Robot.pose(values) input and returned values | degrees | mm |
RobotPath.waypoints, RobotPath.poseAt(t) | degrees | mm |
Robot.path(waypoints, { limits }) velocity and acceleration | deg/s, deg/s² | mm/s, mm/s² |
Robot.joints(), Robot.setJoints() and stored RobotSettings.joints lower/upper limits | degrees | mm |
| Public and stored joint velocity | deg/s | mm/s |
| Public acceleration and jerk | deg/s², deg/s³ | mm/s², mm/s³ |
| Public and stored joint effort; reported torque or force | N·mm | N |
RobotPath.check() contact values | degrees | mm |
The internal joint tree, kinematics and dynamics keep their radians and SI calculations. Adapters convert at the public boundary. Values that already use degrees, such as pose inputs and saved motion waypoints, need no second conversion. A value of 90 must remain a quarter turn after a save, read, pose or contact report.
For a mimic relation, follower = multiplier × leader + offset. The offset uses the follower's unit. The multiplier uses the follower's unit divided by the leader's unit. It is dimensionless when both use the same unit. For a turn that drives a slide, a public multiplier of 0.1 mm/degree and an offset of 2 mm give 11 mm at 90 degrees. For the reverse relation, 10 degrees/mm and an offset of 5 degrees give 35 degrees at 3 mm. Convert both the multiplier and offset when you pass between public and internal units. Apply the same joint-type rule to cam and contact values.
Nested gear placements couplings[i].g1.rotation and g2.rotation use degrees in the gear pair's common frame. The internal FK and GearPlacement keep radians. GearSpec pressure and helix angles already use degrees; do not convert them again. A pose's gear metadata uses phase and homePhase in degrees and backlash in mm. loops.residual is the pin distance in mm for a pin closer. For a general closer, it is the original norm of distance and rotation constraint rows, not a pure length. The four-bar pin-loop sample's checked motion reports loops.chordResidual in mm.
Public reports. Robot.inertia() returns { links }. Each link uses these fields, as does its agent report:
| Field | Public unit |
|---|---|
links[i].mass | g |
links[i].centroid | mm |
links[i].inertia, links[i].principal.moments | g·mm² |
links[i].frame.origin | mm |
links[i].bodies[j].mass | g |
For Robot.gravity(values, g), supply g in mm/s². The default is [0, 0, -9806.65], which preserves the existing 9.80665 m/s² physical value. An explicit input of [0, 0, -9810] selects 9.81 m/s² instead. The reply's gravity is the magnitude in mm/s². It is not a returned vector. torques and generalized contain the holding moment or force by joint key. Read units[key]: a turn uses N·mm, and a slide uses N. Density remains g/cm³.
A motion report uses joints[key].peak, rms and unit for moment or force. Its distance, peakVelocity, peakAcceleration and peakJerk use degrees or mm and the corresponding time derivatives. at is in seconds. These motion fields are separate from a gravity reply. The object facade exposes path() for motion; it has no move() or size() method.
Public durations and timestamps use seconds. This includes duration, time, at, moveDuration, cycleDuration and dwell. evaluationTime, builtTime and wallTime convert former millisecond values by dividing by 1000. serviceLife converts former hours to seconds by multiplying by 3600. A turning joint's stopDeceleration uses deg/s².
For a physical reference, take a solid 10 × 10 × 10 mm cube at density 2.7 g/cm³. Its mass is 2.7 g, centroid is [5, 5, 5] mm and each diagonal centroidal inertia is 45 g·mm². With the explicit test input [0, 0, -9810] mm/s², its weight is 0.026487 N. With its centre 5 mm perpendicular to a hinge axis, the holding torque magnitude is 0.132435 N·mm. The corresponding native SI values are 0.0027 kg, [0.005, 0.005, 0.005] m and 4.5 × 10⁻⁸ kg·m². The cube samples below check mass, inertia and slide force against these independent values. The hypothetical 5 mm hinge is a calculation only; the tested hinge below uses a drilled arm with a 20 mm lever.
Calculate the sign of a holding torque
Consider one moving link at a prescribed static pose. Its total mass is 100 g, its centre of mass is r = [200, 0, 0] mm from the hinge, and the hinge's positive axis is world +Y. All vectors below are in world coordinates. Use gravity [0, 0, -9806.65] mm/s² and no other applied loads.
| Calculation | Value |
|---|---|
| Convert mass and acceleration | 100 g = 0.1 kg; -9806.65 mm/s² = -9.80665 m/s² |
Gravity force, F = m g | [0, 0, -0.980665] N |
Gravity moment, r × F, with r in mm | [0, +196.133, 0] N·mm |
| Holding moment, opposite to gravity | [0, -196.133, 0] N·mm |
Holding moment projected onto the +Y axis | -196.133 N·mm |
The public gravity reply reports the holding value by joint key, so this single independent turning joint has -196.133 in both torques and generalized, with unit N·mm. It does not report the positive gravity moment. The internal calculation uses a 0.2 m lever and gives -0.196133 N·m; the public conversion multiplies by 1000. A negative value means holding effort opposite to the joint's positive axis. It is not a negative mass or a failure.
Open the holding-torque diagram at full size.
This is a calculated example and diagram, not an API execution, measurement, or validation result. It explains one static pose; it does not predict free motion, acceleration, contact forces, or actuator suitability. The bounded static gravity experiment still requires its supported one-joint model, explicit gravity input and known materials.
Physical report examples
The cube uses aluminium al6061, whose density is 2.7 g/cm³. The code calls the object facade, and compares its reply to closed-form values. The expected values are not taken from a conversion helper.
import { Robot, part, BarocssError } from '@barocss/cad-model/api';const cube = () => part('cube').box({ w: 10, d: 10, h: 10 }).material('al6061');const robot = new Robot(cube().doc), before = robot.doc;
const [link] = robot.inertia().links;
near(link.mass, cubeCase.mass); // 2.7 g
link.centroid.forEach((value, i) => near(value, cubeCase.centroid[i])); // [5, 5, 5] mm
link.inertia.forEach((row, i) => row.forEach((value, j) => near(value, cubeCase.inertia[i][j]))); // diag 45 g·mm²
link.principal.moments.forEach((value, i) => near(value, cubeCase.moments[i]));
link.frame.origin.forEach(value => near(value, 0)); // mm
near(link.bodies[0].mass, cubeCase.mass); // the body's mass is also in gThe gravity input is a vector, and the returned gravity is its magnitude. A cube with no joint can check that magnitude, but supplies no joint holding-force result:
const robot = new Robot(cube().doc);
const standard = robot.gravity();
const explicit = robot.gravity({}, [0, 0, -9810]);
near(standard.gravity, 9806.65); // magnitude, mm/s²
near(explicit.gravity, 9810); // this call supplies 9.81 m/s²Add two perpendicular plane mates to constrain a second cube to a vertical slide. Its holding force is 0.026477955 N at the default gravity and 0.026487 N at the explicit 9810 mm/s². A 20 mm displacement does not change its weight:
function cubeSlide() {
const block = cube().doc;
return new Robot({ ...block,
instances: [{ id: 'slide', name: 'slide', doc: block, position: [10, 10, 0], rotation: [0, 0, 0] }],
mates: [
{ id: 'x', kind: 'coincident', a: { part: 'base', face: 'n1.side1' }, b: { part: 'slide', face: 'n1.side3' } },
{ id: 'y', kind: 'coincident', a: { part: 'base', face: 'n1.side2' }, b: { part: 'slide', face: 'n1.side0' } },
],
});
}for (const [gravity, expected] of [[undefined, 0.026477955], [cubeCase.gravity, cubeCase.force]]) {
const reply = robot.gravity({ [joint.key]: 20 }, gravity);
assert.equal(reply.units[joint.key], 'N');
near(reply.torques[joint.key], expected); // mass in kg × acceleration in m/s²
near(reply.generalized[joint.key], expected);
t.diagnostic(JSON.stringify({ gravity: reply.gravity, force: reply.torques[joint.key], expected }));
}For turning effort, use a 20 × 20 × 80 mm aluminium block. It has two blind bores of radius 4 mm and depth 8 mm, and two transverse bores of radius 4 mm and length 20 mm. None intersect. The concentric and plane mates make a hinge about +Y. The block's centre is 20 mm above that hinge at home. At 90 degrees, the lever is perpendicular to gravity. The holding moment is negative about +Y, in N·mm:
function drilledArm() {
const block = part('block').box({ w: 20, d: 20, h: 80 })
.hole(b => b.faces().facing('+z'), { d: 8, type: 'blind', depth: 8, x: 10, y: 10 })
.hole(b => b.faces().facing('-z'), { d: 8, type: 'blind', depth: 8, x: 10, y: 10 })
.hole(b => b.faces().facing('+y'), { d: 8, x: 10, y: 20 })
.hole(b => b.faces().facing('+y'), { d: 8, x: 10, y: 60 }).material('al6061');
return new Robot({ ...block.doc,
instances: [{ id: 'arm', name: 'arm', doc: block.doc, position: [0, 20, 40], rotation: [0, 0, 0] }],
mates: [
{ id: 'axis', kind: 'concentric', a: { part: 'base', face: 'n5.side0' }, b: { part: 'arm', face: 'n4.side0' } },
{ id: 'seat', kind: 'coincident', a: { part: 'base', face: 'n1.side2' }, b: { part: 'arm', face: 'n1.side0' } },
],
});
}// Two blind bores (r=4, depth=8) and two transverse through bores (r=4, length=20), with no overlap.
const volume = 20 * 20 * 80 - 2 * Math.PI * 4 ** 2 * 8 - 2 * Math.PI * 4 ** 2 * 20;
const mass = volume * 2.7 / 1000; // g; closed-form geometry, not a report-derived oracle
for (const gravity of [9806.65, 9810]) {
const reply = gravity === 9806.65 ? robot.gravity({ [joint.key]: 90 })
: robot.gravity({ [joint.key]: 90 }, [0, 0, -gravity]);
const expected = -mass * gravity / 1e6 * 20; // N × 20 mm, holding about +Y
assert.equal(reply.units[joint.key], 'N·mm');
near(reply.torques[joint.key], expected);
near(reply.generalized[joint.key], expected);
t.diagnostic(JSON.stringify({ gravity, torque: reply.torques[joint.key], expected }));
}The samples also check a real sweep's initial contact at 45 degrees and −12.5 mm. A separate unit projection fixture covers all four turn/slide mimic combinations. That fixture checks conversion; it does not demonstrate four physically assembled coupling mechanisms. The duty/metadata samples above exercise actual shared producers; the final combined checks after the remaining field changes are still pending.
Native export files retain their format-specific SI units. Their frozen bytes need a separate check from public JSON quantities. Explicit source catalogue records such as { v, unit, src } retain their source units and provenance. They do not change the units of public robot results. See Unit and export comparisons.
import { part, assembly } from '@barocss/cad-model/api';/** A sample robot: its document (a plain-JSON .bcad) opened as a studio part, the assembly read as a robot. */
const open = id => assembly(id, part(id, read(`${id}.bcad`))).robot();- The 2R arm: its two turns, a pose, and a path checked for collisions.
const index = read('index.json'); // [{ id, title, about, file }]
assert.deepEqual(index.map(s => s.id), ['arm-2r', 'scara', 'arm-6r', 'gantry-ppp', 'pan-tilt', 'gripper', 'four-bar', 'gear-joint']);
const arm = open('arm-2r');
assert.deepEqual(arm.joints().joints.map(j => [j.key, j.type]), [['base~a', 'revolute'], ['a~b', 'revolute']]);
const pose = arm.pose({ 'base~a': 90, 'a~b': -90 }); // degrees in; each link's place out
assert.deepEqual(link(pose, 'a').rotation, [0, 0, 90]);
assert.deepEqual(link(pose, 'b').rotation, [0, 0, 0]); // the turns add up: 90 − 90
const [sweep] = arm.path([{}, { 'base~a': 60, 'a~b': -90 }]).check();
assert.equal(sweep.clear, true); // nothing hit on the way- The SCARA arm: the quill's slide.
const scara = open('scara');
assert.deepEqual(scara.joints().joints.map(j => j.type), ['revolute', 'revolute', 'prismatic', 'revolute']);
const home = link(scara.pose(), 'quill').position, down = link(scara.pose({ 'arm2~quill': -30 }), 'quill').position;
assert.deepEqual([down[0] - home[0], down[1] - home[1], down[2] - home[2]], [0, 0, -30]); // the quill slides 30 mm down- The 6R arm: its axes, its demo motion swept, and its URDF read back.
const arm = open('arm-6r');
const axes = arm.joints().joints.map(j => 'XYZ'[j.axis.findIndex(v => Math.abs(v) > 0.5)]);
assert.deepEqual(axes, ['Z', 'Y', 'Y', 'Z', 'Y', 'Z']); // waist, shoulder, elbow, a three-axis wrist
const [reach] = read('arm-6r.bcad').robot.motions; // the sample's demo motion, in degrees
assert.ok(arm.path(reach.path.waypoints).check().every(s => s.clear));
const urdf = arm.urdf('arm-6r'); // { urdf, files, notes, check }
assert.deepEqual(urdf.check, []); // read back by our own URDF reader: nothing wrong- The gantry: each slide carries the ones after it.
const gantry = open('gantry-ppp');
const home = gantry.pose(), moved = gantry.pose({ 'base~x': 150, 'x~y': 100, 'y~z': -30 });
const by = id => link(moved, id).position.map((v, k) => v - link(home, id).position[k]);
assert.deepEqual(by('x'), [150, 0, 0]); // each slide carries the ones after it
assert.deepEqual(by('y'), [150, 100, 0]);
assert.deepEqual(by('z'), [150, 100, -30]);- The pan-tilt head: its camera frame at a pose, and a pose past the tilt's limit.
const head = open('pan-tilt');
const [camera] = head.pose({ 'base~pan': 90, 'pan~tilt': 30 }).frames;
assert.equal(camera.frame, 'camera'); // the sensor frame on the head
assert.deepEqual(camera.rotation, [30, 0, 90]);
assert.deepEqual(head.pose({ 'pan~tilt': 80 }).out_of_limits, ['pan~tilt']); // the tilt stops at ±60°- The gripper: only the leader is given; the follower turns by the coupling.
const gripper = open('gripper');
const [coupling] = gripper.joints().couplings;
assert.deepEqual([coupling.leader, coupling.follower, coupling.multiplier], ['base~left', 'base~right', -1]);
const pose = gripper.pose({ 'base~left': 25 }); // only the leader is given
assert.ok(near(pose.values['base~right'], -25));
assert.equal(pose.gears[0].held, true); // the teeth stay in mesh- The four-bar linkage: the loop, and what a tree format leaves out.
const linkage = open('four-bar');
const { joints, loops } = linkage.joints();
assert.equal(joints.length, 3); // crank, coupler, rocker: a tree of three turns
assert.equal(loops.length, 1); // and the coupler–rocker pin closing the loop
const pose = linkage.pose({ 'base~crank': 60 }); // turn the crank: the others follow
assert.ok(link(pose, 'rocker').rotation[2] !== 0 && link(pose, 'coupler').rotation[2] !== 0);
assert.match(linkage.urdf('four-bar').notes[0], /closure \(Cc\) is not written/); // URDF is a tree format- The gear-driven joint: the gear ratio.
const pose = open('gear-joint').pose({ 'base~g1': 30 });
assert.ok(near(pose.values['base~g2'], -20)); // two thirds as far, the other way- Motions: a path timed and played, the sample's saved motion read, and a path saved as a motion.
path(waypoints, { profile?, limits? })takes waypoints in degrees and millimetres, and limits per joint in deg/s and deg/s² (or mm/s and mm/s²).duration()gives its length in seconds.poseAt(t)returns the driving-joint values at a time in degrees or mm; pass them torobot.pose(...)for the solved passive values and link placements.motion(name)reads a saved motion, andwithMotion(name, path)returns a robot with the path saved.- Supported looped paths, including the sample four-bar's saved
crankmotion, can useduration(),poseAt(t)andproblems(). Supply driving joints only. Seeking keeps the assembled branch through preceding segment joins; a later seek cannot skip an unreachable or dead-point part of the path. problems()returns[]for a supported, closable path, or lists its typed refusal.duration()andposeAt(t)throw the typed refusal when the required path cannot close. Finite lower or upper bounds on passive loop joints remain unsupported and giveLOOP_OPEN. Extra passive-joint waypoint inputs giveLOOP_PASSIVE.- An empty problem list describes the motion's timing and closure. Collision checking along that motion is separate. The four-bar example does not establish support for arbitrary mechanisms with several coupled loops.
- Supported looped paths, including the sample four-bar's saved
const arm = open('arm-2r');
// Home to 60° on the first joint, at 90°/s and 180°/s²: a trapezoid of two half-second ramps and 1/6 s between.
// (`default` limits every joint not named; a joint's own key limits that one.)
const swing = arm.path([{}, { 'base~a': 60 }], { limits: { default: { velocity: 90, acceleration: 180 } } });
assert.deepEqual(swing.problems(), []);
const T = swing.duration();
assert.ok(near(T, 1 + 1 / 6));
assert.ok(near(swing.poseAt(T / 2)['base~a'], 30)); // degrees: half-way at half the time
assert.ok(near(swing.poseAt(T)['base~a'], 60));
const wave = arm.motion('wave'); // the sample's demo motion, saved in its robot settings
assert.deepEqual(wave.waypoints, [{}, { 'base~a': 60, 'a~b': -90 }, { 'base~a': -45, 'a~b': 90 }, {}]);
const saved = arm.withMotion('swing', swing); // a new robot, the motion kept in its document
assert.deepEqual(saved.motion('swing').waypoints, swing.waypoints);- Checking a motion for contact. The open-chain samples' demo motions are clear, and the gripper's meshing fingers are skipped as designed contact. For a looped motion, the object API's
check()still refuses withLOOP_OPEN: its sweep and continuous collision checks do not yet follow the closed motion. Use the agent'scheck_pathfor the supported looped path, with the chord and residual contract described above. Studio's Check path has the sameLOOP_OPENboundary. Playback alone does not certify collision clearance.
// The four-bar plays with its loop closed; sweep/CCD is still refused for it.
const LOOPED = ['four-bar'];
for (const sample of read('index.json').filter(s => !LOOPED.includes(s.id))) {
const [demo] = read(sample.file).robot.motions;
assert.ok(open(sample.id).motion(demo.name).check().every(segment => segment.clear), sample.id);
}
// The gripper's fingers mesh: their teeth are the coupling's to hold, so that pair is skipped, with why.
const [segment] = open('gripper').motion('grip').check();
assert.match(segment.skipped.find(p => p.links.join() === 'left,right').why, /^meshing gears/);
// The first 60-degree move takes 7/6 s. At t=1 s, deceleration has 1/6 s left:
// 60 - (180 / 2) * (1 / 6) ** 2 = 57.5 degrees.
const crank = open('four-bar').motion('crank');
assert.throws(() => crank.check(), e => e.code === 'LOOP_OPEN');
const drivers = crank.poseAt(1);
assert.deepEqual(Object.keys(drivers), ['base~crank']);
assert.ok(near(drivers['base~crank'], 57.5));
assert.deepEqual(crank.problems(), []);- The exports, each with what its reader found and what it had to assume.
checklists what our own reader found wrong when reading the file back, andnoteswhat the export assumed, such as aluminium for a body without a material.
const arm = open('arm-2r');
const urdf = arm.urdf('arm-2r'), mjcf = arm.mjcf('arm-2r');
assert.deepEqual(urdf.files.map(f => f.path), ['meshes/base.stl', 'meshes/base_collision.stl', 'meshes/a.stl',
'meshes/a_collision.stl', 'meshes/b.stl', 'meshes/b_collision.stl']);
assert.deepEqual([urdf.check, mjcf.check], [[], []]); // each read back by our own reader
assert.match(urdf.notes[0], /without a material, aluminium assumed/); // what the export had to assume
assert.equal(arm.sdf('arm-2r').ok, true);
assert.equal(arm.usd('arm-2r').ok, true);