Installation
- Clone or download
ParNMPC
from Github: ParNMPC. -
Extract the downloaded file.
Requirements
ParNMPC
supports MATLAB R2016a or later, and requires the following tools:- MATLAB Coder
- MATLAB Optimization Toolbox
- MATLAB Parallel Computing Toolbox
- MATLAB Symbolic Math Toolbox
- C/C++ compiler supporting parallel code generation
For compilers that do not support OpenMP, code generation will treat parallel computing as serial computing. Check Supported and Compatible Compilers for details.
Warning
ParNMPC
may not work properly on MATLAB R2017b and R2018a because of the bug that exists in certain Windows 10 builds. Check sym bug report for details.
File Layout
The file layout of ParNMPC
looks like this:
ParNMPC/ % The toolkit folder. docs/ % The documents folder. SemiActiveDamper/ % Example of controlling a semi-active damper. NMPC_Problem_Formulation.m % NMPC formulation and initialization. Simu_Matlab.m % Closed-loop simulation in MATLAB. Simu_Simulink.slx % Closed-loop simulation in Simulink. Simu_Simulink_Setup.m % Setup for the Simulink simulation. Timer.m % Your own timer function. GEN_initData.mat % Initial guess DoubleInvertedPendulum/ % Example of swinging up a double inverted pendulum on a cart. ... % Files Quadrotor/ % Example of controlling a quadrotor. ... % Files
Getting Started
This section shows how to do the closed-loop simulation in Simulink using MATLAB R2016a and Microsoft Visual C++ 2015 Professional as an example.
-
Run the following MATLAB command and select the Microsoft Visual C++ 2015 Professional (C) compiler:
>> mex -setup
-
Navigate to the Quadrotor/ folder.
>> cd Quadrotor/
-
Open
NMPC_Problem_Formulation.m
and run. By running this file, the following things are done:- The NMPC controller is defined and configured, and necessary files are automatically generated to the
./funcgen/
and./codegen/
folders. - The very first OCP is solved and its solution is saved to
GEN_initData.mat
. - The controlled plant for simulation is defined and auto-generated.
- The NMPC controller is defined and configured, and necessary files are automatically generated to the
-
Open
Simu_Simulink_Setup.m
and run. By doing this, the NMPC controller is generated into C codes and compilied into a DLL file. -
Open
Simu_Simulink.slx
and run.Simu_Simulink.slx
calls the generated NMPC controller function from the DLL file.Warning
Running
Simu_Matlab.m
directly is not in parallel.