Forward and Inverse Kinematics
Forward kinematics maps joint settings to end-effector position through rigid geometry; inverse kinematics solves the reverse, finding the joint angles that place the hand at a target pose. While forward kinematics is unique and closed-form, inverse kinematics can have multiple solution branches, singularities, or no solution at all.
Why Does This Exist?
When commanding a robotic arm, the goal is expressed in operational task coordinates: "place the suction gripper at coordinate on the conveyor belt." But motors do not accept Cartesian coordinates. Motors rotate joints through individual angles .
Mapping between these two representations is the domain of kinematics:
- Forward Kinematics (FK): Given joint angles , where is the hand? This is a forward geometric evaluation: every joint angle yields exactly one unique end-effector pose.
- Inverse Kinematics (IK): Given a desired hand pose , what joint angles reach it? This is fundamentally difficult: non-linear trigonometric equations yield multiple solution branches (e.g. elbow-up versus elbow-down), boundary singularities where joints lock up, or no solution if the target lies outside the arm's reach.
Solving inverse kinematics reliably is the bridge that allows high-level trajectory planners to command low-level joint motor drives.
Basics first: the configuration space and workspace geometry of robotic limbs live in robot-degrees-of-freedom. Transforming between base and tool frames lives in robot-coordinate-frames. Generating collision-free paths between joint configurations lives in robot-motion-planning.
Think of It Like This
Touching your laptop keyboard with your elbow up versus down
Place your index finger firmly on the spacebar of your keyboard. Keep your fingertip glued to that exact spot. Now, notice what your arm can do: you can swing your elbow outward and upward into the air, or you can drop your elbow downward close to your ribs.
Your fingertip is at the exact same position, but your shoulder and elbow joints occupy two completely different mathematical configurations. These are distinct inverse kinematic branches: "elbow-up" and "elbow-down."
Where it stops: your human brain chooses an elbow posture based on muscle comfort and natural tendon tension. A robot arm controller must explicitly calculate both mathematical branches and evaluate whether the elbow-down posture collides with the tabletop, or whether the elbow-up posture hits an overhead ceiling beam.
How It Actually Works
The 2-link planar arm forward kinematics
For a planar 2-link arm with link lengths and , and joint angles and , the end-effector position is given by simple trigonometry:
This forward mapping is unique, continuous, and straightforward to evaluate.
Inverse kinematics via the Law of Cosines
Given a target position , we first compute the squared distance from the base origin:
If or , the target is outside the reachable workspace and no physical solution exists.
Inside the workspace, applying the Law of Cosines to the triangle formed by , , and gives:
Solving for :
Because , there are two distinct solutions for joint 2:
Once is selected, is found by projecting angles:
- corresponds to the elbow-down configuration.
- corresponds to the elbow-up configuration.
Kinematic singularities: losing degrees of freedom
A singularity occurs when the arm loses the ability to move in one or more Cartesian directions. For the 2-link arm, this happens when:
- : The arm is fully outstretched (). The arm cannot produce radial velocity outward.
- : The arm is folded completely onto itself ().
At a singularity, the Jacobian matrix drops rank. Attempting to track a Cartesian path through a singularity demands mathematically infinite joint velocities (), causing motor drives to trip overcurrent or velocity safety limits.
Worked example: solving IK for target
Consider a 2-link arm with equal link lengths and . We want to reach target .
Compute squared distance :
Distance . Since , the target is reachable.
Compute :
Compute the two joint 2 branches:
Compute base angle :
For Branch 1 (Elbow-Down, ):
For Branch 2 (Elbow-Up, ):
Forward kinematics confirms both branches reach exactly:
- Elbow-down: .
- Elbow-up: .
Code
This Python snippet implements forward and inverse kinematics for the 2-link planar arm, verifies both solution branches, and tests for singularity boundary detection.
import math
def solve_2link_ik( l1: float, l2: float, x: float, y: float,) -> tuple[tuple[float, float], tuple[float, float]] | None: """Solve inverse kinematics for 2-link planar arm returning (elbow_down, elbow_up) in degrees.""" r2: float = x ** 2 + y ** 2 cos_th2: float = (r2 - l1 ** 2 - l2 ** 2) / (2.0 * l1 * l2)
if abs(cos_th2) > 1.0: return None # Target unreachable
th2_down: float = math.acos(cos_th2) th2_up: float = -th2_down
beta: float = math.atan2(y, x) psi: float = math.atan2(l2 * math.sin(th2_down), l1 + l2 * math.cos(th2_down))
th1_down: float = beta - psi th1_up: float = beta + psi
return ( (round(math.degrees(th1_down), 2), round(math.degrees(th2_down), 2)), (round(math.degrees(th1_up), 2), round(math.degrees(th2_up), 2)), )
solutions = solve_2link_ik(l1=0.5, l2=0.5, x=0.6, y=0.4)if solutions is not None: elbow_down, elbow_up = solutions print(elbow_down) # -> (-10.16, 87.71) print(elbow_up) # -> (77.54, -87.71)Watch Out For
Branch flipping during smooth Cartesian trajectory tracking
When commanding an arm to draw a straight Cartesian line across a workbench, independent IK queries at each waypoint can suddenly jump between the elbow-up and elbow-down branches.
The symptom is the arm moving smoothly for several waypoints, then violently attempting to flip its elbow within a single 10 ms control cycle, causing a velocity fault. Fix it by seeding numerical or analytical IK solvers with the robot's current joint state , minimizing to guarantee configuration continuity.
Commanding Cartesian velocities through kinematic singularities
When the arm reaches full extension (), the Jacobian matrix determinant drops to zero: the arm loses a degree of freedom in the radial direction.
The symptom is joint motors whining and shutting down due to excessive commanded speed when tracking a trajectory that grazes the workspace boundary. Fix it by monitoring the Jacobian condition number or manipulability measure (), and using damped least-squares (Levenberg-Marquardt singularity avoidance) when approaching singular configurations.
The Quick Version
- Forward kinematics uniquely maps joint coordinates to end-effector pose using geometric link transformations.
- Inverse kinematics recovers joint angles from a desired Cartesian target; it is non-linear and produces multiple solution branches.
- For a 2-link planar arm () reaching , the Law of Cosines yields two branches: elbow-down and elbow-up .
- Singularity configurations occur at workspace boundaries (full extension or folding), where the arm loses an instantaneous degree of freedom.
- Continuous trajectory tracking must maintain configuration branch consistency to prevent catastrophic joint flips during motion.