Skip to content

Code generation #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ufechner7 opened this issue Nov 11, 2024 · 5 comments
Open

Code generation #124

ufechner7 opened this issue Nov 11, 2024 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ufechner7
Copy link

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?

@baggepinnen
Copy link
Member

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.

@franckgaga
Copy link
Member

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!

@franckgaga franckgaga added enhancement New feature or request help wanted Extra attention is needed labels Feb 28, 2025
@1-Bart-1
Copy link

I agree with @franckgaga in that the future of MPC probably is not on small embedded systems. A small Linux computer is cheap, can run more complex models and can compile and run the Julia code. The main advantage of Julia is the ability to write easily-readable code that is fast as well. Generating C code in Julia defeats this purpose.

@baggepinnen
Copy link
Member

Here's a new MPC package in julia that supports C codegen
https://github.com/darnstrom/LinearMPC.jl
the docs are sparse and the level of testing isn't very high yet, but it could turn into something nice eventually if the author keeps working on it

@franckgaga
Copy link
Member

Yes It would be a simpler option than ACADOS, and it is generally expected that codegen only support a subset of the features. So if only DAQP solver is supported that would be okay IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants