Inverse kinematics and the workspace
Use the two-link inverse kinematics solution like an engineer: map the workspace, choose between multiple solutions, handle unreachable targets and recognise singularities.
Lesson 5 of 6 · 40 min · Self-paced · Free
From a formula to a decision
In the two-link arm lesson you derived the inverse kinematics (IK) of a planar arm: given a target (x, y), find joint angles θ₁ and θ₂. That formula is the start of the job, not the end. A real robot asking "how do I reach there?" must also decide which answer to use when there are two, what to do when there are none, how joint limits change the picture, and why some targets cause wild, fast joint motions. This lesson turns the formula into a working decision procedure.
As a reminder, for links L₁ and L₂ and a target at distance r from the base:
cos θ₂ = (r² − L₁² − L₂²) / (2 · L₁ · L₂)
θ₂ = ± arccos(cos θ₂)
θ₁ = atan2(y, x) − atan2(L₂ · sin θ₂, L₁ + L₂ · cos θ₂)Throughout this lesson we use the explorer's default arm: L₁ = 20 cm and L₂ = 15 cm, with a reach from 5 cm (|20 − 15|) to 35 cm (20 + 15).
Two answers: elbow up and elbow down
Take the target (22, 18), at distance r ≈ 28.43 cm. Then cos θ₂ ≈ 0.305 and θ₂ ≈ ±72.24°. The two complete solutions are:
elbow down: θ₁ ≈ 9.12°, θ₂ ≈ +72.24°
elbow up: θ₁ ≈ 69.46°, θ₂ ≈ −72.24°Both put the hand exactly on the target. Geometrically they are mirror images: the elbow sits on one side or the other of the straight line from the base to the target. (Which one gets called "up" is a naming convention; the explorer calls positive θ₂ "elbow down" and negative θ₂ "elbow up".)
Try it now. Switch the explorer to Inverse, set the target near (22, 18) and flip between the two elbow solutions.
Explorer 01 — Robotic kinematics
From joint angles to a position, and back again
Fig. — 2-link planar arm · units cm · y up
Joint angles (relative)
More controls
Arm geometry
- End x
- 15.1 cm
- End y
- 26.4 cm
- Distance r
- 30.4 cm
- workspace 5.0–35.0 cm
- |sin θ2|
- 0.87
- well-conditioned
- Tip angle φ
- 95.0°
State
Forward kinematics. Joint angles: joint 1 35°, joint 2 60°. End effector at x 15.1 cm, y 26.4 cm, 30.4 cm from the base. Elbow well-conditioned (|sin θ2| = 0.87).
Forward kinematics. Joint angles: joint 1 35°, joint 2 60°. End effector at x 15.1 cm, y 26.4 cm, 30.4 cm from the base. Elbow well-conditioned (|sin θ2| = 0.87).
How to read this
The base sits at the centre (grid squares are 10 cm). Each thick bar is a link; circles are joints J1, J2. The shaded ring is the workspace: every point the tip can reach with unlimited joint travel. Its outer edge is L1 + L2; the inner hole appears when one link is longer than the others combined.
Arcs show each joint angle. θ1 is measured from the dashed horizontal; θ2 from the dashed extension of link 1. In inverse mode the square is the target (dashed and labelled unreachable when outside the ring), and the arm is solved with the law of cosines. Most targets have two solutions: elbow-up and elbow-down.
Assumptions & limitations
- Ideal rigid links and revolute joints with no mass, friction, backlash, or flex.
- Joints may rotate a full ±180°; real joints have hard limits that shrink the workspace, and links cannot pass through each other or the floor.
- Kinematics only: nothing here says whether the motors are strong or fast enough to hold or reach a pose (that is dynamics).
- Three-link inverse kinematics is made solvable by fixing the tool angle φ; real controllers choose among redundant solutions with extra goals.
- Unreachable targets are projected onto the nearest edge of the reachable ring for display; a real controller would refuse or plan around them.
Choosing between solutions
Which solution should the robot use? There is no single right answer, but there are standard rules:
- Respect joint limits. If one solution needs an angle the joint cannot physically reach, discard it.
- Avoid collisions. If one elbow position would hit the table, a wall or the robot's own body, discard it.
- Move as little as possible. Among what remains, prefer the solution closest to the arm's current angles. This keeps motion short and smooth and avoids the arm suddenly "flipping" its elbow through a large swing.
Here is a small Python IK solver that returns every solution, plus a chooser that applies rule 3:
import math
def solve_ik(L1, L2, x, y):
"""Return a list of (theta1, theta2) solutions in degrees (may be empty)."""
c2 = (x * x + y * y - L1 * L1 - L2 * L2) / (2 * L1 * L2)
if c2 > 1 or c2 < -1:
return [] # out of reach
solutions = []
for sign in (+1, -1): # elbow down, elbow up
t2 = sign * math.acos(c2)
t1 = math.atan2(y, x) - math.atan2(L2 * math.sin(t2), L1 + L2 * math.cos(t2))
solutions.append((math.degrees(t1), math.degrees(t2)))
return solutions
def closest(solutions, current):
"""Pick the solution needing the least total joint movement."""
return min(solutions, key=lambda s: abs(s[0] - current[0]) + abs(s[1] - current[1]))
L1, L2 = 20, 15
for target in [(22, 18), (34, 0), (34.9, 0), (40, 10), (3, 2)]:
sols = solve_ik(L1, L2, *target)
shown = ", ".join(f"({a:6.2f}, {b:6.2f})" for a, b in sols) or "unreachable"
print(f"target {target}: {shown}")
a, b = closest(solve_ik(L1, L2, 22, 18), current=(60, -60))
print(f"closest to (60, -60): ({a:.2f}, {b:.2f})")target (22, 18): ( 9.12, 72.24), ( 69.46, -72.24)
target (34, 0): (-11.85, 27.75), ( 11.85, -27.75)
target (34.9, 0): ( -3.75, 8.75), ( 3.75, -8.75)
target (40, 10): unreachable
target (3, 2): unreachable
closest to (60, -60): (69.46, -72.24)If the arm is currently at (60°, −60°), the elbow-up solution needs only about 9° and 12° of joint motion, while elbow-down would need about 51° and 132°. The chooser picks elbow up. (A real solver would also wrap angle differences, so that 179° and −179° count as 2° apart, not 358°.)
Unreachable targets
The solver returns nothing for (40, 10) and (3, 2). The first is r ≈ 41.23 cm from the base, beyond the 35 cm reach, about 6.2 cm too far. The second is r ≈ 3.61 cm, inside the 5 cm hole where the forearm cannot fold back far enough.
What should the robot do? Silently returning garbage is the worst option. Sensible responses include:
- Refuse and report ("target out of reach"), so the planner can choose another target or move the robot's base.
- Go to the nearest reachable point, if getting close is useful. The explorer does this: the arm stretches towards the target and reports how far short it stops.
Either is reasonable; what matters is that the choice is deliberate and visible.
How joint limits reshape the workspace
The ideal workspace is a ring between 5 and 35 cm. Real joints have limits. Suppose the elbow can only bend from 0° to +150°. Two things change:
- Only the elbow-down family of solutions (positive θ₂) is available.
- The arm cannot fold completely. At θ₂ = 150°, the hand's distance from the base is √(L₁² + L₂² + 2 · L₁ · L₂ · cos 150°) = √(400 + 225 − 519.6) ≈ 10.27 cm. The unreachable hole grows from 5 cm to about 10.3 cm.
Shoulder limits, in turn, cut slices out of the ring. Mapping the real workspace, with limits included, is one of the first things engineers do when placing a robot in a work cell.
Singularities: where the two solutions meet
Look again at the solver output for targets on the x-axis:
- At (34, 0), θ₂ = ±27.75°.
- Move 0.9 cm further out to (34.9, 0), and θ₂ = ±8.75°.
A 0.9 cm move of the target demanded a 19° change of the elbow. Compare a target well inside the workspace: moving from (30, 0) to (30.9, 0) changes θ₂ from 62.72° to 56.65°, about 6°. Near the outer edge, the arm is nearly straight, and small target changes need large joint changes.
At the very edge (r = 35 cm) the two solutions merge into one, θ₂ = 0, and the arm is fully stretched. The same happens at the inner edge, fully folded. These configurations are called singularities. At a singularity the arm loses the ability to move its hand in some direction: stretched out straight, it simply cannot move its hand further outward, no matter how fast the joints turn. Near a singularity it can move that way, but only with very large joint speeds.
The explorer's |sin θ₂| reading measures how close you are. It is 0 when the arm is straight or folded and 1 when the elbow is at a right angle. The next lesson shows exactly where that number comes from, and why it controls how joint speeds turn into hand speed.
Beyond two links
With three links in a plane, a target position no longer pins down the joint angles: the third joint adds an extra degree of freedom, so there are infinitely many solutions. The explorer's 3-link mode resolves this by asking you to fix the tool's angle φ, which turns the problem back into a two-link problem for the wrist. Real six-joint arms have closed-form solutions for their particular geometry, or use numerical IK: start from a guess, compute how far the hand is from the target, nudge the joints to reduce that error, and repeat. Whichever method is used, the questions from this lesson remain: how many solutions, which one, and what if there are none?
Recap
A reachable target generally has two IK solutions, elbow up and elbow down. Choose between them using joint limits, collisions and the least movement from the current pose. Targets outside the outer radius or inside the inner hole have no solution; handle them deliberately. Joint limits shrink and reshape the workspace. At the workspace edges, the solutions merge at singularities, where the arm cannot move in some direction and nearby targets demand large joint motions.
Project
Explorer and Python project: a reachability report
Using the explorer's default arm (L₁ = 20 cm, L₂ = 15 cm):
- Choose eight targets: three well inside the workspace, two within 1 cm of the outer edge, one within 1 cm of the inner edge, and two unreachable.
- For each, record both solutions from the explorer, or from the Python solver, and verify one of them with forward kinematics.
- Assume the arm currently sits at θ₁ = 0°, θ₂ = 90°. For each reachable target, say which solution the "least movement" rule picks.
- Now impose an elbow limit of 0° to +150°. Which of your targets become unreachable, and why?
No hardware is needed.
Deliverables
- A list of eight targets with r, cos θ₂ and both solutions (or 'unreachable')
- One forward-kinematics check per reachable target
- The chosen solution for each target and the effect of the elbow limit
Knowledge check
Check your understanding
Go further
- Wikipedia — Inverse kinematics ↗
Analytical and numerical approaches to IK, with examples beyond two links.
Lesson materials · free to download
Sign in to track your progress. Reading is free without an account.