planar-arm-kinematics
v1.0.2
Published
Forward and inverse kinematics for planar (2-link and general n-link) revolute robot arms.
Downloads
135
Maintainers
Readme
planar-arm-kinematics
Forward and inverse kinematics for planar revolute robot arms in the XY plane. Pure JavaScript, no dependencies.
Two levels of API:
- 2-link (2R) closed form — exact, instant, returns both the elbow-up and elbow-down solutions.
- General n-link — a forward map plus a damped-least-squares (Levenberg– Marquardt) numerical IK that handles redundant chains.
All joint angles are radians, each relative to the previous link.
Install
npm install planar-arm-kinematics2-link arm
import { forwardKinematics, analyticIK2R } from "planar-arm-kinematics";
const tip = forwardKinematics(2, 1, 0, Math.PI / 2); // { x: 2, y: 1 }
const sol = analyticIK2R(2, 1, tip.x, tip.y);
// { elbowUp: { t1, t2 }, elbowDown: { t1, t2 } } (or null if unreachable)analyticIK2R returns null when the target lies outside the reachable
annulus [|l1 - l2|, l1 + l2].
General chain
import { forwardChain, jacobianIK } from "planar-arm-kinematics";
const lengths = [1, 1, 1];
const seed = [0.1, 0.1, 0.1];
const res = jacobianIK(lengths, seed, 1.5, 1.0);
// { angles, error, iterations, converged }
forwardChain(lengths, res.angles); // { x, y, phi }jacobianIK accepts { lambda, tol, maxIter }. The damping factor lambda
trades convergence speed for stability near singularities — larger is safer,
smaller is faster.
License
Released into the public domain under the Unlicense.
