berlala / pyMPC

A Model Predictive Control (MPC) Python library based on the OSQP solver.

Home Page:http://www.marcoforgione.it/pyMPC

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pyMPC

Linear Constrained Model Predictive Control (MPC) in Python:

where

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

  1. 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

  1. 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:

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: marco.forgione@idsia.ch

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}
}

About

A Model Predictive Control (MPC) Python library based on the OSQP solver.

http://www.marcoforgione.it/pyMPC

License:MIT License


Languages

Language:Python 66.9%Language:Jupyter Notebook 32.2%Language:MATLAB 0.9%