Inverse Kinematics: Jacobians & Numerical Solvers
Harddifficulty
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:
| Method | Best when | Core idea |
|---|---|---|
| Closed-form trigonometry | The mechanism has about the same freedoms as the target, like a two-link arm reaching . | Break links into vector components and solve the equations directly. |
| FABRIK | You 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 descent | You 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 / pseudoinverse | You 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.
The Jacobian is a sensitivity matrix
For the same two-link arm, forward kinematics gives:
Now ask: if only changes a tiny bit, how fast do and change? And the same for . 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:
Rows are directions the claw can move, and columns are joints. Differentiating the two forward equations gives, for this arm:
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:
is a small change in claw position and the small change in joint angles that causes it. The matters: it only holds for small steps, and has to be worked out again at each new pose.
One numerical correction
Let , , and the current claw position be . For a nearby target , the desired task-space change is . At that pose,
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 and repeat.
The same table relates speeds, too. Going from joint speeds to claw speed is easy:
Inverse velocity kinematics asks for the reverse:
when 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 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:
is the transpose (rows and columns swapped), is the identity matrix, and is a damping constant. Adding keeps the matrix invertible even at a singularity. The correction comes out slightly less accurate but never enormous, and a larger is safer but slower. With and an invertible , it's the same as . 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:
is the claw error (target minus current) and 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:
- Compute the current claw position with forward kinematics.
- Compute the error .
- Compute the Jacobian at the current angles.
- Solve for a small correction .
- Add the correction to the joint targets.
- 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.
// 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
, and the last lines solve and return .
Differentiate the two forward-kinematics equations: with respect to and then , and
the same for . Check your answers against j00 to j11.
Without Fully extended, both links point the same way, so the two columns of the Jacobian are parallel and the
determinant of 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 keeps the matrix invertible, trading
a slightly wrong direction for a step that stays a reasonable size.LAMBDA, the code would invert directly. What is its determinant for a fully
extended arm, and what size step would a plain inverse ask for?Show solution
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? 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.Show solution
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.
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.
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.
- 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.