Skip to content

affine_mpc

affine_mpc is a library for model predictive control of discrete-time affine systems, with C++ and Python interfaces. It provides condensed and sparse MPC formulations, input trajectory parameterization through B-splines, OSQP-backed solves, and binary logging for simulation and analysis workflows.

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.

Start Here

If you are new to the project, the shortest path is:

  1. Read Concepts for the supported problem class.
  2. Choose Python or C++.
  3. Run the mass-spring-damper walkthrough in Examples.
  4. Inspect the generated outputs in Logging.

To contribute, see Development.

Choose Python if you want fast iteration, NumPy-based analysis, notebooks, or teaching workflows. Choose C++ if you want native integration, tighter runtime control, or lower-overhead deployment.

Core Workflow

No matter which interface you use, the main workflow is the same:

  1. Choose a Parameterization
  2. Select desired Options
  3. Construct CondensedMPC or SparseMPC
  4. Set model, limits, weights, and references
  5. Call initializeSolver()
  6. Call solve(...) in a loop
  7. Retrieve inputs and predicted trajectories
  8. Optionally log results with MPCLogger