Stage 08 · Lesson 14/15

Kinematics & Inverse Kinematics · Lesson 14

Multiple Solutions & Singularities

Est. 60–80 min

Why

Why this lesson matters

Lesson 12 showed that IK often has more than one answer. Lesson 13’s solver got stuck when the arm was stretched straight. This lesson puts names and numbers on both: how to choose between several valid answers, and how to recognise singular poses, where the arm loses the ability to move in some direction and IK asks for huge or impossible joint speeds.

By the end of this lesson you will be able to: list all position answers for the example arm (base facing or turned around × elbow one way or the other); choose the answer that is inside the limits and closest to the current pose; explain a singularity using the Jacobian determinant L1·L2·sin(q2); see the base singularity when the wrist is over the base axis; and add a guard that stops motion before a singular pose.

A black-and-white view from a Mars rover’s camera showing its jointed robotic arm stretched out in front, over bright churned soil
NASA’s rover Spirit looking at its own robotic arm stretched out in front of it on Mars. A fully stretched arm is a classic singular pose: the tip cannot move further along the arm’s line.Photo: NASA/JPL-Caltech · Public domain · Source: Wikimedia Commons · resized, converted to WebP

Concept

Many answers, and poses where IK breaks

Part A — Multiple solutions

For the example arm, a wrist-centre position can be reached in up to four ways: the base can face the target or turn 180° and reach back over the top (‘lefty/righty’), and in each case the elbow can bend one way or the other (‘elbow-up/elbow-down’). *Modern Robotics* shows the same four answers for a PUMA-type arm’s position. Add wrist joints and orientation, and there can be even more: the most general 6-joint arm can have up to 16 IK answers.

How to chooseWhy
1. Drop answers outside joint limitsThe servo physically can’t get there
2. Drop answers that collide (table, base, own links)Safety first
3. Prefer the answer closest to the current poseSmallest motion, no sudden flips
4. Keep the same ‘family’ along a pathDon’t switch elbow-up ↔ elbow-down in the middle of a line
5. Prefer answers far from singularitiesMore control, less risk

Part B — Singularities

The Jacobian (Lesson 13) says how the tip moves for small joint motions. At a singularity it loses rank: some tip direction cannot be produced by *any* joint motion. Near a singularity, small tip motions in that direction need very large joint motions.

  • Stretched (or fully folded) arm: for a 2R arm, det J = L1·L2·sin(q2) = 0 when q2 = 0° or 180°. The tip can’t move along the arm’s line.
  • Wrist centre over the base axis: *Modern Robotics* gives ‘the wrist centre of an elbow-type arm directly above the shoulder’ as a singularity. The base angle J1 = atan2(y, x) becomes undefined at x = y = 0, and tiny sideways moves need huge J1 turns.
  • Wrist singularity: when two wrist joint axes line up (for example wrist pitch at 0° on many 6-axis arms), the two joints do the same thing and one direction of rotation is lost — the robot version of gimbal lock (Lesson 10), often called a ‘wrist flip’.

Visual

Visualise it: two elbows and a stretched arm

Two elbow answers for one target; at the outer circle (arm stretched) they merge — the singular pose. Educational 2R solver, simplified.

Interactive · IK solver lab (analytical 2R — educational)

IK concept: target to jointsSingularity sketch

Workflow: target → IK → joints → FK verify → residual. Not a black box — elbow-up/down closed form. Not full 6DOF analytic IK.

Status · ok

2 analytical solution(s) (2R planar).

θ₁

-12.2°

θ₂

92.3°

FK err

0.000

Code lab

Code lab: solutions_singularities.py

solutions_singularities.py lists all four wrist-centre answers for one target, keeps those inside example limits, and picks the one closest to three different current poses. Then it shows the 2R Jacobian determinant and the joint speed needed to move the tip 1 cm/s along the arm as q2 approaches 0°, and finally the base singularity.

