Can a neural network learn a robot arm's inverse kinematics (IK) by copying a numerical solver? This repo has the original project (MATLAB Robotics Toolbox + Keras) for two textbook 3-DOF arms, plus a follow-up technical report that checks how well it actually works and what fixes it.
Short answer: the baseline network looks good on paper (74% Keras "accuracy") but its hand lands a median of ~4% of the arm's reach from the target, and misses by more than half the reach on the worst 5% of targets. Most of that error comes from the training labels, not the network. With consistent, exact labels and a sine/cosine output, the same network is 43Γ more accurate at the median and ~200Γ more accurate on the hardest targets. Used as a warm start, it cuts the numerical solver's iterations by 3.5Γ and always returns the intended solution.
π Paper: paper/main.pdf (IEEE two-column) Β· paper/main_long.pdf (10-page extended version)
ποΈ Original project: slides Β· video demo Β· course write-up
| Arm | Joints | Notes |
|---|---|---|
| RRR (anthropomorphic) | base yaw ΞΈβ, shoulder ΞΈβ, elbow ΞΈβ | aβ = aβ = 10 LU, reach 20 LU, up to 4 IK solutions per target |
| RPP (cylindrical) | base yaw ΞΈβ, vertical lift dβ, radial reach dβ | one solution per target, ~200 LU workspace |
Both arms have closed-form IK, which makes them a clean testbed: every network answer can be checked against the exact solution.
offline: random targets βββΊ ikine (LM, β€1000 iters) βββΊ (x,y,z) β (q1,q2,q3) dataset βββΊ Keras MLP βββΊ model/*.h5
online: target [x y z] βββ¬ββΊ ikine βββββββββββββΊ animate()
βββΊ MLP (via Python) βββΊ animate() β compare poses
| Model | Arm | Keras acc. | Median error | p95 error | Within 1 LU |
|---|---|---|---|---|---|
model20000_rrr (test) |
RRR | 74.1% | 0.78 LU | 10.92 LU | 61.6% |
model20000_rrr (train) |
RRR | 97.3% | 0.50 LU | 2.14 LU | 82.5% |
model8000_rpp_rad (test) |
RPP | 99.9% | 2.11 LU | 7.70 LU | β |
Keras's default 'accuracy' only checks which of the three outputs is largest, so it says almost nothing about IK error. One RPP model scores 91.4% while missing by a median of 148 LU.
- Inconsistent labels.
ikinestarts from all-zero joints and picks whichever of the four RRR solutions it converges to, so neighbouring targets get different solution types. The network ends up averaging them. - Unwrapped angles. The solver reports ΞΈ and ΞΈ + 2Ο as different answers.
- Sampling bug. The RPP generator drew
xfrom[0, 2Ο](an angle range), so the training data covers only ~14% of the base rotation.
Controlled study on the RRR arm (same network and inputs, only the labels and output format change):
| Median | p95 | Notes | |
|---|---|---|---|
| Solver labels (baseline) | 1.94 LU | 21.9 LU | p95 exceeds the arm's reach |
| Consistent exact labels, (cos, sin) output | 0.045 LU | 0.11 LU | 43Γ / 199Γ better |
| Same, 30k samples | 0.032 LU | 0.068 LU | 99.1% within 0.1 LU, 42% fewer params |
Starting guess for LM ikine |
Mean iterations | Intended solution |
|---|---|---|
| All zeros (default) | 15.8 | 39.5% |
| Baseline network | 6.2 | 39.7% |
| Improved network | 4.5 | 100% |
.
βββ run_project/ # Ready-to-run demo: MATLAB scripts + trained models
β βββ rrr_3_link_toolbox.m RRR IK with Robotics Toolbox ikine + animation
β βββ rrr_3_link_NN.m RRR IK with the neural network (calls py_rrr.py)
β βββ rpp_toolbox.m RPP IK with ikine + animation
β βββ rpp_NN.m RPP IK with the neural network (calls py_rpp.py)
β βββ py_rrr.py, py_rpp.py Keras inference bridges
β βββ model/ Trained Keras .h5 models
β βββ dataset/ MATLAB β Python exchange files
βββ devlopment_project/ # Data generation, training, all trained checkpoints
β βββ gen.m, gen_rpp.m Build datasets by running ikine on random targets
β βββ train.py Train the Keras MLP
β βββ inferance.py Ad-hoc predictions
β βββ train*.csv Generated datasets
β βββ model/ All 7 trained models
βββ paper/ # Technical report: analysis + improvements
β βββ main.tex, refs.bib LaTeX source (IEEEtran)
β βββ code/ Audit, controlled study, figures, tables (PyTorch/NumPy)
β βββ results/ Raw results (JSON / NPZ) and the improved model
β βββ figures/, tables/ Generated from results/
β βββ README.md Reproduction details
βββ Project_Presentaion.pdf # Original course presentation
βββ VIDEO DEMONSTRATION.mp4 # Demo of both arms animating
Requirements: MATLAB with Peter Corke's Robotics Toolbox, and Python 3 with numpy pandas scikit-learn tensorflow keras on your PATH.
cd run_project
rrr_3_link_toolbox % enter [x y z], e.g. [1 4 9]; the arm animates to the ikine solution
rrr_3_link_NN % same target, solved by the neural network
rpp_toolbox
rpp_NNNo MATLAB or TensorFlow needed: ikcore.py includes a Python replica of ikine and reads the Keras weights straight from the .h5 files.
cd paper
python3 -m venv venv && venv/bin/pip install h5py numpy pandas scipy scikit-learn matplotlib torch
cd code
../venv/bin/python audit.py # Part I: dataset audit + re-evaluation of all shipped models (~30 s)
../venv/bin/python improved.py # Part II: controlled study, scaling, warm start, latency (~45 min on M1 Pro CPU)
../venv/bin/python figures.py && ../venv/bin/python make_tables.py
cd .. && tectonic --keep-intermediates main.texSee paper/README.md for details.
Durgesh S. Reddiyar (dreddiya@asu.edu). Originally built for MAE 547 Modeling and Control of Robots, Arizona State University, Fall 2021.
@techreport{reddiyar2026nnik,
author = {Durgesh S. Reddiyar},
title = {Learning Inverse Kinematics by Imitating a Numerical Solver:
Analysis and Improvements on Two 3-DOF Manipulators},
institution = {Arizona State University},
year = {2026}
}- P. Corke, Robotics, Vision and Control, Springer. Robotics Toolbox for MATLAB.
- B. Siciliano, L. Sciavicco, L. Villani, G. Oriolo, Robotics: Modelling, Planning and Control, Springer, 2009.
- M. I. Jordan and D. E. Rumelhart, "Forward models: Supervised learning with a distal teacher," Cognitive Science, 1992.