Interfaces
Classes
| Class name | Description |
|---|---|
OptimalControlProblem |
Create an OCP |
NMPCSolver |
Configurate the solver |
OCPSolver |
Solve the very first OCP |
DynamicSystem |
Create a dynamic system |
OptimalControlProblem
Formulate an OCP.
Example
./NMPC_Problem_Formulation.m
| Properties | Description |
|---|---|
dim |
structure.{lambda,mu,u;x;p}, dimensions of lambda, mu, u, x, p. |
lambda |
symbolic vector, multiplier vector. |
mu |
symbolic vector, multiplier vector. |
u |
symbolic vector, input vector. |
x |
symbolic vector, state vector. |
p |
symbolic vector, parameter vector. |
f |
symbolic expression, function f. |
M |
symbolic expression, matrix M . |
L |
symbolic expression, function L. |
C |
symbolic expression, function C. |
N |
[1,1], number of discretization grids N. |
T |
[1,1], prediction horizon T. |
deltaTau |
[1,1], discretization size (T/N). |
discretizationMethod |
string, discretization method. |
isMEnabled |
bool, whether the M matrix is enabled. |
| Functions | Description |
|---|---|
OptimalControlProblem |
Constructor. Input: muDim: [1,1], dimension of mu.uDim: [1,1], dimension of u.xDim: [1,1], dimension of x.pDim: [1,1], dimension of p.T: [1,1], prediction horizon.N: [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, function L.Output: none. |
setC |
Set C. Input: C: symbolic expression, 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. |
setDiscretizationMethod |
Set the discretization method. Input: method: string, 'Euler' 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', method of Hessian approximation.Output: none |
codeGen |
Generate necessary files. Input: none. Output: none. |
OCPSolver
Solve the very first OCP offline.
Example
./NMPC_Problem_Formulation.m
| Properties | Description |
|---|---|
OCP |
OptimalControlProblem, OptimalControlProblem object. |
NMPCSolver |
NMPCSolver, NMPCSolver object. |
x0 |
[xDim,1], initial state. |
lambda |
[xDim,N], multipliers. |
mu |
[muDim,N], multipliers. |
u |
[uDim,N], inputs. |
x |
[xDim,N], states. |
p |
[pDim,N], given parameters. |
LAMBDA |
[xDim,xDim,N], dependent variable LAMBDA. |
| Functions | Description |
|---|---|
OCPSolver |
Constructor. Input: OCP: OptimalControlProblem, OptimalControlProblem object.NMPCSolver: NMPCSolver, NMPCSolver object.x0: [xDim,1], initial state.pVal: [pDim,N], given parameters.Output: OCPSolver |
OCPSolve |
Solve the OCP with a providing initial guess offline. Input: lambdaInitGuess: [xDim,N], initial guess of lambda.muInitGuess: [muDim,N], initial guess of mu.uInitGuess: [uDim,N], initial guess of u.xInitGuess: [xDim,N], initial guess of x.method: string, 'fsolve' or 'NMPC_Iter_GaussNewton', solver.Output: lambda: [xDim,N], optimal value of lambda.mu: [muDim,N], optimal value of mu.u: [uDim,N], optimal value of u.x: [xDim,N], optimal value of x. |
initFromMatFile |
Initialize from file with automatic interpolation. Input: matFile: string, file name of the mat file.Output: lambda: [xDim,N], interpolated value of lambda.mu: [muDim,N], interpolated value of mu.u: [uDim,N], interpolated value of u.x: [xDim,N], interpolated value of x. |
initFromStartEnd |
Initialize from the start and the end values by linear interpolation. Input: lambdaStart: [xDim,1], start value of lambda.muStart: [muDim,1], start value of mu.uStart: [uDim,1], start value of u.xStart: [xDim,1], start value of x.lambdaEnd: [xDim,1], end value of lambda.muEnd: [muDim,1], end value of mu.uEnd: [uDim,1], end value of u.xEnd: [xDim,1], end value of x.method: string, 'fsolve' or 'NMPC_Iter_GaussNewton', solver.Output: lambda: [xDim,N], interpolated value of lambda.mu: [muDim,N], interpolated value of mu.u: [uDim,N], interpolated value of u.x: [xDim,N], interpolated value of x. |
getLAMBDA |
Get the dependent variable LAMBDA from the given x0, lambda, mu, u, x, p. Input: x0: [xDim,1], initial state.lambda: [xDim,N], lambda.mu: [muDim,N], mu.u: [uDim,N], u.x: [xDim,N], x.p: [pDim,N], p.Output: LAMBDA: [xDim,xDim,N] |
getCost |
Get the cost function from the given u, x, p. Input: u: [uDim,N], u.x: [xDim,N], x.p: [pDim,N], p.Output: cost: [1,1] |
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, input vector. |
x |
symbolic vector, state vector. |
p |
symbolic vector, parameter vector. |
f |
symbolic expression, function f. |
M |
symbolic expression, matrix M . |
isMEnabled |
bool, whether the M matrix is enabled. |
| Functions | Description |
|---|---|
DynamicSystem |
Constructor. Input: uDim: [1,1], dimension of u.xDim: [1,1], dimension of x.pDim: [1,1], dimension of p.Output: DynamicSystem |
setf |
Set f. Input: f: symbolic expression, function f.Output: none. |
setM |
Set M. Input: M: symbolic expression, 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_Iter |
Perform one iteration for solving the KKT conditions. |
NMPC_Iter_CodeGen |
Generate code for function NMPC_Iter. |
SIM_Plant_RK4 |
Simulate the dynamic system using the 4-order Runge-Kutta method. |
Timer |
Specify your own timer function. |
NMPC_Iter
Example
./Simu_Matlab.m
| Function name | NMPC_Iter |
|---|---|
| Description | Perform one iteration to solve the KKT conditions. |
| Input | x0: [xDim,1], initial state.lambda: [xDim,N/DoP,DoP].mu: [muDim,N/DoP,DoP].u: [uDim,N/DoP,DoP].x: [xDim,N/DoP,DoP].p: [pDim,N/DoP,DoP], given parameters.LAMBDA: [xDim,xDim,N/DoP,DoP].discretizationMethod: string, 'Euler' or 'RK4'.isMEnabled: bool. |
| Output | lambda: [xDim,N/DoP,DoP].mu: [muDim,N/DoP,DoP].u: [uDim,N/DoP,DoP].x: [xDim,N/DoP,DoP].LAMBDA: [xDim,xDim,N/DoP,DoP].cost: [1,1], evaluation of the cost function after iteration.error: [1,1], Euclidean norm of the KKT conditions.timeElapsed: [1,1], computation time. |
NMPC_Iter_CodeGen
Example
./Simu_Simulink_Setup.m
| Function name | NMPC_Iter_CodeGen |
|---|---|
| Description | Generate code for function NMPC_Iter. |
| Input | target: string, 'mex', 'dll', or 'mex'.targetLang: string, 'C' or 'C++'.args: cell, arguments applied to NMPC_Iter. |
| Output | None |
SIM_Plant_RK4
Example
./Simu_Matlab.m
| Function name | SIM_Plant_RK4 |
|---|---|
| Description | Simulate the dynamic system using the 4-order Runge-Kutta method. |
| Input | u: [uDim,1], inputs applied to the plant.x: [xDim,1], current state of the plant.p: [pDim,1], given parameters.Ts: [1,1], sampling interval. |
| Output | xNext: [xDim,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. |