Open ufechner7 opened 2 days ago
There is no code generation from this package yet, and it's not a small task to implement. One possible way forward is to use the code-generation capabilities of an existing MPC package with this feature, such as acados. I have a proof-of-concept doing that here https://github.com/baggepinnen/AcadosInterface.jl You would have to manually create the acados problem by passing the same cost matrices to acados as you do to MPC.jl, but this should be quite straightforward. It's limited to things that are easy to express in both Symbolics.jl and CasADi, so it does not accept any arbitrary dynamics.
One issue with code generation in general is how it can be hard to exactly reproduce results. I expect to see difference between MPC.jl results and the Acados interface (different solvers, state estimators, linear algebra libraries, etc.). Hopefully, these differences will be negligible for well-conditioned problems.
In the end code generation is just another form of the two-language problem. It may be kind of a long shot prediction, but I think the future of MPC lies in more advanced control hardware, like a full-fledge computer or server instead of embedded platform. Micro-controllers and PLCs computational capabilities are more than enough for PIDs, but the layers of complexity in MPC (solvers, automatic differentiation libraries, linear algebra libraries, etc.) clearly benefits from Julia's modern features like the composability, the package manager, etc.
Still, code generation features for this package would be extremely useful right now!
What would be the way forward to become able to run an MPC controller on a small microcontroller?
Other packages implement C code generation. Would that be possible, or what could be alternatives?