pyMPC
Linear Constrained Model Predictive Control (MPC) in Python:
Requirements
pyMPC requires the following packages:
- numpy
- scipy
- OSQP
- matplotlib
Installation
Stable version from PyPI
Run the command
pip install python-mpc
This will install the stable version of pyMPC from the PyPI package repository.
Latest version from GitHub
- Get a local copy the pyMPC project. For instance, run
git clone https://github.com/forgi86/pyMPC.git
in a terminal to clone the project using git. Alternatively, download the zipped pyMPC project from this link and extract it in a local folder
- Install pyMPC by running
pip install -e .
in the pyMPC project root folder (where the file setup.py is located).
Supported platforms
We successfully tested pyMPC on the following platforms:
- Windows 10 on a PC with x86-64 CPU
- Ubuntu 18.04 LTS on a PC with x86-64 CPU
- Raspbian Buster on a Raspberry PI 3 rev B
Detailed instructions for the Raspberry PI platform are available here.
Usage
This code snippets illustrates the use of the MPCController class:
from pyMPC.mpc import MPCController
K = MPCController(Ad,Bd,Np=20, x0=x0,xref=xref,uminus1=uminus1,
Qx=Qx, QxN=QxN, Qu=Qu,QDu=QDu,
xmin=xmin,xmax=xmax,umin=umin,umax=umax,Dumin=Dumin,Dumax=Dumax)
K.setup()
...
xstep = x0
for i in range(nsim):
uMPC = K.output()
xstep = Ad.dot(xstep) + Bd.dot(uMPC) # system simulation steps
K.update(xstep) # update with measurement
Full working examples are given in the examples folder:
- Point mass with input force and friction
- Inverted pendulum on a cart
- Inverted pendulum on a cart with kalman filter
Contributing
I am slowly adding new functionalities to pyMPC according to my research needs. If you also wanna contribute, feel free to write me an email: [email protected]
Citing
If you find this project useful, we encourage you to
- Star this repository
โญ - Cite the paper
@inproceedings{forgione2020efficient,
title={Efficient Calibration of Embedded {MPC}},
author={Forgione, Marco and Piga, Dario and Bemporad, Alberto},
booktitle={Proc. of the 21st IFAC World Congress 2020, Berlin, Germany, July 12-17 2020},
year={2020}
}