Tools › Robot arm
Robot arm: from target to joint angles
A robot is told where the hand should go, but its motors move joints. Inverse kinematics turns the first into the second. Click or drag in the picture to move the target.
What to look for
- Formula versus iteration. For two joints there is an exact answer, drawn as the grey ghost arm. Press “Run” and the arm finds the same pose by repeated small corrections, the way larger robots must.
- Two solutions. A target usually has an “elbow up” and an “elbow down” pose. Iteration finds the one nearest to where it started.
- Out of reach. The dashed circles mark the reach. Outside them the target is red and the arm stretches towards it as far as it can.
- Singularities. With the arm almost stretched or folded, a small joint change moves the hand only sideways. Plain steps then crawl, and damped steps cope better.
- Step size. A small step is slow, a larger one is faster until it starts to overshoot. The plot shows the distance per iteration on a log scale.
The maths
Forward kinematics gives the hand position from the angles: x = L1 cos θ1 + L2 cos(θ1+θ2) and y = L1 sin θ1 + L2 sin(θ1+θ2).
Inverse, closed form: cos θ2 = (x² + y² − L1² − L2²) / (2 L1 L2), so θ2 = ± arccos(…), and θ1 = atan2(y, x) − atan2(L2 sin θ2, L1 + L2 cos θ2). The target is reachable when the cosine lies between −1 and 1.
Iterative: let e be the vector from the hand to the target and J the Jacobian, the matrix that says how the hand moves per joint change. One step is θ ← θ + α Jᵀ e, which is gradient descent on the squared distance. The damped variant uses θ ← θ + α Jᵀ (J Jᵀ + λ² I)⁻¹ e. It stays bounded where J loses rank, at the price of slower progress. The determinant of this arm's Jacobian is L1 L2 sin θ2, which is zero when the arm is stretched or folded.
Why this matters for AI
Learned robot policies replace such formulas with a neural network that maps camera images and a goal to motor commands. The classical solution stays important as a check, as a fallback and as a source of training data. The problems seen here, several solutions, unreachable goals and singular poses, are also the places where a learned policy has to behave sensibly.
This is a flat arm with two joints, no limits, no obstacles and no dynamics such as mass, inertia or motor limits. Real arms have six or seven joints, joint limits and collisions to consider.