solutions_singularities.py · Python
# solutions_singularities.py - many IK answers, how to choose one, and where IK breaks (singularities).
# Part 1: the example arm (Lessons 7-12) reaching a POSITION has up to 4 answers:
#         base facing the target or turned 180 deg (reaching over the top), x elbow one way or the other.
# Part 2: choose the answer closest to the current pose, inside joint limits.
# Part 3: the 2R Jacobian determinant L1*L2*sin(q2) -> 0 when the arm is straight: a singularity.
import math

D1, A2, A3 = 9.0, 10.5, 9.8            # wrist-centre chain of the example arm, cm
LIM = {1: (-90, 90), 2: (-30, 180), 3: (-150, 150)}   # example limits (deg): elbow may bend both ways


def ik2(x, y, l1, l2):
    d2 = x * x + y * y
    c = (d2 - l1 * l1 - l2 * l2) / (2 * l1 * l2)
    if abs(c) > 1:
        return []
    out = []
    for s in (1, -1):
        q2 = s * math.acos(c)
        q1 = math.atan2(y, x) - math.atan2(l2 * math.sin(q2), l1 + l2 * math.cos(q2))
        out.append((math.degrees(q1), math.degrees(q2)))
    return out


def wrap(a):
    return (a + 180) % 360 - 180


def ik_wrist(x, y, z):
    """All (J1, J2, J3) that put the wrist centre at (x, y, z)."""
    sols = []
    r = math.hypot(x, y)
    for flip in (False, True):
        j1 = math.degrees(math.atan2(y, x)) + (180 if flip else 0)
        rr = -r if flip else r                     # facing away: the target is 'behind' the arm
        for j2, j3 in ik2(rr, z - D1, A2, A3):
            sols.append((wrap(j1), wrap(j2), wrap(j3)))
    return sols


def ok(q):
    return all(LIM[i + 1][0] <= q[i] <= LIM[i + 1][1] for i in range(3))


def fmt(q):
    return "(" + ", ".join(f"{round(v, 1) + 0.0:7.1f}" for v in q) + ")"


target = (12.0, 5.0, 14.0)
print(f"Part 1 - wrist centre target {target} cm: all position answers")
sols = ik_wrist(*target)
for q in sols:
    print(f"  J1..J3 = {fmt(q)}   {'inside limits' if ok(q) else 'outside limits'}")

print("\nPart 2 - choose: inside limits AND closest to where the arm is now")
for current in ((20, 60, -60), (20, 10, 40), (-20, 150, -20)):
    valid = [q for q in sols if ok(q)]
    best = min(valid, key=lambda q: max(abs(wrap(a - b)) for a, b in zip(q, current))) if valid else None
    biggest = max(abs(wrap(a - b)) for a, b in zip(best, current))
    print(f"  arm now at {fmt(current)} -> go to {fmt(best)}  (largest joint move {biggest:.1f} deg)")

print("\nPart 3 - singularity of a 2R arm (L1 = 10, L2 = 8 cm)")
L1, L2 = 10.0, 8.0
print("  q2 (deg) | det J = L1*L2*sin(q2) | joint speed needed to move the tip 1 cm/s towards/away from the shoulder")
for q2 in (90, 45, 20, 10, 5, 2, 1, 0):
    det = L1 * L2 * math.sin(math.radians(q2))
    # radial speed of the tip per unit q2-rate: d|p|/dq2 = -L1*L2*sin(q2)/|p|
    reach = math.sqrt(L1 * L1 + L2 * L2 + 2 * L1 * L2 * math.cos(math.radians(q2)))
    rate = abs(L1 * L2 * math.sin(math.radians(q2)) / reach)  # cm per rad
    speed = "infinite (impossible)" if rate < 1e-9 else f"{math.degrees(1 / rate):8.1f} deg/s"
    print(f"  {q2:8} | {det:21.2f} | {speed}")
