Inverse Kinematics (Damped Least Squares)
April 4, 2026 · View on GitHub
Overview & Motivation
Inverse Kinematics (IK) solves the problem dual to Forward Kinematics: given a desired 3D end-effector position , find joint angles such that the end-effector reaches that position. This is the core computational problem in robot arm control, motion planning, and teleoperation.
The Damped Least Squares (DLS) method, also known as the Levenberg-Marquardt approach, iteratively refines a joint-angle estimate by solving a small linear system at each step. Unlike the plain pseudoinverse, DLS adds a damping term that keeps the system numerically stable even when the manipulator is near a singular configuration (such as a fully extended arm).
Mathematical Theory
Jacobian of a Serial Chain
For a serial revolute-joint chain with joints, the geometric Jacobian maps joint velocities to end-effector linear velocity:
Column of is the linear velocity contribution of joint :
where:
- is the joint axis in world frame (accumulated rotation applied to the link-frame axis)
- is the world-frame position of joint (from Forward Kinematics)
- is the current end-effector position
DLS Update Rule
Define the position error:
The DLS joint update per iteration is:
This is equivalent to solving the $3 \times 3$ linear system:
where is always symmetric positive definite (the damping guarantees this), so GaussianElimination<T, 3> solves it reliably.
The updated joint angles are:
Convergence
The loop terminates when:
- (success), or
- The maximum iteration count is reached (failure to converge — target unreachable or tolerance too tight)
Why DLS over Plain Pseudoinverse
At a kinematic singularity (e.g., fully extended arm), becomes rank-deficient. The pseudoinverse would produce infinite joint velocities. The damping term bounds the solution:
The cost is a small positional bias proportional to : the algorithm converges to within approximately rather than exact zero. Choosing balances stability and accuracy for typical robot geometries.
Complexity Analysis
| Case | Time | Space | Notes |
|---|---|---|---|
| Per iteration | FK sweep + Jacobian + $3\times3$ solve | ||
| Total | = iterations (typically 10–50) |
The $3 \times 3O(1)n$.
Step-by-Step Walkthrough
Consider a 2-link planar arm with , , both joints rotating about the Z-axis, target , initial guess , .
Iteration 1:
- FK gives (fully extended along X)
- Error: ,
- Jacobian (Z-axis joints, cross-product form):
- (only Y-row is non-zero for planar X motion)
- — a $3 \times 3$ SPD matrix
- Solve , compute
- Update both joint angles toward a bent configuration
After ~40 iterations converges to joints that produce .
Pitfalls & Edge Cases
- Unreachable targets: If exceeds the total arm length, the algorithm reaches maximum iterations without converging. The returned result has
converged = false; the end-effector will be as close as geometrically possible. - Singularity handling: Near singularities (e.g., fully extended arm), the damping prevents numerical blow-up but introduces a small steady-state error. Reduce for higher accuracy away from singularities.
- Local minima in redundant chains: For (redundant), DLS finds a solution (minimum-norm joint motion) but not necessarily the one with the best posture. Null-space techniques (projecting secondary objectives into ) can improve this.
- Initial guess sensitivity: Starting closer to the expected solution reduces iterations and avoids winding through joint-limit regions. For repeated calls (e.g., tracking), use the previous solution as the initial guess.
- Float-only: Uses
std::cos,std::sin, andstd::sqrt; Q15/Q31 fixed-point types are not supported. - Configuration preconditions:
dampingFactorandtolerancemust both be strictly positive. The damping term ensures is symmetric positive definite only when ; both values are asserted in debug builds viareally_assert.
Variants & Generalizations
- Jacobian Transpose: — no matrix solve, but slower convergence and step-size sensitive. Suitable for very constrained embedded targets.
- Pseudoinverse (Moore-Penrose): DLS with — exact minimum-norm solution but numerically unstable at singularities.
- FABRIK: Forward-And-Backward Reaching IK — purely geometric, position-only, no Jacobian required. Very fast per iteration; preferred when orientation control is not needed.
- Cyclic Coordinate Descent (CCD): Each joint independently minimizes error; simple but produces unnatural motion.
- Full 6-DOF pose IK: Extend to $6 \times ne\mathbb{R}^6$ to control both position and orientation.
Applications
- Robot arm target tracking: Drive the end-effector to follow a moving 3D target in real-time.
- Teleoperation: Map operator hand position to robot joint angles continuously.
- Motion planning: Compute joint-space waypoints from Cartesian-space paths.
- Animation & simulation: Pose limbs in a physically plausible configuration to reach a point of interest.
Connections to Other Algorithms
- Forward Kinematics: Called internally every iteration to compute current end-effector position and joint positions for the Jacobian.
- GaussianElimination: Solves the $3 \times 3Ay = e$ at the core of each iteration.
numerical/math/Geometry3D.hpp: ProvidesCrossProductfor Jacobian column computation,RotationAboutAxisfor accumulated rotation, andVectorNormfor convergence check.
References & Further Reading
- Buss, S.R. (2004). Introduction to Inverse Kinematics with Jacobian Transpose, Pseudoinverse and Damped Least Squares methods. University of California, San Diego. PDF
- Nakamura, Y. and Hanafusa, H. (1986). "Inverse kinematic solutions with singularity robustness for robot manipulator control". Journal of Dynamic Systems, Measurement, and Control, 108(3).
- Siciliano, B. et al. (2009). Robotics: Modelling, Planning and Control. Springer. Chapter 3.
- Craig, J.J. (2005). Introduction to Robotics: Mechanics and Control. 3rd ed. Chapter 4.