Skip to content
Tactiverge

Textbooks/Robotics From First Principles/Chapter 6Lite (plain text) version

6Inverse kinematics

Version 1 · Technically checked (automated checks only) · 3 source lessons · 7 practice items

Text
All chapters and search
  1. 1. Sense, think, act
  2. 2. Actuators and drives
  3. 3. Vectors and frames
  4. 4. Rotations and transforms
  5. 5. Forward kinematics
  6. 6. Inverse kinematics
  7. 7. Motion and trajectories
  8. 8. Where am I? Drift, uncertainty and fusion

Introduction

Usually you know where the hand should go and need the joint angles. That is inverse kinematics, and it is harder: the law of cosines gives the elbow angle, but there are often two answers, elbow up and elbow down, and sometimes none at all. Near the edge of the workspace and when the arm is fully stretched, tiny moves of the hand demand huge moves of the joints. Those are singularities.

targetcos θ2 = -0.1elbow down:θ1 -21.3°θ2 95.7°elbow up:θ1 74.4°θ2 -95.7°
Figure 6.1. Two ways to reach one point. A two-link arm with 1 m links reaching the target (1.2, 0.6). The law of cosines gives cos θ2 = -0.1, so θ2 = ±95.7°. Elbow down: θ1 = -21.3°, θ2 = 95.7°. Elbow up (dashed): θ1 = 74.4°, θ2 = -95.7°.

Explanation

This chapter is built from 3 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.

6.1 Inverse kinematics: from a target to joint angles

Forward kinematics always has one answer. Ask the question backwards, 'which angles put the hand HERE?', and you may get two answers, or none. Why?

The elbow first

Only the distance to the target decides how much the elbow must bend; direction doesn't matter. Compute d² = x² + y², then cos θ2 = (d² − L1² − L2²)/(2L1L2). If |cos θ2| > 1 the target is unreachable. Otherwise there are two elbow angles, +θ2 and −θ2 (one if θ2 = 0 or 180°).

Then the shoulder

With θ2 chosen, θ1 = atan2(y, x) − atan2(L2 sin θ2, L1 + L2 cos θ2). The first term points the shoulder straight at the target; the second rotates it back by the angle the bent elbow adds. Use atan2 for both: targets behind or below the base are common.

Trust, but verify

