Skip to content

Robot motion: from a path to a pose ​

Physics supports continuous primitive rotation for admitted boxes, spheres and capsules. This does not qualify connected robot joint dynamics. CAD proxy conversion, kinematic pose calculation and control accuracy require their own evidence.

Use CAD Model to prescribe joint motion, calculate link poses and inspect limits. Use Physics to predict motion from initial conditions and applied loads within an admitted physical model. These operations have different inputs, outputs and verification requirements.

The former @barocss/motion package is retired. The functions on this page belong to @barocss/cad-model. A sampled pose is not a command to a motor.

Choose the calculation ​

CalculationInputOutputWhat it does not establish
Forward kinematics (FK)Joint values and a joint treeLink and tool posesForces, contact response or stability
Inverse kinematics (IK)A tool target, joint tree and optional start valuesJoint values, residuals and reachedA clear path to the target or a unique solution
Timed pathJoint waypoints and velocity/acceleration limits, with optional jerkDuration and joint values at a timeWhether an actuator can follow that motion
Clearance or sweepGeometry and selected poses or a pathDistances, contact, or an incomplete checkPhysical contact forces
Statics and inverse dynamicsMass/inertia, gravity and a prescribed pose or motionRequired joint holding effort or motion loadsFree motion from those loads
Forward dynamicsA supported physical model, initial state and loadsState after a time stepGeneral robot, controller or hardware acceptance

See the Robot API, the Studio robot workflow and the kinematics algorithms for their full contracts.

Keep the units and frame explicit ​

The Robot object uses degrees for turns and mm for slides. Path times are seconds. Velocity, acceleration and jerk use the joint's own units per second, second squared and second cubed. A default rate has each joint's own unit; a named joint rate overrides it.

RobotPath.poseAt(t) returns joint inputs. Pass them to robot.pose(values) to obtain link positions in mm and rotations in degrees. These placements use the assembly's coordinates. Missing joint values mean zero at the solved home pose, rather than the previous waypoint's value.

The lower-level FK/IK and timed-path functions use radians for turns and mm for slides and point positions. IK reports its position residual in metres and angle residual in radians. Do not pass degree values to solveIk, or convert a public RobotPath.poseAt reply a second time before Robot.pose.

Read Robot unit boundaries before combining public MMGS mass/inertia reports with SI dynamics. Declare the gravity vector and frame; the robot gravity default is along -Z, while many Physics examples use -Y. A display adapter must make any frame change explicit.

Time a turn and a slide together ​

The following repository sample opens the shipped SCARA document. It uses its first turning joint and the quill's sliding joint. Other joints stay at their zero values. The file path is relative to apps/library-docs/samples; an application can instead supply its own .bcad document.

mjs
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { assembly, part, BarocssError } from '@barocss/cad-model/api';
mjs
// Repository sample: this file runs from apps/library-docs/samples.
const samplePath = resolve(import.meta.dirname, '../../../packages/barocss-cad-model/samples/robots/scara.bcad');
const scaraDocument = JSON.parse(readFileSync(samplePath, 'utf8'));
const scara = assembly('scara', part('scara', scaraDocument)).robot().setJoints({ joints: {
  'base~arm1': { lower: -90, upper: 90, velocity: 60 },
  'arm2~quill': { lower: -40, upper: 40, velocity: 15 },
} });
const turn = 'base~arm1', slide = 'arm2~quill';

Set the joint limits separately from the timing rates. Limits describe the allowed joint range. Rates describe how this particular path is timed. setJoints and withMotion return new robot objects; they keep the originals.