print("  -> near q2 = 0 (arm straight) the tip can hardly move along the arm: huge joint speeds, IK blows up")

print("\nBase singularity of the example arm: wrist centre near the vertical base axis")
for a, b in (((10.0, 0.0), (10.0, 0.1)), ((1.0, 0.0), (0.0, 1.0)), ((0.1, 0.0), (0.0, 0.1))):
    j1a = math.degrees(math.atan2(a[1], a[0]))
    j1b = math.degrees(math.atan2(b[1], b[0]))
    print(f"  wrist moves {math.dist(a, b):5.2f} cm sideways, from {a} to {b}: J1 must turn {abs(j1b - j1a):5.1f} deg")
print("  at exactly (0, 0), atan2(0, 0) has no meaning: ANY J1 gives the same wrist position")

Output (run with python3 solutions_singularities.py)

Part 1 - wrist centre target (12.0, 5.0, 14.0) cm: all position answers
  J1..J3 = (   22.6,   -23.6,    93.4)   inside limits
  J1..J3 = (   22.6,    65.7,   -93.4)   inside limits
  J1..J3 = ( -157.4,   114.3,    93.4)   outside limits
  J1..J3 = ( -157.4,  -156.4,   -93.4)   outside limits

Part 2 - choose: inside limits AND closest to where the arm is now
  arm now at (   20.0,    60.0,   -60.0) -> go to (   22.6,    65.7,   -93.4)  (largest joint move 33.4 deg)
  arm now at (   20.0,    10.0,    40.0) -> go to (   22.6,   -23.6,    93.4)  (largest joint move 53.4 deg)
  arm now at (  -20.0,   150.0,   -20.0) -> go to (   22.6,    65.7,   -93.4)  (largest joint move 84.3 deg)

Part 3 - singularity of a 2R arm (L1 = 10, L2 = 8 cm)
  q2 (deg) | det J = L1*L2*sin(q2) | joint speed needed to move the tip 1 cm/s towards/away from the shoulder
        90 |                 80.00 |      9.2 deg/s
        45 |                 56.57 |     16.9 deg/s
        20 |                 27.36 |     37.1 deg/s
        10 |                 13.89 |     74.0 deg/s
         5 |                  6.97 |    147.8 deg/s
         2 |                  2.79 |    369.3 deg/s
         1 |                  1.40 |    738.6 deg/s
         0 |                  0.00 | infinite (impossible)
  -> near q2 = 0 (arm straight) the tip can hardly move along the arm: huge joint speeds, IK blows up

Base singularity of the example arm: wrist centre near the vertical base axis
  wrist moves  0.10 cm sideways, from (10.0, 0.0) to (10.0, 0.1): J1 must turn   0.6 deg
  wrist moves  1.41 cm sideways, from (1.0, 0.0) to (0.0, 1.0): J1 must turn  90.0 deg
  wrist moves  0.14 cm sideways, from (0.1, 0.0) to (0.0, 0.1): J1 must turn  90.0 deg
  at exactly (0, 0), atan2(0, 0) has no meaning: ANY J1 gives the same wrist position

Try it: switch between the two elbow solutions for the same target. Then drag the target to the dashed outer circle — the two answers merge into one at the stretched, singular pose. (Educational 2R solver — simplified.)

Interactive · IK solver lab (analytical 2R — educational)

IK concept: target to jointsSingularity sketch

Workflow: target → IK → joints → FK verify → residual. Not a black box — elbow-up/down closed form. Not full 6DOF analytic IK.

Status · ok

2 analytical solution(s) (2R planar).

θ₁

-12.2°

θ₂

92.3°

FK err

0.000

Simulator

Try it in the simulator

Real world

In the real world

  • Wrist flip: in industrial arms a wrist singularity is often called a ‘wrist flip’: when the first and third wrist axes line up, the middle wrist axis tries to spin 180° in zero time to keep the tool’s orientation — with possibly dramatic effects on the arm, the tool, the process and safety.
  • Path planning therefore keeps straight-line tool motions away from singular poses, or slows down near them.
  • Strength: near a singularity the arm can hold large loads along the lost direction with little joint torque — like carrying a suitcase with a straight arm.
