Using Acados in a C++ project


I’m about to start using Acados for solving a NMPC problem, and basically all of my model is already written in C++ with libraries written from my team to interface easily with our robot, my idea was to use Acados to solve this optimization problem and taking advantage of all the different solvers implemented in it.

My issue it that I’m a bit lost on how should I proceed, my idea was first to use the C library in my C++ project in order to formulate my problem, convert my model if necessary, and solve it with the acados solver, but I feel it is very tricky to do it in that way, so I better tried some Python examples that I understand more knowing that I could generate C code after that and (In my mind) I would just need to call the C functions in my C++ project.

I would love some tips for getting started, also if I misunderstood the way to proceed with Acados, do not hesitate to tell me, I want to learn. :slight_smile:

Thanks in advance,
Best regards,

Hi Max,

I wrote something here:

You can port your model equations to Python CasADi, generate code from there and embedd it in your C++ framework.
What framework do you use to formulate your model in C++ with derivatives?


Hey Jonathan,

Thanks for the quick answer.
I’m working with ViSP as I work on Visual Servoing, as it provides some useful tools to work with images.
I would like my control law to be computed by a sqp solver, as I want to add some tricky constraints, for each feedback obtained in my image.

For now my model is formulate in a discrete state by a simple Euler discretization (and I do think it will be enough for now) with visp formulation.

Actually, my mpc looks like really simple, the trickiest thing is that all the formulation is made in an other framework, that also provides the visualization and the acquisition part, so in my mind I was thinking that I could just create a box “acados solver” in my c++ code that takes all the variables it needs and gives me the optimized control. And finally I was thinking to create this box through python and generate C-code after that, and implement the C-code directly in my C++.

I was just afraid that my would-like use of Acados is not what it is made for, and that I would first probably better implement a sqp solver like qpOases, OSQP or hpipm (the ones used by Acados basically) directly using the C++ wrapper in it, as it would probably be more friendly with my C++ interface.

Still I think that it might be better to use Acados as it provides lot of interesting features, that I could use in the future.

You know everything, sorry for the story telling ahaha.


Hi Max,

Thanks for sharing your usecase!

Since the OCP solver needs to have the model and its derivatives available, you have the following options:

  • Reimplement the model in CasADi and generate the solver from Python
  • Export a C function of your model with its derivative using your existing framework (ViSP) to be usable within acados with the generic external function interface. See this example:
  • Write an SQP solver yourself using one of the QP solvers you mentioned. In this case, you will of course also need the model with its derivative.

Good luck!

Hi Jo,

Thanks for the several answer, I will give a try to all the options an see what fits me the best.

Eager to share this here after.

Thanks again,