Skip to content

RobOptim for real-time computation

An answer to this question on the Scientific Computing Stack Exchange.

Question

Do you think that the RobOptim optimization library (which I read about in https://scicomp.stackexchange.com/questions/4927/c-library-for-nonlinear-constrained-minimization?newreg=6c70b99bbd0e4809966b8a7cce65c706) could be used for real-time optimization for the velocity control of a robot? Being more specific, I have a distance function that I want to minimize between a point of the robot and an obstacle and I have constraints on the maximum velocity/acceleration/jerk of the robot joints, and I want to find the velocities needed to drive the robot away from the obstacle. Do you think I can solve such an optimization problem respecting the real-time requirements of my robot, considering that the iteration time is 1 ms. I know the question may be very vague, and more details should be provided about the algorithm, but for now I am just interested in the order of magnitude of the time needed by this optimization library to provide a result. For example, if the library is generally used for problems that need a solution after a time in the order of seconds it is clearly not suitable for my application.

Thanks for any suggestion

Answer

Your problem can be approximated as a discrete time forward Euler integration, therefore it can be cast as a linear program. The osqp library will give you C code that will meet your performance constraints.

I have no idea about the RobOptim library.

2022-06-14 Update

You've mentioned that your objective function has sines and cosines. These functions are non-convex, so they cannot be handled well by any non-convex programming library.

However, if you want a fast solver, then using a non-convex optimizer such as the one you link to won't get you there. Though such a solver may still work for your use case, you're leaving a lot of performance on the table. Convex solvers are also guaranteed to find a globally optimal solution which nonconvex solvers do not offer such a guarantee. Therefore, it's worth figuring out if your problem can be modified to make a convex program.

The solution is to build a convex approximation of the sine/cosine functions. This paper surveys several possibilities.

As you can see below, the approximations are quite good!

Convex approximations of sine and cosine functions