An old anatomical drawing of the bones and muscles of the human shoulder, arm and hand
Your own arm has joint limits (your elbow bends only one way), which is why you rarely ‘flip’ — limits remove many IK answers before your brain even considers them.Photo: Wellcome Collection (lithograph by Battistelli after C. Squanquerillo, c. 1839) · CC BY 4.0 · Source: Wikimedia Commons · resized, converted to WebP

Bench build

Bench build: a singularity guard on the two-servo arm

Use the Lesson 12 two-servo arm. singularity_guard.ino moves the tip in a straight line outwards from x = 15 cm in 0.1 cm steps, solving IK at each step and printing q2, det J and the joint step size. As the arm straightens, the steps grow. The guard stops the motion when |sin q2| < 0.17 (about 10° from straight) or when one 0.1 cm step would need more than 3° — with these numbers it stops at about x = 17.7 cm, q2 ≈ 21°.

  1. Power

    Servos on their own 5–6 V supply (2 A or more), GND joined to Arduino GND. Shoulder → pin 5, elbow → pin 6.

  2. Run

    Open Serial Monitor, type go and watch the printed step sizes grow.

  3. Compare

    Mark where the guard stopped on graph paper. Measure how far that is from full reach (18 cm).

  4. Tune

    Change MAX_STEP_DEG to 2 and to 5. Where does it stop now?

singularity_guard.ino · Arduino C++
// singularity_guard.ino - watch a singularity coming on the real 2-servo arm (Lessons 6 and 12).
// Type "go". The tip moves in a straight line along y = 0 from x = 15 cm outwards in 0.1 cm steps,
// solving IK at every step. As the arm straightens (q2 -> 0) the Jacobian determinant
// L1*L2*sin(q2) shrinks and the joints must turn more and more for each 0.1 cm.
// The guard STOPS the motion when |sin(q2)| < 0.17 (about 10 deg from straight) or when one step
// would need more than 3 deg of joint motion - before the arm reaches the singular pose.
// SERVOS run from their OWN 5-6 V supply (2 A or more), NEVER from the Arduino 5 V pin.
// Join the servo supply GND to Arduino GND. Signal wires: shoulder -> pin 5, elbow -> pin 6.
#include <Servo.h>
const float L1 = 10.0, L2 = 8.0;                  // cm - MEASURE
const int SH_ZERO = 90, EL_ZERO = 90;             // servo command for 0 deg
const float MIN_SIN = 0.17, MAX_STEP_DEG = 3.0;
Servo shoulder, elbow;

bool ik(float x, float y, float &q1, float &q2) { // elbow-positive answer, degrees
  float c = (x * x + y * y - L1 * L1 - L2 * L2) / (2 * L1 * L2);
  if (c > 1 || c < -1) return false;
  float a2 = acos(c);
  q1 = degrees(atan2(y, x) - atan2(L2 * sin(a2), L1 + L2 * cos(a2)));
  q2 = degrees(a2);
  return true;
}

void setup() {
  shoulder.attach(5); elbow.attach(6);
  Serial.begin(115200);
  float q1, q2;
  ik(15.0, 0, q1, q2);
  shoulder.write(SH_ZERO + (int)round(q1)); elbow.write(EL_ZERO + (int)round(q2));
  Serial.println(F("At x = 15 cm. Type go"));
}

