# \[ANN\] LinearMPC.jl: Embedded Model Predictive Control of linear systems

**URL:** https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484
**Category:** Package Announcements
**Tags:** control, optimization, dynamical-systems, controlsystems
**Created:** [April 28, 2025, 11:06am UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484 "2025-04-28T11:06:40Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![darnstrom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darnstrom/32/216558_2.png) [@darnstrom](https://discourse.julialang.org/u/darnstrom)
#### Post date: [April 28, 2025, 11:06am UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484/1 "2025-04-28T11:06:40Z")

</div>

I am developing the package LinearMPC.jl, which is a package for Model Predictive Control (MPC) of linear dynamical systems.

The focus of the package to produce high-performant and lightweight C-code that can easily be used on embedded systems, while at the same time give a user-friendly and expressive development environment for linear MPC.  
It also includes tools for computing explicit MPC controllers, and for certifying the compelxity of implicit MPC controllers before they are deployed on hardware.

A summary of some of the main features:

- Code generation of high-performant, allocation-free, library-free, and lightweight C-code that can be embedded on any micro controller (with the QP solver DAQP).
- State-of-the-art computation of explicit MPC (~100x faster than other software packages such as MPT in MATLAB)
- Tools to determine real-time certificates of the complexity of the solver, allowing for MPC in with guarantees on the memory and computationala requirements before deploying the solver.

The main difference to the excellent package ModelPredictiveControl.jl of @franckgaga & @baggepinnen is that LinearMPC.jl focus on MPC controllers that can be deployed directly on embedded systems, while ModelPredictiveControl.jl is currently more for high-level development of MPCs in Julia with more flexibility (e.g., support for nonlinear MPC).

Any feedback is highly appreciated!

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [April 28, 2025, 11:37am UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484/2 "2025-04-28T11:37:36Z")

</div>

Tjenare, congratulations on the release and welcome to the community! 🙂

I have looked through the code and docs (a few days ago), and would be happy to promote the package from the [ecosystem section in the ControlSystem docs](https://juliacontrol.github.io/ControlSystems.jl/stable/#Ecosystem) if it had a bit more developed documentation and tests.

---

<div class="post-metadata">

### Author: ![darnstrom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darnstrom/32/216558_2.png) [@darnstrom](https://discourse.julialang.org/u/darnstrom)
#### Post date: [April 28, 2025, 11:47am UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484/3 "2025-04-28T11:47:45Z")

</div>

Tackar @baggepinnen 🙂

The docs/tests are indeed lacking a bit… But now when most of the “base functionality” of the package is established, my main focus is on improving that. So in the upcoming days the documentation will be improved!

---

<div class="post-metadata">

### Author: ![pierre-haessig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pierre-haessig/32/217129_2.png) [@pierre-haessig](https://discourse.julialang.org/u/pierre-haessig)
#### Post date: [April 28, 2025, 12:00pm UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484/4 "2025-04-28T12:00:24Z")

</div>

Thanks for sharing this work!

Slightly off-topic, I see that you’re using a custom QP solver [DAQP](https://github.com/darnstrom/daqp). Is this code in the same spirit as the older conic solver [ECOS](https://github.com/embotech/ecos)?

---

<div class="post-metadata">

### Author: ![darnstrom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darnstrom/32/216558_2.png) [@darnstrom](https://discourse.julialang.org/u/darnstrom)
#### Post date: [April 28, 2025, 12:38pm UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484/5 "2025-04-28T12:38:50Z")

</div>

It depends on what you mean with “in the same spirit”, but I would say yes.  
ECOS solves a slightly wider problem class (conic problems), while DAQP focuses on quadratic programs. But both are written in C and are readily embeddable.  
DAQP is for example library-free, allocation-free, square-root-free, which makes it embeddable on any platform with a C compiler (which is basically any target)  
Regarding performance, I tend to get speedups with DAQP that are one or two orders of magnitude faster than ECOS (just to be transparent: I am the developer of DAQP, so I might not be completely unbiased)

If you want some more information on DAQP, you can checkout the corresponding [publication](https://arxiv.org/abs/2103.16236).

---

<div class="post-metadata">

### Author: ![franckgaga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/franckgaga/32/218241_2.png) [@franckgaga](https://discourse.julialang.org/u/franckgaga)
#### Post date: [April 28, 2025, 1:02pm UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484/6 "2025-04-28T13:02:01Z")

</div>

Great Job @darnstrom, both for LinearMPC.jl and DAQP.jl !

About the features:

- Does it support constraint softening ? I don’t see any constraint relaxation term e.g. C\epsilon^2 in the objective function
- I see the the initial state is defined as x\_0 = \hat{x}. There is probably no built-in state estimator in your package, e.g. you assume that all the states are measured? Is there any offset-free tracking mechanism (the integral action)?

At some point I would like to link ModelPredictiveControl.jl with this LinearMPC.jl. The objective would be to offer some code generation functionalities. For sure it would be limited in feature (no nonlinear MPC and only DAQP solver), but that’s generally expected for code generation.

Keep up the good work!

---

<div class="post-metadata">

### Author: ![darnstrom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darnstrom/32/216558_2.png) [@darnstrom](https://discourse.julialang.org/u/darnstrom)
#### Post date: [April 28, 2025, 1:21pm UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484/7 "2025-04-28T13:21:26Z")

</div>

Thank you @franckgaga, and great job with ModelPredictiveControl.jl!

Yes, it supports soft constraints (I will add information about this in the documentation.)  
Actually, DAQP internally handles soft constraints in a very efficient manner (might publish something on this in another context soon)

The problem formulation in the README is just a simplified version to make it more readable. Some things supported in the package, but that are not documented yet:

- Soft constraints
- Prestabilizing feedback
- Move blocking
- Binary controls (so hybrid systems can be handled)
- Measured disturbances
- Prioritized constraints (when I release DAQP v0.7.0)

The measured disturbances relates to offset-free tracking.

Currently, it assumes full state measurements. So an observer need to be provided from another package (I don’t plan on providing an observer to keep the focus of the package on LMPC, rather than the observer.) In the end the `compute_control` function takes in `x`, which can be provided by any state estimator.

I have also been thinking about linking ModelPredictiveControl.jl with LinearMPC.jl. In addition to code generation, I think the explicit MPC support could be nice (since only constraint-free explicit MPC is currently supported in ModelPredictiveControl.jl)  
I have been putting of this linking until the basic interface/internals of LinearMPC.jl have converged . But I think that the package is soon in a state to start this linking. Let’s discuss this more at some point!

---

<div class="post-metadata">

### Author: ![pierre-haessig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pierre-haessig/32/217129_2.png) [@pierre-haessig](https://discourse.julialang.org/u/pierre-haessig)
#### Post date: [April 28, 2025, 2:27pm UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484/8 "2025-04-28T14:27:03Z")

</div>

OK that’s what I thought with “in the same spirit”: close to bare metal micro controller implementation.

Also it’s good to know that you have observed “one or two orders of magnitude” of faster solving speed versus ECOS. I’ll keep this in my mental library.

---

<div class="post-metadata">

### Author: ![darnstrom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darnstrom/32/216558_2.png) [@darnstrom](https://discourse.julialang.org/u/darnstrom)
#### Post date: [July 17, 2025, 11:55am UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484/9 "2025-07-17T11:55:28Z")

</div>

## v0.5.0

v0.5.0 of LinearMPC.jl has just been released.  
Since the previous annoucement, the documentation has been improved significantly. Hopefully this should make it easier for new users to try it out. Have a look here.

A selection of some new features that has been added since the previous annoucmenet:

- Faster and more reliable code generation for Explicit MPC.
- Support for hybrid MPC (i.e., some of the controls/states can be restricted to take binary values)
- Support for reference preview (thanks @baggepinnen for this contribution)

The work on improving the docs will continue, and there are several new features on the horizon! Any feedback is, as always, highly appreciated.

---

<div class="post-metadata">

### Author: ![franckgaga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/franckgaga/32/218241_2.png) [@franckgaga](https://discourse.julialang.org/u/franckgaga)
#### Post date: [July 17, 2025, 1:36pm UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484/10 "2025-07-17T13:36:32Z")

</div>

Good job ! Minor comment, the equations here and here are hard to read in the dark theme:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/7/b73ed53203a3b48546b4413d9041414e71e72be6.png)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/a/0a3dc5fb988cafdc9e43acc974ba8a0b80415838.png)

---

<div class="post-metadata">

### Author: ![darnstrom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darnstrom/32/216558_2.png) [@darnstrom](https://discourse.julialang.org/u/darnstrom)
#### Post date: [April 8, 2026, 10:48pm UTC](https://discourse.julialang.org/t/ann-linearmpc-jl-embedded-model-predictive-control-of-linear-systems/128484/11 "2026-04-08T22:48:45Z")

</div>

Some highlights of features in v0.9.0 of LinearMPC.jl that have been added since v0.5.0:

- The code generation now also supports observers
- Robust MPC - optimal a priori constraint tightening
- Game-theoretic objectives
- Time-varying linear cost

The documentation continues to be improved (feedback is always appreciated!)

Comparisons with alternative packages that supports code generations have also been started. Some initial results can be seen here: [Benchmark · LinearMPC.jl](https://darnstrom.github.io/LinearMPC.jl/dev/manual/benchmark/)
