Forward Kinematics and the Denavit-Hartenberg Convention
What You'll Learn
- 1Assign the four Denavit-Hartenberg parameters to any serial chain using the axis intersection rules
- 2Write the 4x4 transform matrix that each joint contributes
- 3Multiply the joint transforms to obtain tool position and orientation
- 4Compare the Denavit-Hartenberg chain with the product of exponentials form
Forward kinematics answers one question: given the joint angles the encoders report, where is the tool and how is it pointed? Without that map a controller cannot verify a target, and one wrong link length silently shifts every pick. This lesson sets the four Denavit-Hartenberg parameters, builds the per-joint matrix, and multiplies a complete chain for a 2R and a 3R arm.
Theory and Foundations
A serial arm is described by a chain of frames, one per link, and the Denavit-Hartenberg convention fixes where those frames go so that each transform uses only four numbers. The rules are geometric: the z axis lies along the joint axis, the x axis lies along the common normal between consecutive z axes, and the four parameters measure one distance and three angles between them.
Assumptions matter here: links are rigid, joint axes are straight and perfectly located, clearances are absorbed by calibration, and backlash is small compared with the tolerance you must hold. Under those assumptions every joint contributes one matrix whose entries mix its own variable with its three fixed parameters.
For a revolute joint moves while is fixed; for a prismatic joint moves while stays constant. Every other entry is a constant of the link, so the controller only ever refreshes one column of trigonometry per joint.
The tool pose is the product of the chain, written with frames cancelled left to right so no index can be dropped.
For a planar arm with all joint axes parallel to z, the chain collapses to familiar trigonometry: each link adds its projection rotated by the accumulated angle.
The reachable radius from the origin follows from the law of cosines, which is the quickest check that a target is inside the workspace before any matrix is multiplied.
An equivalent formulation avoids frame assignment entirely. The product of exponentials writes the tool pose as a product of matrix exponentials of screw twists, one per joint, followed by the zero-angle pose.
Each twist comes from the joint axis and a point on it, and is the tool pose at zero angles. Both methods give identical numbers: the parameter table is easier to read, the exponential form easier to differentiate and calibrate.
Key Formulas
Worked Examples
| i | a_i (m) | alpha_i (deg) | d_i (m) | theta_i (deg) |
|---|---|---|---|---|
| 1 | 0.35 | 0 | 0 | variable |
| 2 | 0.25 | 0 | 0 | variable |
| 3 | 0.15 | 0 | 0 | variable |
| 4 (tool) | 0.10 | 0 | 0 | 0 |
Real-World Examples
- Six-axis arms - A typical articulated wrist carries three intersecting axes, which lets three short offsets collapse the wrist into a single point and keeps the parameter table at six rows.
- Product of exponentials in research - The exponential form is the default in modern kinematics libraries because it needs no frame assignment, so a mislabeled frame cannot corrupt the model.
- Calibration residuals - Measured link lengths often differ from nominal by 0.1 to 0.5 mm, and fitting those offsets is what separates a 0.5 mm repeatability arm from a 0.1 mm accuracy arm.
- SCARA arms - Four parallel axes reduce the chain to two planar terms plus a height and a roll, which is why SCARA kinematics fit in a few lines of controller code.
đĄCheck the zero configuration first
Assembling the Chain in Python
The parameter table becomes executable the moment each row turns into one matrix and the product is taken in index order. Keep the argument order fixed and documented, since swapping the link length with the offset is the commonest table-to-code translation error, and let the product accumulate row by row instead of building all four matrices first. With every twist zero the result stays a planar rotation plus a translation, which is the quick check that the assignment did not mix standard and modified conventions.
import math
def dh_transform(a, alpha_deg, d, theta_deg):
al, th = math.radians(alpha_deg), math.radians(theta_deg)
ca, sa, ct, st = math.cos(al), math.sin(al), math.cos(th), math.sin(th)
return [[ct, -st * ca, st * sa, a * ct],
[st, ct * ca, -ct * sa, a * st],
[0.0, sa, ca, d],
[0.0, 0.0, 0.0, 1.0]]
def matmul(A, B):
return [[sum(A[i][k] * B[k][j] for k in range(4)) for j in range(4)]
for i in range(4)]
rows = [(0.35, 0, 0, 30), (0.25, 0, 0, -45),
(0.15, 0, 0, 20), (0.10, 0, 0, 0)]
T = [[1.0 if i == j else 0.0 for j in range(4)] for i in range(4)]
for a, al, d, th in rows:
T = matmul(T, dh_transform(a, al, d, th))
print(round(T[0][3], 3), round(T[1][3], 3), round(T[0][0], 4))
# 0.794 0.132 0.9962
Walking the Chain in a C++ Loop
A controller does not rebuild four 4x4 blocks every cycle; it keeps the link lengths, accumulates one joint angle per joint, and adds each projection as it goes. The same loop hosts the reach check, because a radius from the law of cosines costs one square root and settles in a single line whether the target lies inside the annulus before any matrix work runs. Watch the units at this boundary: configuration tools display degrees while the servo loop works in radians, and one unchecked conversion shows up as a mirrored workspace rather than a small offset.
#include <cmath>
#include <cstdio>
struct Tool { double x, y, phi; };
Tool planar_fk(const double* L, const double* theta, int n) {
Tool t{0.0, 0.0, 0.0};
for (int i = 0; i < n; ++i) {
t.phi += theta[i]; // accumulated angle
t.x += L[i] * std::cos(t.phi);
t.y += L[i] * std::sin(t.phi);
}
return t;
}
int main() {
const double pi = 3.14159265358979323846;
const double L[] = {0.35, 0.25, 0.15, 0.10};
const double deg[] = {30.0, -45.0, 20.0, 0.0};
double theta[4];
for (int i = 0; i < 4; ++i) theta[i] = deg[i] * pi / 180.0;
Tool t = planar_fk(L, theta, 4);
std::printf("x=%.3f y=%.3f phi=%.1f deg\n", t.x, t.y, t.phi * 180.0 / pi);
return 0;
}
Common Mistakes
Mixing standard and modified Denavit-Hartenberg conventions
Fix: Standard uses a i and alpha i for joint i, modified shifts them one index back; pick one and label the table header.
Reversing the multiplication order
Fix: Cancel adjacent frame labels: 0 T 1 times 1 T 2 leaves 0 T 2, so the base index always stays on the left.
Feeding degrees into radian-only code
Fix: Convert before the matrix is built, and keep one unit policy through the whole controller.
Key Takeaways
- Four parameters per joint, one 4x4 matrix, and a product left to right gives the tool pose.
- For a planar nR arm the position is the sum of link projections at accumulated angles and phi is the sum of joint angles.
- Radius check with the law of cosines, r = sqrt of L1 squared plus L2 squared plus 2 L1 L2 cos theta 2, confirms reach before computing.
- The product of exponentials gives the same numbers without frame assignment, which removes a whole class of modeling errors.
Frequently Asked Questions
Which Denavit-Hartenberg convention should I use?
Either, but state it. The standard convention attaches and to joint i, while the modified convention used by Craig shifts them back one index; mixing them produces a model that is wrong by one link offset everywhere.
Why do three wrist axes usually intersect?
Because an intersecting triplet has no common normal length, three of the four parameters vanish, which decouples orientation from position and lets the controller solve the wrist angles separately from the arm angles.
How accurate is forward kinematics in practice?
Exact for the model, limited by the model: link length and axis errors of 0.2 mm and 0.05 deg typically produce 0.3 to 0.5 mm of tool error, which is why warm-up and calibration matter as much as encoder resolution.
Interview Questions
Q1: How many parameters does each joint need and why?
Four: a, alpha, d and theta. They measure one length and three angles between consecutive joint axes, which is enough to fix any two-axis pair.
Q2: What does the product of exponentials buy you over a parameter table?
No frame assignment is required, so indexing errors disappear and the same expression differentiates directly for velocity and Jacobian work.