void loop() {
  if (!Serial.available()) return;
  while (Serial.available()) Serial.read();
  float p1, p2;
  ik(15.0, 0, p1, p2);
  for (float x = 15.1; x <= 18.0; x += 0.1) {
    float q1, q2;
    if (!ik(x, 0, q1, q2)) { Serial.println(F("out of reach - stop")); break; }
    float detJ = L1 * L2 * sin(radians(q2));
    float step = max(fabs(q1 - p1), fabs(q2 - p2));
    Serial.print(F("x ")); Serial.print(x, 1); Serial.print(F("  q2 ")); Serial.print(q2, 1);
    Serial.print(F("  detJ ")); Serial.print(detJ, 1); Serial.print(F("  step ")); Serial.print(step, 2);
    Serial.println(F(" deg"));
    if (fabs(sin(radians(q2))) < MIN_SIN || step > MAX_STEP_DEG) {
      Serial.println(F("GUARD: near singularity (arm almost straight) - stopping here."));
      break;
    }
    shoulder.write(SH_ZERO + (int)round(q1)); elbow.write(EL_ZERO + (int)round(q2));
    p1 = q1; p2 = q2;
    delay(60);
  }
  Serial.println(F("Done. Reset the board to start again from x = 15 cm."));
}
A simple 3D drawing of a white aeroplane inside three coloured gimbal rings, with two of the rings lying flat in the same plane
Gimbal lock: two of the three gimbal rings have lined up in the same plane, so one direction of rotation is lost. A robot wrist with two joint axes lined up has the same problem — a wrist singularity.Photo: MathsPoetry · CC BY-SA 3.0 · Source: Wikimedia Commons · resized, converted to WebP

Debugging

Debugging solution choice and singularities

SymptomLikely causeFix
Elbow flips half-way along a pathSolver picks a different answer each stepPick the answer closest to the previous step; keep one family
Base whips round when the target passes over the baseBase singularity (x = y ≈ 0)Keep paths away from the base axis; limit J1 speed
Servo whines and jerks near full reachNear the stretched singularityStay below ~95% of reach; add a step-size guard
Numerical IK stops at onceStarting guess exactly singularStart from a slightly bent pose
Wrist spins fast though the tool barely movesWrist singularity (axes lined up)Avoid wrist pitch near the aligned angle; re-plan the path
Arm takes a long way roundClosest-answer rule not usedCompare joint distance to every valid answer

Think

Think about it

Think

Harsh says, “I’ll just make my arm reach 18 cm and keep it fully stretched all the time — maximum reach!” What problems will he have?

Experiment

Try it in the lab

About 45 minutes with solutions_singularities.py, and optionally the two-servo arm.

Experiment

Choose wisely, stay away from trouble

You will need

  • `solutions_singularities.py` and Python 3
  • Graph paper
  • Optional: two-servo arm, separate 5–6 V servo supply, Arduino UNO

Steps

  1. Run the script. Change the target to (5, 2, 25) and see how many answers survive the limits.
  2. Add a current pose of your own and check which answer it picks.
  3. Extend the q2 table to 0.5° and 0.1°. Plot joint speed against q2.
  4. Move the wrist target along a line passing 1 cm from the base axis and print J1 at each step.
  5. If you built the arm, run the guard with MAX_STEP_DEG = 2, 3 and 5 and mark the stop points.
  6. In the IK lab, find a target where the two elbow answers are almost the same.

Interactive · IK solver lab (analytical 2R — educational)

IK concept: target to jointsSingularity sketch

Workflow: target → IK → joints → FK verify → residual. Not a black box — elbow-up/down closed form. Not full 6DOF analytic IK.

Status · ok

2 analytical solution(s) (2R planar).

θ₁

-12.2°

θ₂

92.3°

FK err

0.000

Several answers are normal; choosing the nearest valid one keeps motion smooth. Singularities show up as a shrinking Jacobian determinant and exploding joint steps — easy to detect if you look for them, dangerous if you don’t.

Knowledge check

Check your understanding

Knowledge check

1. How many position answers can the example arm’s wrist centre have (base × elbow)?

2. Between two valid answers, the usual best choice is…

3. For a 2R arm, det J = L1·L2·sin(q2). It is zero when…

