Skip to the content
FixTheRobot Explore Robotics / Manipulator Basics / Theory / 07

Manipulator Basics · Theory · Module 07 of 14

07 — Inverse Kinematics

Inverse kinematics finds the joint values that put the tool at a desired pose. Solve the 2R arm exactly by geometry and algebra, meet the elbow-up and elbow-down branches, and then iterate with the Jacobian, learning why damped least squares is the method of choice near singularities.

  • Intermediate
  • About 7 minutes to read
  • 1 linked lab

Most tasks are specified where the tool must be, not what the joints must do. IK bridges the two, and unlike FK it can fail, return several answers or need a good starting guess.

Learning objectives

After this module you should be able to:

  • Derive the closed-form IK of a planar 2R arm geometrically and algebraically, including both branches.
  • Decide whether a target is reachable and what joint limits do to the solution set.
  • Solve 3R planar IK by wrist-point decoupling.
  • Explain and compare Jacobian-pseudoinverse, Jacobian-transpose and damped least-squares IK.
  • Recognise non-convergence, local minima and singularities, and choose among multiple solutions.

Conceptual explanation

Given a desired tool pose xdx_d, IK seeks qq with f(q)=xdf(q) = x_d. The answer depends on the target and the robot:

  • No solution: the target is outside the workspace, or reachable only with joints beyond their limits.
  • Finitely many: a 2R arm usually has two (elbow up and elbow down); a general 6-DOF arm can have up to 16, and a typical industrial arm with a spherical wrist up to 8.
  • Infinitely many: on certain singular targets, or for a redundant arm with more joints than task constraints.

Analytic versus numerical