mjs
const waypoints = [
  { [turn]: 0, [slide]: 0 },
  { [turn]: 0, [slide]: 0 }, // Repeated waypoint: zero duration.
  { [turn]: 60, [slide]: -30 },
  { [turn]: 0, [slide]: 0 },
];
const limits = {
  default: { velocity: 60, acceleration: 120 }, // deg/s and deg/s² for a turn.
  [slide]: { velocity: 15, acceleration: 30 },  // mm/s and mm/s² for this slide.
};
const path = scara.path(waypoints, { profile: 'trapezoid', limits });
const recorded = scara.withMotion('turn-and-lower', path);
const motion = recorded.motion('turn-and-lower');
assert.deepEqual(motion.problems(), []);
// The limiting slide takes 30/15 + 15/30 = 2.5 s, each way.
assert.ok(Math.abs(motion.duration() - 5) <= 1e-12);

The turn travels 60° at a maximum 60°/s and 120°/s². The slide travels 30 mm at 15 mm/s and 30 mm/s². Each segment uses one normalized progress function shared by both joints. The tighter slide rate limits that progress to 0.5/s and its acceleration to 1/s².

For a rest-to-rest trapezoid with distance d, speed v and acceleration a, duration is d/v + v/a when d >= v²/a. Here the slide takes 30/15 + 15/30 = 2.5 s. The return takes another 2.5 s. The repeated initial waypoint adds zero time. Every nonzero segment starts and ends at rest; a waypoint join is not a blended robot corner.

Read the joint inputs, then obtain the pose ​

mjs
const values = motion.poseAt(1.25); // Seconds. Returns degrees and mm.
assert.ok(Math.abs(values[turn] - 30) <= 1e-9);
assert.ok(Math.abs(values[slide] + 15) <= 1e-9);
const pose = recorded.pose(values); // Link positions in mm, rotations in degrees.
const quill = pose.links.find(link => link.link === 'quill');
assert.deepEqual(pose.out_of_limits, []);
// After solving the mates, the quill origin is (225,25,-30), with pivot (40,40).
const angle = 30 * Math.PI / 180;
const analyticPoint = [40 + 185 * Math.cos(angle) + 15 * Math.sin(angle),
  40 + 185 * Math.sin(angle) - 15 * Math.cos(angle), -45];
// Public pose positions are reported to six decimal places in mm.
const expected = analyticPoint.map(value => Math.round(value * 1e6) / 1e6);
quill.position.forEach((value, axis) => assert.ok(Math.abs(value - expected[axis]) <= 1e-9));

At 1.25 s, the shared progress is one half: 30° and -15 mm. The example compares the quill origin with an independent rotation about the first joint's off-origin pivot. The mate solve places the home quill origin at (225,25,-30) mm; this differs from the document's initial unsolved instance position. Public link positions are rounded to six decimal places in mm. The example compares the analytic point at that same reporting precision, with a 1e-9 mm comparison tolerance. It records the difference from the unrounded analytic point separately. This does not establish full-precision FK accuracy from a rounded reply. That separate reporting difference must be at most 0.5e-6 mm per component, the half-step bound for six decimal places. It is not a wider numerical FK tolerance. The tests also sample both outward and return segments. This checks the stated kinematics and timing; it does not qualify a physical SCARA arm or certify clearance.

Finite times before the start or after the end return the corresponding endpoint. Negative finite time is valid. NaN and infinite query times are refused. A zero-distance segment has no dwell time; add a separate supported timing or application rule if the operation needs a physical pause.

Choose an S-curve when jerk is constrained ​

mjs
const smooth = scara.path([{ [turn]: 0, [slide]: 0 }, { [turn]: 60, [slide]: -30 }], {
  profile: 's-curve', limits: {
    default: { velocity: 60, acceleration: 120, jerk: 240 },
    [slide]: { velocity: 15, acceleration: 30, jerk: 60 },
  },
});
assert.deepEqual(smooth.problems(), []);
const duration = smooth.duration();
const middle = smooth.poseAt(duration / 2);
assert.ok(Math.abs(middle[turn] - 30) <= 1e-9);
assert.ok(Math.abs(middle[slide] + 15) <= 1e-9);