IK formulas are easy to get subtly wrong (a sign, the order of atan2's arguments, degrees vs radians). The fix is cheap: run FK on your answer. If the hand lands on the target, the IK is right. Every robot library's tests do exactly this, as do this lesson's practice generators.

Derivation: Two-link IK with the law of cosines
  1. Shoulder at the origin, target at (x, y), distance d = √(x² + y²). The shoulder, elbow and hand form a triangle with sides L1, L2 and d.

  2. The interior angle at the elbow is 180° − |θ2| (θ2 measures how far link 2 turns away from straight).

  3. Law of cosines: d² = L1² + L2² − 2·L1·L2·cos(180° − θ2) = L1² + L2² + 2·L1·L2·cos θ2.

  4. So cos θ2 = (x² + y² − L1² − L2²) / (2·L1·L2), and θ2 = ±cos⁻¹(that). Plus is elbow down, minus is elbow up (this course's convention).

  5. If the right-hand side is above 1 or below −1, no angle exists: the target is outside the ring.

  6. Shoulder: aim at the target, then correct for the bend: θ1 = atan2(y, x) − atan2(L2 sin θ2, L1 + L2 cos θ2). The correction flips sign with θ2, giving the two matching shoulder angles.

  7. Always check: put (θ1, θ2) back through FK. You should land on (x, y).

Common mix-ups

  • IK always has exactly one answer, like FK.
    ✓ A two-link arm usually has two (elbow up and down), one at the ring's edges, and none outside it.
  • θ1 is just atan2(y, x).
    ✓ That points the shoulder at the target; you must subtract the extra angle the bent elbow adds.

Open the full lesson: Inverse kinematics: from a target to joint angles →

6.2 Elbow up or elbow down? Choosing between solutions

Two sets of joint angles put the hand on the same bolt. One of them smashes the elbow into a shelf. How does a robot choose?

Mirror images

The two solutions share |θ2| and are reflections of each other across the line from shoulder to target. With this course's convention elbow up has θ2 < 0, elbow down θ2 > 0. At the edges of the ring (θ2 = 0 or ±180°) they coincide; in the middle of the ring they differ the most.

How to choose

Common rules: (1) reject any solution outside joint limits or that collides with something; (2) among the rest, pick the one closest to the current joint angles, so the move is short and predictable; (3) keep the same branch throughout a task. Many industrial arms fix the branch in the program ('elbow up' configuration) for exactly this reason.

Don't flip mid-move

If a controller re-solves IK at every step of a straight-line hand move and naively picks 'the first solution', it can jump from one branch to the other. The hand target barely changes, but the elbow swings through a huge arc in one step. That's a sudden, fast, dangerous motion, and a classic bug to test for.

Common mix-ups

  • Elbow up and elbow down are equally good, so it doesn't matter which you pick.
    ✓ Obstacles, joint limits and continuity with the current pose usually make one clearly better.
  • Re-solving IK every step is always safe.
    ✓ Only if you keep the same branch; switching branches mid-move causes sudden large joint motions.

Open the full lesson: Elbow up or elbow down? Choosing between solutions →

6.3 Unreachable targets, joint limits and singularities

Near full stretch, a tiny hand movement can need a huge, fast joint movement. Why do robots go 'weak' at the edge of their reach?

Outside the ring

If d > L1 + L2 (beyond reach) or d < |L1 − L2| (inside the hole), IK has no solution. A good solver says so and reports the gap: d − (L1 + L2) or |L1 − L2| − d. A common safe fallback is to reach the nearest reachable point along the same direction, and flag the shortfall rather than hide it.

Singularities

When θ2 = 0° (straight) or ±180° (folded), the two links are in line. Then both joints can only swing the hand sideways around the shoulder; moving along the arm's line needs no joint motion at first order. The arm's Jacobian determinant, L1·L2·sin θ2, is zero there. Near a singularity, small hand moves along that line demand very large, fast joint moves.

From joint error to hand error

Encoders are never perfect. A shoulder error Δθ1 swings the whole arm, moving the hand by about d·Δθ1 (radians), where d is the shoulder-to-hand distance. A stretched-out arm amplifies errors most. A 0.5° error at d = 0.8 m is 0.8 × 0.00873 ≈ 7 mm: enough to miss a small hole.

Common mix-ups

  • A robot is strongest and most precise at full stretch.
    ✓ Full stretch is a singularity: it loses a direction of motion and amplifies joint errors the most.
  • Unreachable targets only happen beyond full stretch.
    ✓ Unless L1 = L2, there's also a hole near the base that the arm can't fold into.

Open the full lesson: Unreachable targets, joint limits and singularities →

Worked examples

Inverse kinematics: from a target to joint angles: example 1

L1 = 5 cm, L2 = 3 cm, target (6, 2) cm. Find both solutions.

Solution

d² = 40. cos θ2 = (40 − 25 − 9)/30 = 0.2, |θ2| = 78.5°. Elbow up (θ2 = −78.5°): θ1 = atan2(2, 6) − atan2(3 sin(−78.5°), 5 + 3 cos 78.5°) = 18.4° − (−27.7°) = 46.1°. Elbow down: θ1 = 18.4° − 27.7° = −9.3°. These match the Gripper Build's Level 4 answer key.

Elbow up or elbow down? Choosing between solutions: example 1

The arm is at (θ1, θ2) = (40°, −70°). The two IK solutions for the next target are (45°, −75°) and (−5°, 75°). Which should it use?

Solution

The first: it's 5° away on each joint, on the same branch (θ2 negative). The second needs a 45° shoulder move and a 150° elbow swing.

Unreachable targets, joint limits and singularities: example 1

L1 = 40 cm, L2 = 25 cm. A target is at (50, 45) cm. Reachable? If not, by how much is it out?

Solution

d = √(2500 + 2025) = √4525 ≈ 67.3 cm. Outer radius 65 cm. Unreachable, 2.3 cm beyond full stretch.

Interactive figures

Figure 6.2 from Inverse kinematics: from a target to joint anglesIn 'Inverse' mode, drag the target around with the sliders. Watch the readout's cos θ2 value. What happens to it as the target approaches the outer edge? The inner edge? Just outside? Note the grey dashed arm: when do the two solutions look most different?
Can't use the interactive? Read a description instead

In Inverse mode a crosshair marks the target; the arm is drawn reaching it with the chosen elbow, and the other solution is shown as a grey dashed arm. The readout gives d, cos θ2, both joint-angle pairs and an FK check, or says the target is unreachable and by how much.

Interactive figure (online). Description: In Inverse mode a crosshair marks the target; the arm is drawn reaching it with the chosen elbow, and the other solution is shown as a grey dashed arm. The readout gives d, cos θ2, both joint-angle pairs and an FK check, or says the target is unreachable and by how much.

Laboratory

Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.

Guided practice

Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.

Practice 1

L1 = 0.5 m, L2 = 0.5 m, target (0.5, 0.5) m. What is cos θ2? (2 decimal places)

Practice 2

You compute cos θ2 = 1.18. What does it mean?

Practice 3

What is the most reliable quick check of an IK answer?

Practice 4

What do the elbow-up and elbow-down solutions for the same target always share?

Practice 5

Which rule best avoids sudden elbow swings during a long move?

Practice 6

For a two-link arm, at which elbow angles is it singular?

Practice 7

A target is 3 cm beyond reach. What should a well-designed IK function do?

  1. L1 = 0.5 m, L2 = 0.5 m, target (0.5, 0.5) m. What is cos θ2? (2 decimal places)
  2. You compute cos θ2 = 1.18. What does it mean?
    • θ2 ≈ 10°
    • The target is beyond full stretch: no solution
    • Use the elbow-up solution
    • Round it to 1
  3. What is the most reliable quick check of an IK answer?
    • Check θ1 is positive
    • Run forward kinematics on the angles and compare with the target
    • Check θ2 is less than 180°
    • Ask whether the angles look reasonable
  4. What do the elbow-up and elbow-down solutions for the same target always share?
    • The same θ1
    • The same |θ2|
    • The same elbow position
    • Nothing
  5. Which rule best avoids sudden elbow swings during a long move?
    • Always pick the solution with positive θ1
    • Pick the valid solution closest to the current joint angles, and keep the same branch
    • Pick at random each step
    • Always pick elbow down
  6. For a two-link arm, at which elbow angles is it singular?
    • θ2 = 90° and −90°
    • θ2 = 0° and ±180°
    • θ1 = 0°
    • Whenever the hand is on the x axis
  7. A target is 3 cm beyond reach. What should a well-designed IK function do?
    • Crash
    • Return NaN and let the motors try
    • Report 'unreachable' with the 3 cm gap, and optionally the nearest reachable pose
    • Silently reach the nearest point and report success

Engineering applications

  • Avoiding the table

    When an arm works just above a table, the elbow-down solution may drive the elbow through the surface. Controllers pick the solution that keeps clear of obstacles and stays far from joint limits.

  • Graceful failure

    If a target is out of reach, the cosine of the elbow angle comes out bigger than 1 and there is no solution. Good code detects that and moves to the nearest reachable point instead of crashing.

Watch

Optional verified videos. Nothing loads from YouTube until you press play.

Shows the reverse problem of choosing joint angles to reach a target, and why it can have several answers.

4 min 3 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

Introduces the Jacobian: how joint speeds turn into hand speed, and how hand forces load the joints.

8 min 27 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

  • Modern Robotics, Chapter 6: Inverse Kinematics of Open Chains (Northwestern Robotics)
  • Modern Robotics, Chapter 5: Velocity Kinematics and Statics (Northwestern Robotics)

Chapter summary

  • Inverse kinematics finds joint angles for a desired hand position.
  • For two links the law of cosines gives cos θ2; its two signs are elbow up and elbow down.
  • If |cos θ2| > 1 the target is out of reach; check before taking the inverse cosine.
  • Always verify an IK answer by running forward kinematics on it.

Glossary

Inverse kinematics
Inverse kinematics finds joint angles that place the end-effector at a desired position. There may be several solutions, one, or none.
Forward kinematics (two-link arm)
Forward kinematics computes where the end-effector is from the joint angles and link lengths.
Workspace and reach
A robot's workspace is the set of all positions its end-effector can reach. For a two-link planar arm it is a ring between radii |L1 − L2| and L1 + L2.

Definitions from the Field Guide.

Project: A safe IK function

Write a function that returns both inverse-kinematics solutions for a two-link arm, reports clearly when a target is unreachable, and checks every answer with forward kinematics. Test it on targets inside, on the edge of and outside the workspace.

Deliverables

  • The function with a docstring
  • At least six test cases including edge and unreachable targets
  • A note on which solution you would choose and why

Keep your work in your Engineering Journal; it stays private unless you choose to share it.

References

  • Kevin M. Lynch and Frank C. Park (2017). Modern Robotics: Mechanics, Planning, and Control. Cambridge University Press.
  • John J. Craig (2005). Introduction to Robotics: Mechanics and Control, 3rd edition. Pearson Prentice Hall.
  • Mark W. Spong et al. (2006). Robot Modeling and Control. Wiley.

Further reading from the source lessons

Publication record

Version
1
Status
Technically checked (automated checks only)
Technical review
Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
Written by
Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
Licence
All rights reserved by the founders unless a licence is approved.
Corrections
None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.