4. At a singularity, the end-effector…

5. Why is a wrist centre directly above the base axis a problem?

6. A wrist singularity happens when…

7. A sensible guard while moving along a path is to stop when…

Mini assignment

Hands-on assignment

Mini assignment

Solution and singularity map

Make a one-page guide for your arm (or the example arm) on choosing IK answers and avoiding singular poses.

Deliverables

  • All position answers for two targets, marked allowed/not allowed with reasons.
  • Your rule for choosing an answer, written as numbered steps (like the table above).
  • A table or plot of det J (or joint speed) against q2 for your arm.
  • A sketch of where your arm’s singular poses are (stretched, folded, wrist over base).
  • If you built the arm: the guard’s stop points for three MAX_STEP_DEG values.

Do this, step by step

  1. Run python3 solutions_singularities.py and copy Part 1: every position answer for the wrist-centre target, marked allowed or not.
  2. Change the limits in LIM to your own arm’s and rerun. Which answers disappear?
  3. Write your rule for choosing an answer as numbered steps, using Part 2 (inside limits, closest to the current pose).
  4. From Part 3, make a table of det J against q2 and mark where it gets close to zero (stretched and folded).
  5. Optional bench: run singularity_guard.ino with three different MAX_STEP_DEG values and record where the guard stops the arm.

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. Remove answers outside limits first, then pick the one with the smallest joint change from now.
  2. For the 2R arm, det J = L1·L2·sin(q2), so it is zero when the elbow is straight or fully folded.
  3. Near a singular pose a small tip move needs big joint moves; slow down or choose a different path.

Challenges (pick by level)

  • 🟢 Easy: Explain with your own arm why a fully straight elbow makes it hard to push forward quickly.
  • 🟢 Easy: For the 2R arm, compute det J at q2 = 30° by hand.
  • 🟡 Medium: Add a collision rule to Part 1 (elbow must stay above z = 2 cm) and see which answers survive.
  • 🟠 Hard-ish: Write a path follower that keeps the same elbow family for a 20-point line and prints any flips.
  • 🔴 Hard: Compute the manipulability √det(J Jᵀ) for the 3R arm of Lesson 13 along a path and find its lowest point.
  • ⚫ Research: Read *Modern Robotics* Section 5.3 and describe one of its singularity cases in your own words.

Next step

You now have every piece: frames, transforms, FK, DH, workspace, IK, solution choice and singularities. In Lesson 15 — Capstone: Design & Solve the Kinematics of Your 6DOF Robot you put them together for your own arm, with clear pass/fail checks.

Look back: Lesson 13: Analytical vs Numerical IK. Next: Lesson 15: Capstone: Design & Solve the Kinematics of Your 6DOF Robot. Related: Stage 9 — Trajectory Planning and Stage 13 — Perception, Planning & Manipulation.

Sources

  • Modern Robotics — K. M. Lynch & F. C. Park (book home page, free preprint) — Section 5.3 Singularity Analysis (Jacobian loses rank; wrist centre above the shoulder), manipulability and the suitcase example, Chapter 6 (four PUMA-type position answers; up to 16 answers for a general 6R arm).
  • Wikipedia — Gimbal lock — loss of one degree of freedom when two gimbal axes line up; the ‘wrist flip’ (wrist singularity) in robot arms.
  • Wikipedia — Inverse kinematics — multiple solutions and numerical solvers.
  • Lessons 10, 12 and 13 of this stage — gimbal lock in angle sets, the two-servo arm, and the stuck numerical solver.
  • Photos: Wikimedia Commons (credits under each image).

Self-attested for now — keep artifacts in your lab notebook.

Complete

Today's goal

0 of 1 done today

0-day streak
Daily goal:lessons, quizzes or assignments a day

Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).

Stuck somewhere?

Ask a doubt about this lesson

Saved with this lesson's id and your email so we can reply. Privacy · or email contact@aihubstation.in