Implementing Generic External Nonlinear Constraint in acados

Hi :wave:

I am working on a nonlinear model predictive control (NMPC) problem that involves nonlinear constraints for obstacle avoidance. Specifically, I have a separate C file that computes the distance to the closest obstacle and provides the corresponding gradient at a given point. However, this function relies on multiple external libraries, making it impractical to express symbolically in CasADi.

I would like to integrate this constraint efficiently within acados. After reviewing the documentation and examples, I found that the Python interface supports generic external dynamics but does not explicitly mention support for generic external constraints.

Upon further investigation, I came across the nonlinear_chain_ocp_nlp_no_interface.c example, which includes hand-written constraints. This led me to wonder whether it is possible to integrate my constraint function as a separate C file while still using the Python interface for setting up the problem. My model dynamics and cost functions can be expressed using CasADi, so the only external component is the nonlinear constraint.

My questions are:

  1. Can the Python interface be used to set up an NMPC problem with external nonlinear constraints defined in a separate C file?
  2. If so, what steps are required to integrate such a constraint properly?

Any guidance or examples on this topic would be greatly appreciated. Thanks in advance :folded_hands:

Hi,

unfortunately, this is not yet possible in the Python interface.
It is certainly possible to extend the interface to support it.
Generic nonlinear constraints would be implemented very similarly to how it was done for dynamics, so you could try to understand how this is done and modify the interface accordingly.
If you consider implementing this, a PR is very welcome.
The functions that you need to provide in this case would be very similar to the ones in the nonlinear_chain_ocp_nlp_no_interface.c example that you saw.
If you have more specific questions on how to do it, let me know :slight_smile:

Best,
Jonathan

Hi Jonathan,

Thanks for your reply !

I did implement it in the python interface and it works very well!

Best,
Taha