Analytic vs Learned Inverse Kinematics
Compare exact inverse kinematics with a frozen 388-parameter neural network. The analytic solution reaches every reachable target exactly, while the network typically misses by around 7–10 mm and becomes less accurate near full extension.
Overview
Drag the target on the command pad at the left. The grey arm uses the law of cosines to calculate its joint angles and reaches every reachable target exactly. The amber arm uses the weights generated by a 2-16-16-4 tanh neural network, with a typical error around 7–10 mm, but accuracy drops near full extension: beyond , one target in twenty has an error of at least 27 mm.
Task
Both methods solve the same inverse-kinematics problem: a planar two-link arm with unit-length links () must reach a commanded target.
- Workspace: The reachable workspace is a disk of radius 2. Targets beyond the boundary are clamped to the rim for the analytic solution. The network receives the original target and must extrapolate beyond its training domain.
- Branch: Both methods use the elbow-down configuration, with . A target can correspond to more than one joint configuration. Training on both branches without accounting for this ambiguity can cause a network to predict an average that corresponds to neither valid solution.
- Score: The error is the distance between the end effector and the commanded target, reported in millimeters using 300 mm per unit. The analytic solution has zero error for reachable targets, apart from numerical precision. The network’s error is measured in the simulation.
If you leave it untouched for a second, the target resumes its automatic sweep from the interior toward the edge of the workspace. The animation starts when the widget scrolls into view and pauses when the user first interacts with it.
How It Works
In each frame, both methods calculate a joint configuration for the same target.
-
Solve analytically. The law of cosines gives the elbow angle. Let :
The shoulder angle is then
Targets beyond the arm’s reach are clamped to the boundary. The origin is handled separately because the target direction is undefined there.
-
Run the network. The target is normalized by the arm’s maximum reach, passed through a 2-16-16-4 tanh network, and decoded into two joint angles. Each angle is represented by a pair of outputs corresponding to its cosine and sine, then recovered with
atan2. The network makes a single forward pass: it receives no target-specific labels and performs no iterative refinement. -
Animate the result. Both arms move smoothly toward their calculated poses using angle interpolation that accounts for wraparound. This makes it easier to compare their motion without confusing the animation with the underlying calculation.
The network contains 388 parameters and was trained to imitate the analytic solution using 48,000 samples drawn uniformly in joint space, with random seed 7 and the elbow-down branch fixed. Training used an Adam warmup followed by full-batch L-BFGS optimization. The deployed model, arm-ik-nn/1, performs only forward inference, and the training code lives in elbow-grease.
On 12,000 held-out targets, the saved model produced these results:
| Test region | RMSE | Median error | 95th-percentile error |
|---|---|---|---|
| Interior | 10.0 mm | 8.0 mm | 17.9 mm |
| Near the rim | 9.8 mm | 6.7 mm | 19.9 mm |
| Near full extension | 12.6 mm | 7.1 mm | 27.2 mm |
Where the Network Struggles
The main difficulty appears near full extension, where the two-link arm approaches a singular configuration. In this region, small changes in the target can require large changes in the joint angles. The inverse mapping becomes increasingly sensitive, making it harder for a smooth, finite neural network to approximate accurately.
The median error remains around 7–8 mm across the test regions, but the 95th-percentile error rises to 27.2 mm near full extension. In other words, typical predictions remain reasonably accurate while the worst predictions become less reliable near the workspace boundary.
The analytic method does not have this approximation error because it evaluates the inverse-kinematics equations directly rather than learning an approximation to them. The comparison shows both what the network can reproduce and where its accuracy begins to deteriorate.
Widget Details
| Component | Implementation |
|---|---|
| Arm model | Planar two-link arm, unit-length links, elbow-down configuration, workspace radius 2 |
| Units | 1 model unit = 300 mm |
| Analytic method | Law-of-cosines inverse kinematics, boundary clamping, special handling at the origin |
| Neural network | 2-16-16-4 tanh MLP with unit-circle angle outputs; frozen snapshot arm-ik-nn/1 |
| Rendering | Three equal Canvas 2D sections: one command pad and one display for each method |
| Visual feedback | Workspace rings, fading motion trails, and a separate error readout for each arm |
| Representative results | Learned model: 8.0 mm interior median and 27.2 mm near-singular 95th percentile; analytic solution: zero error for reachable targets, up to numerical precision |
References
- Craig, John J. 2005. Introduction to Robotics: Mechanics and Control. 3rd ed. Pearson.
- Hornik, Kurt, Maxwell Stinchcombe, and Halbert White. 1989. “Multilayer Feedforward Networks Are Universal Approximators.” Neural Networks 2 (5): 359–366. https://doi.org/10.1016/0893-6080(89)90020-8
- Kingma, Diederik P., and Jimmy Ba. 2015. “Adam: A Method for Stochastic Optimization.” arXiv. https://doi.org/10.48550/arXiv.1412.6980
- Nocedal, Jorge, and Stephen J. Wright. 2006. Numerical Optimization. 2nd ed. Springer.