Drake NLP Inverse Kinematics Notes
NLP (Nonlinear Programming)
NLP := subfield of mathematical optimization where you try to find a set of variables (in our case, the robot's joint angles ) that minimize some objective cost function, subject to a set of constraints (where at least one of those equations is nonlinear).
- ❓ Why is IK a nonlinear optimization problem?
- → because a robot's forward kinematics relies heavily on trigonometry (sines & cosines of joint angles multiplied through a kinematic chain) → so the relationship between a joint angle and the end-effector's position is inherently nonlinear.
IK written as an NLP
- Find: (joint angles)
- To minimize: effort, distance from rest pose, total movement, ...
- Subject to: [constraints]
- (the gripper must be exactly at target XYZ)
- (the camera must be inside the FOV cone)
- (the distance between link A and B must be > 0 to avoid collision)
Multi-start
Nonlinear programming solvers are local optimizers: they act like a hiker dropped onto a mountain in the fog, using calculus (gradients, Jacobians) to feel the slope of the math and walk downhill until they hit a valley (a local minimum).
- ⚠️ If the problem is highly complex: there are many valleys! If you drop the solver in a bad starting position, it will get stuck in a "local minimum"
- 🔑 ^ Solution: try many starting positions!
Multi-start:
- Generate random different initial joint configurations (the "seeds")
- Start independent NLP solvers, one for each seed
- If any of them converge on a valid pose that passes all constraints, return and declare success.
SNOPT (Sparse Nonlinear OPTimizer)
SNOPT is a commercial-grade Fortran package used to solve NLP problems - this is what Drake uses!
- Uses an algorithm called SQP: Sequential Quadratic Programming
- 💡 Core idea: SNOPT takes the current
- Advantages:
- Disadvantages:
Sequential Quadratic Programming
SQP is one of the main algorithms for solving constrained non-linear optimization problems.
- 💡 Core intuition: Newton's method!
- If you want to find the bottom of a curved valley (a minimum), Newton's Method fits a parabola (quadratic bowl) to the ground right where you are standing. It calculates the exact bottom of that bowl, you jump to that spot, then you fit a new bowl.
- ^ SQP does exactly this, but handles constraints:
- 🔖 At every step, SQP:
- Calculates the gradient (slope) and Hessian (curvature) of the objective
- Constructs a quadratic approximation of the objective (a bowl)
- Constructs a linear approx of the constraints (flat walls)
- Solves this QP to find the best step to take
- Takes the step, updates the approximations, and repeats until convergence
Concrete example
Let's work through a simple example.
- Objective: Move as far "up and right" as possible: minimize
- Constraint: You are tethered to a pole by a 1m cable. You must stay exactly on the edge of the circle -
- SQP uses the Lagrangian to glue the objective with the constraint: (Read about the Lagrangian here: The Lagrangian (Calculus))
- Initialize our guess: Let's drop the solver at a starting point & have an initial multiplier guess -
- Build the approximations: To build the quadratic program for this step, the solver needs the slopes and curvatures at :
- Gradient of the objective:
- Jacobian of the constraint (linearization):
- Hessian of the Lagrangian (curvature):
- Solve the quadratic subproblem: SQP now asks, "what step should I take?" It sets up the following simple QP to solve for :
- Minimize the quadratic objective: subject to the linearized constraint: [CONTINUE FROM HERE brain dead]
IPOPT (Interior Point OPTimizer)
IPOPT is an open-source rival to SNOPT and also widely used in robotics.
- Instead of SQP, IPOPT uses an interior point method.
- 💡 Imagine the constraints form a fenced-in yard. IPOPT solves the problem by adding a mathematical "force field" (barrier penalty) to the edges of the yard. As the solver gets closer to violating a constraint (e.g. self-collision), the penalty shoots toward infinity.