Skip to main content

Inverse Kinematics: Jacobians & Numerical Solvers

Harddifficulty

Readiness and prerequisite recap

Read Inverse Kinematics first. This lesson uses the two-link forward equations from there, plus derivatives (rates of change) and multiplying a matrix by a vector. The arm demo below is the same geometric solver as before, as a reminder; the step-by-step method is worked out in the text.

The two-link solution is neat because everything fits in one triangle. Real mechanisms are often messier: there's a wrist, an offset linkage, a turret that rotates everything, or a slide that changes a link's length. Once the geometry gets that complicated, it's easier to ask a smaller question: if I nudge each joint a tiny bit, which way does the claw move? The answer to that is a table of numbers called the Jacobian.

Where Jacobians fit among IK algorithms​

The Quality Control workshop groups IK methods by how much structure the mechanism has:

MethodBest whenCore idea
Closed-form trigonometryThe mechanism has about the same freedoms as the target, like a two-link arm reaching (x,y)(x, y).Break links into vector components and solve the equations directly.
FABRIKYou have a chain of links and want a geometric, constraint-friendly approximation.Move the end to the target, then sweep backward and forward while preserving link lengths.
Cyclic coordinate descentYou can adjust one joint at a time and want a simple iterative solve.Rotate each joint so the end effector points closer to the target, then repeat.
Jacobian transpose / pseudoinverseYou want a general local solver that also connects to control theory.Use derivatives to turn a small end-effector error into small joint corrections.

FABRIK (Forward And Backward Reaching Inverse Kinematics) is popular in graphics because it's easy to picture: pull the end of the chain to the target, rebuild the chain back toward the base, then back out again. CCD rotates one joint at a time.

Step-by-step methods need a rule for choosing between answers. If many poses reach the same target, the solver can jump between them or curl into something awkward unless you add constraints: joint limits, a fixed wrist angle, "keep the claw level," "prefer elbow up," or "stay close to the last pose." A virtual four-bar linkage is a hardware version of that: it removes a degree of freedom so the end stays level.

Same arm, different approach​

The demo jumps straight to the exact two-link answer. A step-by-step solver would instead start from the current pose, see how far off the claw is, use the Jacobian to estimate a small correction to the angles, move a little, and repeat.

Live demoInverse kinematics - drag the claw target
+x+ytarget
x: 14.0 uy: 11.5 ur: 18.1 utheta1: 71 degtheta2: -73 degreachable: yes
shoulder linkelbow linkdesired claw positionreachable workspace

The Jacobian is a sensitivity matrix​

For the same two-link arm, forward kinematics gives:

x=L1cos⁡(θ1)+L2cos⁡(θ1+θ2)y=L1sin⁡(θ1)+L2sin⁡(θ1+θ2)\begin{aligned} x &= L_1\cos(\theta_1) + L_2\cos(\theta_1 + \theta_2) \\ y &= L_1\sin(\theta_1) + L_2\sin(\theta_1 + \theta_2) \end{aligned}

Now ask: if only θ1\theta_1 changes a tiny bit, how fast do xx and yy change? And the same for θ2\theta_2. Each of those rates is a partial derivative, the rate of change when one input moves and the others stay put. The Jacobian is the table of all four:

J(θ1,θ2)=[∂x∂θ1∂x∂θ2∂y∂θ1∂y∂θ2]J(\theta_1,\theta_2) = \begin{bmatrix} \dfrac{\partial x}{\partial \theta_1} & \dfrac{\partial x}{\partial \theta_2} \\[8pt] \dfrac{\partial y}{\partial \theta_1} & \dfrac{\partial y}{\partial \theta_2} \end{bmatrix}

Rows are directions the claw can move, and columns are joints. Differentiating the two forward equations gives, for this arm:

J=[−L1sin⁡(θ1)−L2sin⁡(θ1+θ2)−L2sin⁡(θ1+θ2)−L1cos⁡(θ1)+L2cos⁡(θ1+θ2)−L2cos⁡(θ1+θ2)]\boxed{ J = \begin{bmatrix} -L_1\sin(\theta_1) - L_2\sin(\theta_1 + \theta_2) & -L_2\sin(\theta_1 + \theta_2) \\[6pt] \phantom{-}L_1\cos(\theta_1) + L_2\cos(\theta_1 + \theta_2) & \phantom{-}L_2\cos(\theta_1 + \theta_2) \end{bmatrix} }

