-
Notifications
You must be signed in to change notification settings - Fork 10
Home
We present a multipurpose, easy-to-use code for Model Predictive Control (MPC) design, analysis and simulation. The major goal of this code is to provide the user with a general, versatile MPC framework that can be adapted to problems in different areas, e.g. process control, robotics, aerospace. Many different MPC simulation problems can be easily studied with this code, given the following features:
- The MPC model can be linear or non-linear, discrete and continuous time.
- The same possibilities apply to the controlled process, which can also be selected equal to the MPC model for nominal simulation cases.
- The finite-horizon cost function can be quadratic as in standard (tracking) MPC problems or any (linear or nonlinear) function, e.g. to consider economic MPC problems. In addition, it can be defined as the sum of discrete-time stage cost terms or the integral of a continuous-time running cost.
- A target calculation module is also available, with simple quadratic or generic cost function.
- State feedback or output feedback can be considered, and in the latter case several choices of linear and nonlinear observers are made available.
- In all cases the user can activate the “offset-free” design option, to implement a linear or non-linear disturbance model, and an associated augmented observer.
The code has been implemented in Python, using CasADi 3.4, and its architecture is rather simple: the basic idea is to have a main file containing all the MPC core functions. Everything else, such as model or cost functions, steady-state and dynamic optimization problems, state estimation, is made in separate Python scripts. In this way the architecture is somehow modular and easier to develop and to further customize.
For each case to simulate, the user has to fill in a single Python script with all the required information such as matrices or functions describing the state dynamics and cost terms, MPC horizon, simulation horizon, time step, etc. Several boolean variables are provided to help the user with the problem definition, e.g. state-feedback, nominal case, continuous cost function. Finally, there is also the possibility to specify which offset-free disturbance model applies by simply changing a name tag.
It is developed by Marco Vaccari at the Department of Civil and Industrial Engineering of University of Pisa under supervision of Prof. Gabriele Pannocchia. MPC Code is distributed under the LGPL license, meaning the code can be used royalty-free even in commercial applications.
To use MPC Code, you will need a recent versions of
- Python 2.7 or >= 3.6 (Download it here)
- Numpy
- Scipy
- Matplotlib
- CasADi (Version >=3.0. Download it here)
- Future (See installation instruction here)
The program has been originally written for Python 2.7 and then updated with Python > = 3.6, and CasADi 3.1 (both are supported on Windows \ Linux \ Mac). Installing CasADi will give you already Python 2.7 or 3.6 (depending on the chosen version), and all the other required packages. In the case where Scypy and Numpy are not included in your Python installation package, you can download it here.
The MPC_code is distributed as packed file MPC_code.zip (download it from here) that contains the following items:
-
User_Guide.pdf: documentation for MPC_code usage. It provides a full list of examples and options to a complte usage of the code -
MPC_code.py: main file that has to be run -
Targ_calc.py: it contains the steady-state target optimization module -
Control_calc.py: it contains the dynamic optimization module -
Estimator.py: it contains all the possible state estimators -
Utilities.py: it contains many functions used in all the other modules -
Default_Values.py: it contains the default values of many options the user can specify in the example file -
SS_JAC_ID.py:it contains a tool for an automatic system linearization -
Ex_LMPC.py: example of linear MPC. It represents the case where both the model and the process maps are linear -
Ex_LMPC_nlplant.py: example of linear controller MPC and non-linear process equations. The linear controller model has been implemented with linearization matrices and corresponding parameters -
Ex_LMPCxp_plant.py: example of linear controller MPC and non-linear process equations where model and process have a different number of states -
Ex_NMPC.py: example of non-linear MPC. It represents the case where both the model and the process maps are non-linear -
Ex_NMPC_dis.py: example of non-linear MPC. It represents the case where both the model and the process maps are non-linear where the state maps are in discrete-time for both the process and the model; -
Ex_ENMPC.py: example of non-linear economic MPC. It represents the case where the model, the process maps and also the optimization modules objective functions are non-linear.
First of all, unpack the zip file and put everything into a folder. In order to run a simulation for the default examples given, write the name of the file to test (i.e. Ex_LMPC.py) in the following line in MPC_code.py:
ex_name = __import__(’Ex_LMPC’)
To clarify better, a line identified by the comment “Insert here your file name" indicates the exact place at the top of the file. Note also that the extension “.py" is not required.
Once set the file name for the wanted file, just run the Python script MPC_code.py to start the simulation.
When, instead, you want to create a file (new, or starting from one of the given examples), i.e. “Ex_1.py"; remember to copy all the import lines present at the top of each given examples. As said above, after preparing the test file, write its name in the MPC_code.py with the following line:
ex_name = __import__(’your_relative_path/Ex_1’)
The ‘your_relative_path’ string identifies the relative path where the Ex_1.py can be found in your disc respect to MPC_code.py. If the file Ex_1.py is in the same folder of MPC_code.py there is no need to add any path before its name.
Since MPC Code uses CasADi, you should cite CasADi as described here. In addition, You can cite MPC Code as
M. Vaccari, G. Pannocchia, A multipurpose, easy-to-use Model Predictive Control design and simulation code, in: Proceedings of the 4th European Conference on Computational Optimization EUCCO, Leuven, Belgium, 2016. https://github.com/mvaccariunipi/MPC-code
For any question, comment, or bug report please refer to the issue tracker on GitHub. Further communication can be held with:
Marco Vaccari [email protected]
University of Pisa, Department of Chemical Engineering