affine_mpc¶
affine_mpc is a library for model predictive control (MPC) of discrete-time affine systems,
with C++ and Python interfaces.
What It Supports¶
- Discrete-time affine time-invariant models
- Finite-horizon tracking MPC
- Condensed and sparse formulations
- Input parameterization with move-blocking, linear interpolation, B-splines, or a custom basis (e.g. Laguerre functions)
- Input limits enforced on the control points or the sampled inputs
- Optional input and input-rate costs, per-sample slew-rate bounds, hard or soft state bounds, and general and terminal linear constraints
- OSQP as the QP solver, with DAQP as an optional dense solver
- Repeated-solve workflows with runtime updates
- Binary logging, read in Python with
load_log()for simulation and analysis
What It Is Not¶
affine_mpc solves one convex QP per time step for a model you provide, so some related tools are out of scope:
- Nonlinear programming. The prediction model is affine (linear plus a constant offset), so each step is a convex QP, not a nonlinear program. For a nonlinear plant, compute an affine approximation yourself (by hand, Eigen AutoDiff, CasADi, or JAX) about an operating point or the current trajectory and update the model between solves. The library does not differentiate models or iterate on the approximation within a time step.
- Explicit MPC. The QP is solved online at every step; no offline partition of the state space or lookup table is computed.
- State estimation.
solve()takes the current state as given. Observers, Kalman filters, and disturbance estimators are up to you (see Modeling Patterns for how to use a disturbance estimate). - A general optimization toolkit. The cost and constraint structure is fixed (see Concepts), and the QP solvers are OSQP and, for the condensed formulation, DAQP.
Choose Your Path¶
- Getting Started: install the library and run a first example
- Concepts: understand the supported problem class and mathematical structure
- Usage: learn the API workflow for configuring and solving MPC problems
Who It Is For¶
affine_mpc is aimed at researchers, students, and engineers who want a focused MPC library rather than a general optimization toolkit.
The Python interface is convenient for experimentation, analysis, and teaching.
The C++ interface is better suited for integration into performance-sensitive applications.
It is intended to lower the barrier to developing MPC controllers for discrete-time affine systems by packaging common formulations, constraints, and workflows into a focused library.
Contributing¶
For repository structure, testing, and contribution workflow, see Development.