Each column is an experiment: the first says how the claw moves if only the shoulder turns a little, the second if only the elbow does. For small moves:

Δx≈J Δθ\Delta \mathbf{x} \approx J\,\Delta\boldsymbol{\theta}

Δx\Delta\mathbf{x} is a small change in claw position and Δθ\Delta\boldsymbol{\theta} the small change in joint angles that causes it. The ≈\approx matters: it only holds for small steps, and JJ has to be worked out again at each new pose.

One numerical correction​

Let L1=L2=1L_1=L_2=1, (θ1,θ2)=(0,π/2)(\theta_1,\theta_2)=(0,\pi/2), and the current claw position be (1,1)(1,1). For a nearby target (0.9,1.1)(0.9,1.1), the desired task-space change is Δx=[−0.1, 0.1]T\Delta\mathbf{x}=[-0.1,\ 0.1]^T. At that pose,

J=[−1−110],J−1=[01−1−1],Δθ=J−1Δx=[0.10] rad.J=\begin{bmatrix}-1&-1\\1&0\end{bmatrix},\qquad J^{-1}=\begin{bmatrix}0&1\\-1&-1\end{bmatrix},\qquad \Delta\boldsymbol{\theta}=J^{-1}\Delta\mathbf{x} =\begin{bmatrix}0.1\\0\end{bmatrix}\ \text{rad}.

So one small step raises the shoulder by about 0.1 rad and leaves the elbow alone. That makes sense if you picture it: the arm goes right along the first link and straight up along the second, and rotating the whole thing slightly counter-clockwise moves the claw left and up. After moving, recompute JJ and repeat.

The same table relates speeds, too. Going from joint speeds to claw speed is easy:

x˙=J θ˙\dot{\mathbf{x}} = J\,\dot{\boldsymbol{\theta}}

Inverse velocity kinematics asks for the reverse:

θ˙=J−1x˙\dot{\boldsymbol{\theta}} = J^{-1}\dot{\mathbf{x}}

when JJ is square and has an inverse. It's the same idea as mecanum mixing: a desired motion goes in, motor commands come out.

What if the matrix cannot be inverted?​

When the arm is almost straight or almost folded, the claw can't easily move in one direction, and J−1J^{-1} blows up or doesn't exist. These poses are called singularities, and near them the solver asks for huge joint changes to make tiny claw movements. The usual fix is to add damping:

Δθ=JT(JJT+λ2I)−1Δx\Delta\boldsymbol{\theta} = J^T\left(JJ^T + \lambda^2 I\right)^{-1}\Delta\mathbf{x}

JTJ^T is the transpose (rows and columns swapped), II is the identity matrix, and λ\lambda is a damping constant. Adding λ2\lambda^2 keeps the matrix invertible even at a singularity. The correction comes out slightly less accurate but never enormous, and a larger λ\lambda is safer but slower. With λ=0\lambda = 0 and an invertible JJ, it's the same as J−1J^{-1}. This is called damped least squares.

Jacobian transpose: the gradient-descent view​

An even simpler option skips the inverse entirely and nudges the joints in whichever direction reduces the error fastest:

Δθ=αJTe\Delta\boldsymbol{\theta} = \alpha J^T\mathbf{e}

e\mathbf{e} is the claw error (target minus current) and α\alpha is a small step size. This is a kind of gradient descent. It's less exact than the damped version and takes more steps, but it never blows up, and it's simple enough to run every loop on a slow mechanism.

Numerical IK loop​

Each loop:

  1. Compute the current claw position with forward kinematics.
  2. Compute the error e=xtarget−xcurrent\mathbf{e} = \mathbf{x}_{target} - \mathbf{x}_{current}.
  3. Compute the Jacobian at the current angles.
  4. Solve for a small correction Δθ\Delta\boldsymbol{\theta}.
  5. Add the correction to the joint targets.
  6. Clamp joint limits and repeat next loop.

It's a control loop, just working on geometry instead of motor speed.

A practical numerical IK skeleton​

This only computes the angle correction. Your subsystem still handles encoder offsets, feedforward, limits, and motor commands.