Analytic (closed-form) IK gives every solution exactly and fast, by geometry or algebra. It exists only for special designs, such as planar arms or 6-DOF arms with a spherical wrist (Pieper's condition). Numerical IK starts from a guess and walks downhill on the pose error using the Jacobian. It works for any arm, but finds one solution near the guess, may stop at a local minimum, and needs care near singularities.

Decoupling

Many arms split into a positioning part and an orienting part. For a planar 3R arm with a required heading ϕ\phi, the wrist point is fixed by the target, so the first two joints solve a 2R problem and the last joint makes up the heading. For a 6-DOF arm with a spherical wrist, joints 1–3 place the wrist centre and joints 4–6 set the orientation.

Choosing among solutions

Controllers pick the solution closest to the current configuration (to avoid big joint swings), the one inside joint limits with the most margin, or one on a requested branch (for example "elbow up, wrist not flipped") so that a program behaves the same every time. Practise in Lab 05.

Mathematical formulation

Planar 2R, algebraic: squaring and adding the FK equations eliminates q1q_1:

  1. x2+y2=L12+L22+2L1L2cos⁡q2  ⇒  c2=x2+y2−L12−L222L1L2x^2 + y^2 = L_1^2 + L_2^2 + 2L_1L_2\cos q_2 \;\Rightarrow\; c_2 = \dfrac{x^2 + y^2 - L_1^2 - L_2^2}{2L_1L_2}

    Reachable only if |c₂| ≤ 1, i.e. |L₁ − L₂| ≤ r ≤ L₁ + L₂.

  2. q2=atan2⁡ ⁣(±1−c22,  c2)q_2 = \operatorname{atan2}\!\left(\pm\sqrt{1 - c_2^2},\; c_2\right)

    The sign picks the branch. Use atan2 rather than arccos, so the angle lands in the right quadrant.

  3. q1=atan2⁡(y,x)−atan2⁡(L2sin⁡q2,  L1+L2cos⁡q2)q_1 = \operatorname{atan2}(y, x) - \operatorname{atan2}(L_2 \sin q_2,\; L_1 + L_2\cos q_2)

    Geometrically: the direction to the target minus the angle the forearm adds at the shoulder.

Numerical IK: with task error e=xd−f(q)e = x_d - f(q), each iteration updates q←q+Δqq \leftarrow q + \Delta q with one of

Numerical IK updates
Δq=J+e  (pseudoinverse),Δq=αJTe  (transpose),Δq=JT(JJT+λ2I)−1e  (DLS)\Delta q = J^{+} e \ \ (\text{pseudoinverse}), \qquad \Delta q = \alpha J^{T} e \ \ (\text{transpose}), \qquad \Delta q = J^{T}(JJ^{T} + \lambda^{2} I)^{-1} e \ \ (\text{DLS})

DLS minimises ∥JΔq−e∥2+λ2∥Δq∥2\|J\Delta q - e\|^2 + \lambda^2\|\Delta q\|^2. In terms of the singular values σi\sigma_i of JJ, the pseudoinverse scales each direction by 1/σi1/\sigma_i, which blows up as σi→0\sigma_i \to 0. DLS scales it by σi/(σi2+λ2)\sigma_i/(\sigma_i^2 + \lambda^2), which stays bounded by 1/(2λ)1/(2\lambda):

Why DLS is robust near singularities
J+=∑i1σiviuiT,JDLS=∑iσiσi2+λ2viuiTJ^{+} = \sum_i \frac{1}{\sigma_i} v_i u_i^{T}, \qquad J^{\text{DLS}} = \sum_i \frac{\sigma_i}{\sigma_i^{2} + \lambda^{2}} v_i u_i^{T}

Diagrams

Two inverse kinematics solutionsFor the target (0.5, 0.3) m both elbow configurations put the tool on the target; the target lies inside the reachable ring between |L1 − L2| and L1 + L2.outer reach L₁ + L₂|L₁ − L₂|elbow up: q = (59.5°, -68.0°)elbow down: q = (2.5°, 68.0°)target (0.5, 0.3)
Both analytic solutions of Example 1, drawn to scale from the engine's output. Outside the outer circle or inside the inner one there is no solution; on either circle the two branches merge into one.

Worked examples

Example 1: analytic 2R IK

Links L1=0.40L_1 = 0.40, L2=0.30L_2 = 0.30 m; target (0.5,0.3)(0.5, 0.3) m, at distance r=0.583r = 0.583 m, inside the ring [0.10,0.70][0.10, 0.70].

c2=0.52+0.32−0.42−0.322⋅0.4⋅0.3=0.3750,q2=±67.98°c_2 = \frac{0.5^2 + 0.3^2 - 0.4^2 - 0.3^2}{2 \cdot 0.4 \cdot 0.3} = 0.3750, \qquad q_2 = \pm 67.98°
The two exact solutions. FK maps both to the target.
Branchq₁q₂
elbow up59.45°-67.98°
elbow down2.48°67.98°

Example 2: numerical IK from a nearly straight arm

The same target, starting from q0=(0.57°,0.57°)q_0 = (0.57°, 0.57°), close to the stretched singular pose:

All three find the elbow-down solution near the start; the transpose method needs several times more iterations.
MethodConvergedIterationsFinal position errorSolution
pseudoinverseyes80.000 mm(2.48°, 67.98°)
damped least squares (λ = 0.05)yes70.008 mm(2.48°, 67.98°)
transpose (optimal step)yes280.062 mm(2.49°, 67.96°)

Each method returned the elbow-down branch, the one nearest the start. Numerical IK does not choose a branch for you; the initial guess does.

Example 3: one step near a singularity

At q=(0°,2°)q = (0°, 2°) the arm is almost straight and one singular value of JJ is tiny. For a 14 mm error e=(0.01,0.01)e = (0.01, 0.01) m, the pseudoinverse step is ∥Δq∥=1.85\|\Delta q\| = 1.85 rad (106°): a wild jump. The DLS step with λ=0.05\lambda = 0.05 is 0.0260.026 rad. Real solvers also cap the step size, as the engine does.

Example 4: an unreachable target

The target (0.8,0.2)(0.8, 0.2) m is 0.825 m away, beyond the 0.70 m reach. DLS stops with ∥e∥=124.7\|e\| = 124.7 mm and reports: "stalled: the error stopped decreasing (target unreachable or a singular configuration)". The arm ends almost straight and pointing at the target, which is the closest it can get. A good IK routine reports failure honestly instead of returning that pose as a solution.

Example 5: planar 3R with a heading, and a 6-DOF arm

For the 3R arm (0.40, 0.30, 0.15 m) the target (0.5,0.3)(0.5, 0.3) with heading 0° puts the wrist at (0.350,0.300)(0.350, 0.300). The two solutions are (80.6°, −99.0°, 18.4°)(80.6°,\ -99.0°,\ 18.4°) and (0.6°, 99.0°, −99.6°)(0.6°,\ 99.0°,\ -99.6°).

For the 6-DOF arm, numerical IK from 40 random starts found 6 distinct solutions for the pose of Module 06, Example 4:

Distinct 6-DOF IK solutions for one tool pose: shoulder left/right, elbow up/down and wrist flip.
#q₁q₂q₃q₄q₅q₆
130°60°-60°0°-45°0°
2-150°120°60°180°-45°0°
330°0°60°0°-105°0°
430°60°-60°-180°45°-180°
5-150°120°60°0°45°180°
630°0°60°-180°105°180°

Interactive experiment

Interactive 2R inverse kinematics (needs JavaScript).

Drag the target. Watch the two branches, the reach ring, and what happens on its edges and outside it.

Real-world applications

  • Cartesian moves (linear moves of the tool) solve IK at every interpolation point.
  • Teleoperation and jogging use the velocity form (q˙=JDLSx˙\dot q = J^{\text{DLS}}\dot x) to follow hand-controller motion smoothly.
  • Pick and place converts a grasp pose computed from vision into joint targets (see the capstone).
  • MoveIt 2 uses kinematics plugins: numerical (KDL, TRAC-IK) or analytic (IKFast) solvers behind one interface.

Common mistakes

Using arccos instead of atan2

arccos only returns 0…180° and loses the branch sign; atan2 of sine and cosine gives the correct quadrant.

Accepting the last iterate as a solution

Always check the final error against a tolerance. An iteration limit or a stall is a failure.

Ignoring joint limits after solving

An exact analytic solution may violate limits. Check each candidate and discard or wrap angles as the joint allows.

Plain pseudoinverse near singularities

Near σ → 0, J⁺ produces huge joint steps. Use DLS (or SVD with a cut-off) and limit the step size.

Jumping between branches during a path

Solving each point independently can switch elbow up and elbow down mid-move. Seed each solve with the previous solution.

Key takeaways

  1. IK can have none, one, several or infinitely many solutions.
  2. Closed-form 2R IK: cos q₂ from the distance, the branch from the sign of sin q₂, then q₁ from the geometry.
  3. Numerical IK iterates with J⁺, Jᵀ or DLS from an initial guess and finds the nearby solution.
  4. DLS bounds the step near singularities at the price of a small bias; always check convergence honestly.

Knowledge check

Write an answer to each question, then reveal the explanation. Your answers stay in your browser.

Question 1

For a 2R arm with L₁ = 0.4 m and L₂ = 0.3 m, which distances from the base are reachable?

Explanation

From |L₁ − L₂| = 0.1 m to L₁ + L₂ = 0.7 m, for joints without limits.

Question 2

What happens to the two 2R solutions when the target is exactly on the outer boundary?

Explanation

They merge: sin q₂ = 0, so q₂ = 0 and the arm is fully stretched, a singular configuration.

Question 3

Numerical IK from two different starting guesses returns two different answers. Is something wrong?

Explanation

Not necessarily: each converges to a solution near its start. Check both errors; if both are below tolerance, they are two valid branches.

Question 4

Why does the damped least-squares step stay finite when J is singular?

Explanation

Each singular direction is scaled by σ/(σ² + λ²) ≤ 1/(2λ) instead of 1/σ, so the step is bounded.

Question 5

How does wrist-point decoupling simplify 3R planar IK?

Explanation

The required heading fixes the wrist point (target minus L₃ along the heading); joints 1–2 solve a 2R problem for it, and q₃ = φ − q₁ − q₂.

Practise it in the labs

Then test yourself in practice exercises and challenge mode.

References and further reading

  • S. R. Buss, "Introduction to inverse kinematics with Jacobian transpose, pseudoinverse and damped least squares methods", University of California San Diego, 2009.
  • C. W. Wampler, "Manipulator inverse kinematic solutions based on vector formulations and damped least-squares methods", IEEE Transactions on Systems, Man and Cybernetics, 16(1), 1986.
  • D. L. Pieper, "The kinematics of manipulators under computer control", Ph.D. thesis, Stanford University, 1968.