pyMPC¶
A python library for Model Predictive Control¶
pyMPC is an open-source python library for Model Predictive Control (MPC). The project is hosted on this GitHub repository.
Requirements¶
As a bare minimum, you will need a python 3.x environment with:
All dependencies should be installed automatically following the pyMPC installation instructions below
Installation¶
- Copy or clone the pyMPC project into a local folder. For instance, run
git clone https://github.com/forgi86/pyMPC.git
from the command line
- Navigate to your local pyMPC folder
cd PYMPC_LOCAL_FOLDER
where PYMPC_LOCAL_FOLDER is the folder where you have downloaded the code in step 2
- Install pyMPC in your python environment: run
pip install -e .
from the command line, in the working folder PYMPC_LOCAL_FOLDER
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