Damped least-squares IK step
// One small joint delta from the current angles toward a target wrist
// position. Returns null for a degenerate step; commands no motors.
double[] step(double theta1, double theta2, double targetX, double targetY) {
double x = link1 * Math.cos(theta1) + link2 * Math.cos(theta1 + theta2);
double y = link1 * Math.sin(theta1) + link2 * Math.sin(theta1 + theta2);

double errorX = targetX - x;
double errorY = targetY - y;

double j00 = -link1 * Math.sin(theta1) - link2 * Math.sin(theta1 + theta2);
double j01 = -link2 * Math.sin(theta1 + theta2);
double j10 = link1 * Math.cos(theta1) + link2 * Math.cos(theta1 + theta2);
double j11 = link2 * Math.cos(theta1 + theta2);

double a00 = j00 * j00 + j01 * j01 + LAMBDA * LAMBDA;
double a01 = j00 * j10 + j01 * j11;
double a10 = a01; // A is symmetric
double a11 = j10 * j10 + j11 * j11 + LAMBDA * LAMBDA;

double det = a00 * a11 - a01 * a10;
if (Math.abs(det) < EPS) return null; // try again next loop

double w0 = ( a11 * errorX - a01 * errorY) / det;
double w1 = (-a10 * errorX + a00 * errorY) / det;

return new double[] {
clamp(j00 * w0 + j10 * w1, -MAX_STEP, MAX_STEP),
clamp(j01 * w0 + j11 * w1, -MAX_STEP, MAX_STEP),
};
}

The first two lines are forward kinematics, j00 through j11 are the Jacobian, the a values are JJ⊤+λ2IJJ^\top + \lambda^2 I, and the last lines solve Aw=eAw = e and return Δθ=J⊤w\Delta\theta = J^\top w.

ExerciseDerive the four Jacobian entries

Differentiate the two forward-kinematics equations: xx with respect to θ1\theta_1 and then θ2\theta_2, and the same for yy. Check your answers against j00 to j11.

ExerciseWhat LAMBDA is protecting

Without LAMBDA, the code would invert JJ⊤JJ^\top directly. What is its determinant for a fully extended arm, and what size step would a plain inverse ask for?

Show solution

Fully extended, both links point the same way, so the two columns of the Jacobian are parallel and the determinant of JJ⊤JJ^\top is zero. A plain inverse divides by it, so the solver asks for an enormous joint step to chase a direction the arm can't move in. Adding λ2\lambda^2 keeps the matrix invertible, trading a slightly wrong direction for a step that stays a reasonable size.

ExerciseWhat MAX_STEP is for

This is one step of a loop that runs every cycle, so it doesn't have to get there this loop. What could a single unlimited step do to a real arm?

Show solution

Near a singularity, or with a target out of reach, the step can come out as several radians. Sent as a joint target in one loop, that's the arm trying to swing its whole range instantly, into a hard stop, the robot, or whatever's in front of it. Limiting the step means it gets there over tens of loops, which at 50 Hz is still well under a second.

In FTC this is useful when the mechanism has more going on than the two-link formula covers:

  • a turret plus an arm, where the turret chooses the plane and the arm solves within that plane;
  • an arm plus slides, where extension changes the reachable workspace;
  • a wrist that must preserve end-effector angle while the shoulder and elbow move;
  • a linkage whose exact geometry is easier to evaluate with forward kinematics than to solve by hand.
It can chase noise

The solver is only as good as the measured joint angles. Backlash, flex, and loose chain make the computed claw position wiggle. Use damping, step limits, and a reasonable tolerance so the loop doesn't keep sending big corrections into a floppy mechanism.

Use the geometric solution when you can

For a simple two-link arm, use the geometric solution from Inverse Kinematics. Use Jacobians when the mechanism is too complicated to solve cleanly with geometry.

Sources & references
  • Kevin Lynch and Frank Park, Modern Robotics - standard open robotics text for Jacobians, velocity kinematics, singularities, and numerical IK.
  • 21229 Quality Control, The Basics of Inverse Kinematics in Robotics - FTC workshop discussion of degree-of-freedom analysis, FABRIK, CCD, constraints, and Jacobian transpose.
  • WPILib, Kinematics and Odometry
    • drivetrain kinematics as the mobile-robot version of task-space to actuator-space mapping.
  • Tyler Veness, Controls Engineering in FRC
    • competitive-robotics controls context for applying math carefully on hardware.