# Solving inverse kinematics with non-linear optimization libraries

Is it a good idea to solve inverse kinematics with non-linear optimization libraries such as Ceres?

I've seen examples of Ceres being used to solve IK and it provides elegant, concise solution.

But my concerns are:

• IK problem is highly non-linear by its nature and solver may get stuck in local minima easily.
• How can we represent the obstacles in optimization problem?
• Can it be used to plan a joint trajectory?

Is it a good idea to solve inverse kinematics with non-linear optimization libraries such as Ceres?

Yes, definitely! The trend in literature during the last years is to walk away from the traditional Jacobian-based methods and adopt optimization techniques, instead, as they have become really powerful and very quick so that they can be implemented in real-time.

Check out the following resources too:

Ceres is very good but implements an unconstrained optimization approach. Other tools like Ipopt, KNITRO, TRACK-IK do implement constrained nonlinear optimization, which turn out to be particularly useful when dealing with obstacles.

IK problem is highly non-linear by its nature and solver may get stuck in local minima easily.

True, but this holds for whatever method you aim to employ. Anyway, the optimization tools I mentioned above are very sophisticated and apply lots of internal techniques to mitigate the problem of local minima. Also, adding up further obstacles and/or secondary tasks helps quite a lot to prevent the solver from getting trapped locally.

How can we represent the obstacles in optimization problem?

Obstacles can be easily represented in form of nonlinear functions $$g(\cdot)$$ (constraints) along with minimum and maximum bounds, which you can add to the problem at hand: these tools can natively handle such constraints. Obstacles can be equivalently described either in the joint space (JS) or in the operational space (OS):

$$min_{JS} < g_{JS} \left( \mathbf{q} \right) < max_{JS} \\ min_{OS} < g_{OS} \left( \mathbf{x} \right) < max_{OS}$$

Can it be used to plan a joint trajectory?

Sure, as long as you can describe your objective in terms of an optimization problem. For example, the trajectory may be encoded resorting to some coefficients. These coefficients can be thought of as the set of the independent variables of the optimization problem whose cost and constraints may be expressed as a collection of properties (e.g., starting and ending points, smoothness, covered distance...).