In this guide
You built a robot arm. You can set each servo to an angle and watch the arm move. But when someone asks "make the gripper touch that bolt at coordinates (20, 5, 10)," you are stuck — you would have to guess angles, tweak, guess again.
Forward kinematics is easy: given joint angles, where is the gripper? (Just geometry.) Inverse kinematics (IK) is the useful direction: given a target position, what joint angles get the gripper there? This guide explains IK from intuition to implementation.
Forward vs inverse, concretely
- Forward kinematics: angles in → position out. Deterministic, one answer, straightforward trigonometry.
- Inverse kinematics: position in → angles out. Harder: there may be zero solutions (target unreachable), one solution, or many (elbow-up vs elbow-down both reaching the same point).
Every pick-and-place robot — including the classic student arm sorting objects — runs IK continuously: camera says "object at (x, y, z)," IK says "shoulder 42°, elbow 88°," servos move.
Start with 2 links in a plane (the essential case)
A 2-joint planar arm (shoulder + elbow) reaching a point (x, y) has a closed-form solution — pure geometry, no iteration:
Link lengths L1, L2. Target (x, y). Distance to target: d = sqrt(x^2 + y^2)
Reachable only if: |L1 - L2| <= d <= L1 + L2
(elbow can't bend past straight; can't reach beyond full extension)
Elbow angle (law of cosines):
cos_elbow = (d^2 - L1^2 - L2^2) / (2 * L1 * L2)
elbow = acos(cos_elbow) # two solutions: +/- (elbow up/down)
Shoulder angle:
shoulder = atan2(y, x) - atan2(L2 * sin(elbow), L1 + L2 * cos(elbow))
That is complete 2-link IK. Understand this derivation and you understand the idea of all analytic IK: constrain the geometry, solve the triangles. Many student arms (2–3 DOF planar) need nothing more than this plus a base rotation.
Adding a rotating base (3 DOF): the base angle is simply atan2(y, x) in the horizontal plane; the remaining 2-link problem is solved in the vertical plane at radial distance sqrt(x^2 + y^2). This covers the overwhelmingly common student arm: base yaw + shoulder + elbow.
When geometry is not enough: numerical IK
Arms with 4+ joints, or with joint limits and obstacles, usually have no clean formula. Numerical methods iterate toward a solution:
- Jacobian-based (Newton-like): compute how small joint changes move the gripper (the Jacobian matrix), step the joints to reduce position error, repeat until close enough. Fast near the solution; needs a good initial guess.
- CCD (Cyclic Coordinate Descent): adjust one joint at a time, starting from the gripper end, rotating each to point at the target; loop until converged. Simple to implement, no matrices.
- FABRIK: work geometrically from both ends toward the middle. Intuitive and stable for chains.
For student projects, the practical advice is: do not implement these yourself. Use a library — ROS2's MoveIt, or IKFast-generated solvers, or even simple iterative code for CCD. The algorithms are solved problems; your project's novelty is elsewhere.
Joint limits, singularities, and picking solutions
Real arms are not math abstractions:
- Joint limits: servos rotate ~0–180° (or 0–270°). A mathematically valid solution outside your servo's range is useless — clamp or discard it.
- Multiple solutions: elbow-up vs elbow-down. Pick by continuity (closest to the current pose — avoids wild swings) or by task (elbow-up clears obstacles).
- Singularities: configurations where the arm loses a degree of freedom (fully extended, or wrist aligned with base). Near singularities, tiny target changes demand huge joint motions — planners avoid lingering there.
- Unreachable targets: check reachability before commanding: is the target within the workspace sphere, and is the path clear? Commanding unreachable poses makes servos strain against their limits.
From IK to smooth motion
IK gives you poses (angle sets). Moving between poses needs trajectory planning:
- Never jump between IK solutions — interpolate joint angles over time (linear or smooth profiles like trapezoidal velocity).
- Move all joints together, arriving simultaneously — sequential joint motion looks robotic in the bad way.
- Respect speed limits — servos have max speeds; commanding faster just saturates and loses accuracy.
- Add a gripper action at the right moment (close after arriving, open after lifting).
A pick-and-place cycle is: IK to pre-grasp pose → descend → close gripper → IK to lift pose → IK to place pose → descend → open. Each arrow is an interpolated trajectory, not a jump.
Calibration: where theory meets your arm
Analytic IK assumes perfect link lengths and perfect 90° assembly. Reality:
- Measure your actual link lengths (joint-axis to joint-axis, not the plastic part length) and use those numbers.
- Servo horns are rarely at true zero. Find each servo's actual center/offset and bake offsets into your angle commands.
- Test with a grid: command a 3×3 grid of points on paper, mark where the gripper actually lands, and you will see your systematic errors — then correct the model.
A 5mm error in a link-length constant produces centimeter-scale errors at full reach. Measure twice.
Orientation: position is only half the problem
Reaching (x, y, z) puts the gripper at the target — but a pick-and-place task also needs the gripper oriented correctly (fingers pointing down at the object, not sideways into the table). Full pose control means position plus orientation (roll, pitch, yaw): 6 numbers, which is why industrial arms have 6 joints.
Student simplifications that work:
- Keep the tool pointing down. Constrain the wrist so the gripper always faces the table. This removes orientation from the IK problem entirely — solve position IK for the wrist point, and the gripper angle is fixed by construction.
- Add one wrist joint for the common case of tilted objects — a single pitch joint at the wrist, set manually per task phase.
- Reserve full 6-DOF IK for later. Libraries (MoveIt, IKFast) solve it, but the calibration and singularity handling are graduate-level fiddliness. A 3-DOF arm with a level gripper completes the vast majority of student pick-and-place demos.
Design the task around the arm you can calibrate, not the arm you wish you had.
Common mistakes
- Commanding angles without reachability checks. The arm strains, servos overheat, nothing reaches.
- Ignoring the elbow-up/down choice. The solver flips solutions between calls and the arm swings wildly through the workspace.
- Jumping between poses. Always interpolate; servos and mechanics punish steps.
- Using CAD link lengths instead of measured ones. Manufacturing and assembly tolerances are real.
- No joint-limit clamping. The math says 200°; your servo physically stops at 180° and burns current trying.
- Solving IK in the wrong frame. Camera gives coordinates in the camera frame; the arm needs base-frame coordinates. The transform between them (hand-eye calibration) must be right or every reach misses.
Quick checklist
- Link lengths measured joint-axis to joint-axis
- Servo zero offsets calibrated per joint
- Reachability check before every commanded pose
- Solution chosen for continuity (nearest to current pose)
- Joint limits clamped in software
- Interpolated trajectories between poses, all joints synchronized
- Tested against a physical grid; systematic errors corrected
Where to go from here
- Control the joints smoothly: PID Control Tuning: A Practical Guide.
- Full arm stack in ROS2/MoveIt: ROS2 Basics for Students.
- Actuator selection: Servo vs stepper motor selection.
- Build the physical arm: CAD to prototype with Fusion 360 and 3D printing.
- Tolerances that affect your measurements: engineering tolerances and fits explained.
- More robotics topics in the Mechanical branch hub.