An S-curve also needs positive jerk limits for every moving joint. It keeps the same joint-space line and synchronized start/end values, but changes the progress in time. This example takes 3 s rather than 2.5 s for the outward segment. A slower profile does not by itself establish acceptable motor torque, reducer life or control tracking.

Inspect refusals before playback ​

mjs
const beyondTravel = scara.path([{}, { [slide]: -41 }], { limits });
assert.deepEqual(beyondTravel.problems().map(problem => problem.code), ['JOINT_LIMIT']);
assert.throws(() => beyondTravel.poseAt(0), error => error instanceof BarocssError && error.code === 'JOINT_LIMIT');
assert.throws(() => motion.poseAt(NaN), error => error instanceof BarocssError && error.code === 'VALUE');
// A direct pose preview reports an out-of-limit value; it does not clamp it.
assert.deepEqual(scara.pose({ [slide]: -41 }).out_of_limits, [slide]);

problems() returns path findings. duration() and poseAt() refuse an invalid path. A direct robot.pose(...) preview has a different contract: it reports out-of-limit joints and keeps the requested values. Inspect out_of_limits before treating a pose as admissible.

Nonfinite joint values use VALUE. Nonfinite supplied rates use LIMITS_BAD. Missing or nonpositive required rates use LIMITS_MISSING. These codes are not a physical failure measurement. See refusal codes.

Solve a tool target with IK ​

The Robot facade has no ik() method. The public robot/ik subpath exposes solveIk(tree,target,start?) for a joint tree. Its target is a rigid motion from the solved home pose, evaluated at the home tool point. It is not an absolute link placement record from Robot.pose.

The following separate analytic tree has a Z turn and an X slide. It has no body geometry or collision model. The tool is 40 mm from the pivot at home. Its analytic target position is [(40+s) cos(theta), (40+s) sin(theta), 0] mm.

mjs
import { solveIk } from '@barocss/cad-model/robot/ik';
import { applyTo, forwardKinematics } from '@barocss/cad-model/robot/fk';
mjs
// A separate analytic RP tree. This is not the SCARA assembly or a collision model.
const tree = {
  version: 1, base: 'base', links: ['base', 'arm', 'tool'].map(id => ({ id, name: id, part: id })),
  joints: [
    { key: 'turn', type: 'revolute', parent: 'base', child: 'arm', origin: [0, 0, 0], axis: [0, 0, 1],
      limit: { lower: -Math.PI / 2, upper: Math.PI / 2 }, mates: [] },
    { key: 'slide', type: 'prismatic', parent: 'arm', child: 'tool', origin: [40, 0, 0], axis: [1, 0, 0],
      limit: { lower: -20, upper: 80 }, mates: [] },
  ], loops: [], couplings: [], problems: [], notes: [],
};
const tool = [40, 0, 0]; // The tool point at the solved home pose, in mm.
function targetMotion(angleRad, slideMm) {
  const c = Math.cos(angleRad), s = Math.sin(angleRad);
  return { R: Float64Array.of(c, -s, 0, s, c, 0, 0, 0, 1),
    t: Float64Array.of(slideMm * c, slideMm * s, 0) };
}

Inspect residuals and joint bounds, including when the target is reachable. The example checks three different targets, rather than accepting one successful pose as general IK qualification.

