Interfaces
Classes
Class name | Description |
---|---|
OptimalControlProblem |
Formulate an OCP |
NMPCSolver |
Configurate the NMPC solver |
DynamicSystem |
Construct a dynamic system |
OptimalControlProblem
Formulate an OCP.
Example
./NMPC_Problem_Formulation.m
Properties | Description |
---|---|
dim |
structure.{lambda,mu,u,x,z,p} , dimensions of lambda, mu, u, x, z, p. |
lambda |
symbolic vector [dim.x,1] , multiplier vector. |
mu |
symbolic vector [dim.mu,1] , multiplier vector. |
u |
symbolic vector [dim.u,1] , input vector. |
x |
symbolic vector [dim.x,1] , state vector. |
z |
symbolic vector [zDim,1] , multiplier vector. |
p |
symbolic vector [pDim,1] , parameter vector. |
f |
symbolic expression [dim.x,1] , function f. |
M |
symbolic expression [dim.x,dim.x] , matrix M . |
L |
symbolic expression [1,1] , function L. |
C |
symbolic expression [dim.mu,1] , function C. |
G |
symbolic expression [dim.z,1] , function G. |
N |
positive integer [1,1] , number of discretization grids N. |
T |
positive [1,1] , prediction horizon T. |
deltaTau |
positive [1,1] , discretization size (T/N). |
discretizationMethod |
string , discretization method. |
isMEnabled |
bool , whether the M matrix is enabled. |
Functions | Description |
---|---|
OptimalControlProblem |
Constructor. Input: dim.u : positive integer [1,1] , dimension of u.dim.x : positive integer [1,1] , dimension of x.pDim : nonnegtive integer [1,1] , dimension of p.N : positive integer [1,1] , number of discretization grids.Output: OptimalControlProblem |
setf |
Set f. Inherit from DynamicSystem |
setM |
Set M. Inherit from DynamicSystem |
setStateName |
Give names to all or part of the states. Inherit from DynamicSystem |
setInputName |
Give names to all or part of the inputs. Inherit from DynamicSystem |
setParameterName |
Give names to all or part of the parameters. Inherit from DynamicSystem |
setL |
Set L. Input: L : symbolic expression [1,1] , function L.Output: none. |
setC |
Set C. Input: C : symbolic expression [dim.mu,1] , function C.Output: none. |
setT |
Set T. Input: T : symbolic variable/double [1,1] , must be included in p if it is a symbolic variable.Output: none. |
setG |
Set G. Input: C : symbolic expression [dim.z,1] , function G.Output: none. |
setDiscretizationMethod |
Set the discretization method. Input: method : string , 'Euler' , 'RK2' , or 'RK4' , discretization method.Output: none |
codeGen |
Generate necessary files. Input: none. Output: none. |
NMPCSolver
Configurate the NMPC solver.
Example
./NMPC_Problem_Formulation.m
Properties | Description |
---|---|
OCP |
OptimalControlProblem , OptimalControlProblem object. |
HessianApproximation |
string , Hessian approximation method. |
Functions | Description |
---|---|
NMPCSolver |
Constructor. Input: OCP : OptimalControlProblem , OptimalControlProblem object.Output: NMPCSolver |
setHessianApproximation |
Set the Hessian approximation method. Input: method : string , 'Newton' , 'GaussNewton' , or 'GaussNewtonLC' , Hessian approximation method.Output: none |
codeGen |
Generate necessary files. Input: none. Output: none. |
DynamicSystem
Construct a dynamic system M(u(t),x(t),p(t))\dot{x}=f(u(t),x(t),p(t)).
Example
./NMPC_Problem_Formulation.m
Properties | Description |
---|---|
dim |
structure.{u;x;p} , dimensions of u, x, p. |
u |
symbolic vector [dim.u,1] , input vector. |
x |
symbolic vector [dim.x,1] , state vector. |
p |
symbolic vector [pDim,1] , parameter vector. |
f |
symbolic expression [dim.x,1] , function f. |
M |
symbolic expression [dim.x,dim.x] , matrix M . |
isMEnabled |
bool , whether the M matrix is enabled. |
Functions | Description |
---|---|
DynamicSystem |
Constructor. Input: dim.u : [1,1] , dimension of u.dim.x : [1,1] , dimension of x.pDim : [1,1] , dimension of p.Output: DynamicSystem |
setf |
Set f. Input: f : symbolic expression [dim.x,1] , function f.Output: none. |
setM |
Set M. Input: M : symbolic expression [dim.x,dim.x] , M matrix.Output: none. |
setStateName |
Give names to all or part of the states. Example: [X,Y,Z] =~.setStateName({'X','Y','Z'}); [X,Z] =~.setStateName({'X','Z'},[1 3]); |
setInputName |
Give names to all or part of the inputs. Example: [F1,F2,F3] =~.setInputName({'F1','F2','F3'}; [F1,F3] =~.setInputName({'F1','F3'},[1 3]); |
setParameterName |
Give names to all or part of the parameters. Example: [a,b,c] =~.setParameterName({'a','b','c'}; [a,c] =~.setParameterName({'a','c'},[1 3]); |
codeGen |
Generate necessary files. Input: none. Output: none. |
Functions
Function name | Description |
---|---|
NMPC_Solve |
Solve the NMPC problem. |
createOptions |
Create an option struct for NMPC_Solve . |
NMPC_Solve_CodeGen |
Generate code for NMPC_Solve . |
SIM_Plant_RK4 |
Simulate the dynamic system using the 4-th order Runge-Kutta method. |
Timer |
Measure the current time. |
NMPC_Solve
Example
./Simu_Matlab.m
Function name | NMPC_Solve |
---|---|
Description | Solve the NMPC problem. |
Input | x0 : [dim.x,1] , initial state.p : [pDim,N] , given parameters.options : struct , options. |
Output | solution : struct , solution.output : struct , output information. |
createOptions
Example
./Simu_Matlab.m
Function name | createOptions |
---|---|
Description | Create an option struct for NMPC_Solve . |
Input | None |
Output | options : struct , options. |
NMPC_Solve_CodeGen
Example
./Simu_Simulink_Setup.m
Function name | NMPC_Solve_CodeGen |
---|---|
Description | Generate code for function NMPC_Solve . |
Input | target : string , 'mex' , 'dll' , or 'mex' , target.targetLang : string , 'C' or 'C++ ', target language.options : struct , options. |
Output | None |
SIM_Plant_RK4
Example
./Simu_Matlab.m
Function name | SIM_Plant_RK4 |
---|---|
Description | Simulate the dynamic system using the 4-th order Runge-Kutta method. |
Input | u : [dim.u,1] , inputs applied to the plant.x : [dim.x,1] , current state of the plant.p : [pDim,1] , given parameters.Ts : positive [1,1] , sampling interval. |
Output | xNext : [dim.x,1] , next state of the plant. |
Timer
Example
./Timer.m
Function name | Timer |
---|---|
Description | Measure the current time. |
Input | None |
Output | t : [1,1] , current time. |
Statement | Create Timer.m in the working directory to specify your own timer function. |