Robot Inverse Kinematics: A Non-Convex Optimization Challenge
Robotics presents fascinating optimization challenges that combine geometry, control theory, and numerical methods. In this post, I explore a project from my optimization course at NTNU where we tackled the inverse kinematics problem for planar robot arms—a fundamental challenge in robot control that’s both theoretically interesting and practically relevant.
Project materials:
- Project description (PDF) — The original assignment from TMA4180 Optimization I
- Project delivery (PDF) — My complete solution with implementations and analysis
The Robot Kinematics Problem
Consider a planar robot consisting of rigid segments of lengths , connected by revolute joints. The first segment is fixed to the origin, and each subsequent segment can rotate freely relative to the previous one. The joint angles fully describe the robot’s configuration.
Forward Kinematics: The Easy Direction
The forward kinematics problem asks: given the joint angles, where is the end-effector (the “hand”)? This is straightforward. The position of the end-effector is given by:
This is a simple composition of trigonometric functions—easy to compute, no surprises.
Inverse Kinematics: The Hard Direction
The inverse kinematics problem reverses the question: given a target position , what joint angles will place the end-effector at ? In other words, solve:
This is where things get interesting—and difficult. The equation is:
- Nonlinear (trigonometric functions)
- Under-determined (for , infinitely many solutions may exist)
- Ill-posed (adding to any joint angle doesn’t change the configuration)
Rather than trying to solve this equation directly, we reformulate it as an optimization problem:
The idea: find joint angles that minimize the squared distance between the end-effector and the target.
Mathematical Analysis
Computing the Gradient
To use gradient-based optimization, we need . Let and denote the and components of . The -th component of the gradient is:
where
This gradient has a beautiful interpretation: it shows how rotating joint affects the end-effector position through all subsequent segments.
Proving Non-Convexity
A natural question: is convex? Unfortunately, no. To see this, consider the one-dimensional case with a single segment of length :
For , choose , , and . Then:
This violates the convexity condition. The non-convexity arises from the periodic nature of the trigonometric functions—there are multiple local minima corresponding to different robot configurations that reach the same target.
Numerical Solution: BFGS with Line Search
Given the non-convexity, finding the global minimum is generally intractable. Instead, we use quasi-Newton methods to find local minima, specifically the BFGS algorithm with line search satisfying the Wolfe conditions.
The BFGS Algorithm
BFGS (Broyden-Fletcher-Goldfarb-Shanno) builds an approximation to the Hessian iteratively:
- Start with (identity matrix)
- Compute search direction:
- Line search: find satisfying Wolfe conditions
- Update:
- Update Hessian approximation using rank-2 update formula
The Wolfe conditions ensure sufficient decrease while preventing steps that are too short:
with . I used in my implementation.
Numerical Results
For a 4-segment robot with lengths targeting the origin :
- Solution found:
- Iterations: 9 iterations to reach gradient norm
- Convergence: Exponential decrease in gradient norm (typical BFGS behavior)
The method’s efficiency is remarkable—achieving machine precision in under 10 iterations despite the problem’s non-convexity.
Optimal Control: Trajectory Planning
Finding a single configuration is useful, but robots need to move smoothly between configurations. This leads to an optimal control problem.
Problem Formulation
Given initial joint angles and target position , find the velocity that:
- Reaches the target:
- Minimizes energy:
This is a constrained optimization problem:
Quadratic Penalty Method
To handle the equality constraint, we use the quadratic penalty method. Replace the constrained problem with:
As , the penalty term forces the constraint to be satisfied. The gradient is:
where is the Jacobian of .
The algorithm iteratively:
- Solve the unconstrained problem for current
- Increase (typically )
- Repeat until constraint violation is small
Multi-Stage Trajectory Planning
We can generalize to piecewise constant velocities by dividing the time interval into subintervals, each with velocity :
Equivalence Theorem
A beautiful theoretical result: the multi-stage problem reduces to the single-stage problem.
Theorem: The sequence solves the multi-stage problem if and only if for all , and each solves the single-stage problem.
Proof Sketch: Fix the mean of the -th coordinates. Let be the deviations. Then:
With fixed, this is minimized when all , i.e., when all velocities are equal.
This result has practical implications: the optimal trajectory has constant velocity—smoother than piecewise trajectories and easier to compute.
Numerical Verification
For , , , , :
All velocity vectors converged to with relative error , confirming the theoretical equivalence.
Joint Constraints and Barrier Methods
Real robots have physical limits on joint angles. Suppose each joint must satisfy:
For the multi-stage problem, this gives constraints:
Logarithmic Barrier Function
To enforce these inequality constraints, we use a logarithmic barrier:
This function is:
- Finite only when constraints are strictly satisfied
- Tends to as any constraint boundary is approached
The complete problem becomes:
where is the penalty for the equality constraint, is large, and is small.
Gradient of the Barrier Function
The gradient with respect to is:
Implementation Challenges
The barrier method introduces numerical challenges:
- Step size restrictions: Line search must ensure the barrier stays finite
- Ill-conditioning: As and , the Hessian becomes poorly conditioned
- Initialization: Starting point must satisfy all constraints strictly
In my implementation, the line search occasionally failed when became too small or converged to a fixed value, causing the BFGS update to fail. This highlights the practical difficulty of barrier methods compared to penalty methods.
Key Takeaways
This project demonstrates several fundamental concepts in nonlinear optimization:
Non-convexity is ubiquitous in real problems—robot kinematics is inherently non-convex due to periodic joint angles
Quasi-Newton methods are powerful even for non-convex problems, providing superlinear convergence to local minima
Penalty methods convert constrained problems to unconstrained ones, but require careful parameter tuning and can become ill-conditioned
Barrier methods naturally enforce inequality constraints but are numerically delicate
Theory and practice diverge: The equivalence theorem is beautiful, but numerical stability matters more in implementation
Problem structure matters: Understanding the geometry (e.g., that optimal trajectories have constant velocity) leads to simpler, more robust algorithms
Extensions and Applications
The techniques developed here extend to:
- 3D robot arms (spatial kinematics with orientation constraints)
- Redundant manipulators (more joints than degrees of freedom)
- Obstacle avoidance (adding inequality constraints for collisions)
- Real-time control (using warm starts from previous solutions)
- Humanoid robots (inverse kinematics for full-body motion)
Modern robotics uses these methods extensively, combined with:
- Sequential Quadratic Programming (SQP) for better constraint handling
- Interior-point methods as more robust alternatives to barrier methods
- Model Predictive Control (MPC) for real-time trajectory optimization
This post summarizes my optimization project at NTNU (Spring 2016), where I implemented and analyzed various numerical methods for robot kinematics and trajectory planning. All implementations were done in MATLAB using custom BFGS and penalty method codes.