mjs
const metrics = [];
for (const [degrees, travel] of [[-60, 25], [0, -10], [45, 60]]) {
  const angle = degrees * Math.PI / 180;
  const result = solveIk(tree, { link: 'tool', tool, motion: targetMotion(angle, travel) });
  const q = result.q; // Radians for turn, mm for slide.
  const expectedPoint = [(40 + travel) * Math.cos(angle), (40 + travel) * Math.sin(angle), 0];
  const actualPoint = [(40 + q.slide) * Math.cos(q.turn), (40 + q.slide) * Math.sin(q.turn), 0];
  const errorM = Math.hypot(...actualPoint.map((v, i) => v - expectedPoint[i])) / 1000;
  const errorRad = Math.abs(Math.atan2(Math.sin(q.turn - angle), Math.cos(q.turn - angle)));
  assert.equal(result.reached, true);
  assert.ok(errorM <= 1e-4 && errorRad <= 1e-3);
  assert.ok(q.turn >= -Math.PI / 2 && q.turn <= Math.PI / 2);
  assert.ok(q.slide >= -20 && q.slide <= 80);
  assert.ok(Math.abs(result.errorM - errorM) <= 1e-9);
  assert.ok(Math.abs(result.errorRad - errorRad) <= 1e-7);
  const fk = forwardKinematics(tree, q);
  applyTo(fk.motions.get('tool'), tool).forEach((v, i) => assert.ok(Math.abs(v - actualPoint[i]) <= 1e-9));
  assert.deepEqual(fk.outOfLimits, []);
  metrics.push({ targetDegrees: degrees, slideMm: travel, errorM, errorRad,
    fkErrorMm: Math.max(...applyTo(fk.motions.get('tool'), tool).map((v, i) => Math.abs(v - actualPoint[i]))) });
}

The example uses the solver's existing acceptance limits: 1e-4 m position and 1e-3 rad orientation. It calculates residuals from the returned joint values with independent scalar geometry. The tests also compare FK at those joint values and the solver's reported residuals.

Retain an unreachable result ​

mjs
const targetAngle = Math.PI / 6;
const result = solveIk(tree, { link: 'tool', tool, motion: targetMotion(targetAngle, 120) });
const q = result.q;
const errorM = Math.hypot((40 + q.slide) * Math.cos(q.turn) - 160 * Math.cos(targetAngle),
  (40 + q.slide) * Math.sin(q.turn) - 160 * Math.sin(targetAngle)) / 1000;
assert.equal(result.reached, false);
assert.ok(errorM >= 0.0399); // At least about40mm outside the allowed radius.
assert.deepEqual(forwardKinematics(tree, q).outOfLimits, []);

The requested slide is 120 mm, but its upper limit is 80 mm. The target radius is 160 mm; the allowed radius is at most 120 mm. The independent position residual remains at least about 40 mm. reached:false is a result to handle, not a reason to apply the target pose. Check errorM, errorRad, joint limits and singularity information for each solve. Reachability still does not establish a collision-free transition.

Check geometry separately ​

Use RobotPath.check() for its supported straight joint-space sweeps. Read each reply's clear, contact, skipped and possible exhausted fields. An empty path problem list does not run that sweep. A budget-exhausted sweep is incomplete, rather than clear. The facade's looped path check still refuses with LOOP_OPEN, even when looped playback is supported.

For a current assembly pose, assembly.clearance({near}) is asynchronous and reports display-mesh distances and any pending exact-overlap distinction. It is a separate calculation from path timing and physical collision response. See assembly clearance and robot path limits before interpreting either result.

Keep loads, dynamics and control separate ​

robot.gravity(...) calculates the effort needed to hold the prescribed pose. Motion-load and actuator-sizing tools calculate demands along a prescribed trajectory. They do not advance free motion from applied torque. Their assumptions, material inputs and sourced ratings remain part of the result.

Physics advances its admitted models from initial conditions and loads. Its reduced one-coordinate planar pendulum is separate from PhysicsWorld's joint solver. Numerical checks of that ODE do not implement the planned CAD-bound pendulum experiment workflow or arbitrary connected robot dynamics.

Contact requires its own geometry and impulse checks. Feedback control also requires a defined plant, controller, sensing and tracking criteria. Sending commands to hardware adds its own calibration and measured acceptance. None of those stages follows from path playback, IK success or an export file.

The original eight-box and two-hinge NO_GO records remain. Narrow contact construction checks do not establish long-term stack stability. Existing Physics, Studio and manufacturing HOLDs stay in force. Read limits and experiment evidence stages before using a calculated motion as a physical prediction.