-
Notifications
You must be signed in to change notification settings - Fork 2
Models
- Parameter-variant systems
- Fast Linear Representation
- Fast representation for nonlinear (parameter-variant) systems
- Using a Model
- Internal Model Represenation
A model is a symbolic representation of the state trajectory over the horizon, together with a symbolic representation of the input u and the disturbances d. A model is defined by a set of ordinary difference equations for the states that yield
Hence, in PARODIS, a model is described by a function, that returns these ODEs in terms of a given sample time along with the number of states, inputs and disturbances
[ode, n_x, n_u, n_d] = my_model_fun(T_s)
The ODE that is returned must be a function handle, which takes three inputs
- The state
$x(k)$ - The input
$u(k)$ - The disturbance
$d(k)$
and returns the resulting state
x_kp = @(x_k, u_k, d_k)( .. )
The following code shows an examplary nonlinear model:
function [ode, n_x, n_u, n_d] = my_model_fun(T_s)
ode = @(x, u, d)( [ x(1)^2 + u(1) + sin(d(1)); ...
x(2) + u(2) + cos(d(2)) ] );
n_x = 2;
n_u = 2;
n_d = 2;
end
PARODIS also supports parameter-variant (nonlinear) models. For a parameter-variant system, the ODEs can take a fourth and fifth argument, namely the time step within the horizon n
and the struct of available parameters params
x_kp = @(x_k, u_k, d_k, n, params)( .. )
function [ode, n_x, n_u, n_d] = my_model_fun(T_s)
ode = @(x, u, d, n, params)( ...
[ params.friction(n) * x(1)^2 + u(1) + sin(d(1)); ...
x(2) + u(2) + cos(d(2)) ] ...
);
n_x = 2;
n_u = 2;
n_d = 2;
end
These ODEs are used for building constraints, as well as calculating the predicted state trajectory over a given prediction horizon. For larger, linear systems this representation is rather inefficient, as the calculation of the predicted trajectory can be contracted into equivalent matrix-vector multiplications. Also, in some special cases, it may be possible to express the entire state trajectory efficiently, instead of splitting it into single ODEs.
Therefore, PARODIS supports two special cases:
Linear systems of the form
function [ode, n_x, n_u, n_d, linearRepresentation] = test_model(T_s)
A = diag([ 0.1 0.05 1.01 ]);
B = [1 0; 0 1; 1 1];
S = diag([2 2 2]);
% always required!
ode = @(x, u, d)( A*x + B*u + S*d );
n_x = 3;
n_u = 2;
n_d = 3;
% additional linear representation
linearRepresentation = struct;
linearRepresentation.A = A;
linearRepresentation.B = B;
linearRepresentation.S = S;
end
PARODIS will use these matrices to built a fast linear representation (FLR) of the system dynamics which is then used whenever the state trajectory over the horizon is calculated.
If the linear system is parameter variant, the matrices n
and the struct of available parameters params
function [ode, n_x, n_u, n_d, linearRepresentation] = test_model(T_s)
% parameter-variant system description
A = @(n, params)( diag([ params.friction(n) 0.05 1.01 ]) );
B = [1 0; 0 1; 1 1];
S = diag([2 2 2]);
% always required!
ode = @(x, u, d, n, params)( A(n, params)*x + B*u + S*d );
n_x = 3;
n_u = 2;
n_d = 3;
% additional linear representation
linearRepresentation = struct;
linearRepresentation.A = A;
linearRepresentation.B = B;
linearRepresentation.S = S;
end
In some cases, it may be possible to calculate the state trajectory over the prediction horizon compactly and efficiently, similar to the fast linear representation. PARODIS therefore supports returning a function(handle)
x_flat = @(x0, u_flat, d_flat, params)( .. )
that returns a x0
and
Since in general knowledge of all sample times within the horizon is necessary, the model function must take a second input argument,
function [ode, n_x, n_u, n_d, x_flat] = my_model_fun(T_s, T_s_all)
% always required, ODE for given sample time
ode = @(x, u, d)( some ODE );
n_x = 2;
n_u = 2;
n_d = 2;
% compact system representation
x_flat = @(x0, u_flat, d_flat, params)( some compact represenation );
end
After having defined a model function, models can be used/created using the createModel
function. This will generate a struct containing a symbolic model representation and information about the ODEs and the model, see internal model representation.
model = createModel( @my_model_fun, T_s, numScenarios, implicitPrediction );
If the argument implicitPrediction
is set to false, the state trajectory
Note: If you are using a parameter-variant model description, you must call createModel
only after you have defined your controller and parameters and provide a 5th input argument to createModel
, namely the controller instance you are using:
controller = SymbolicController( numScenarios ); % or ExplicitController, ParetoController
controller.addParam( ... );
...
model = createModel( @my_model_fun, T_s, numScenarios, implicitPrediction, controller );
This is necessary, because the controller manages the symbolic variables for the parameters, on which the symbolic model description depends in a parameter-variant system.
Internally, in PARODIS a model is stored in a struct of the following structure:
Field | Description |
---|---|
x0 |
Symbolic expression for the initial state, sdpvar of size |
x |
Cell array of length numScenarios , where each cell contains a sdpvar that describes the symbolic state trajectory in terms of model.x0 , model.u and model.dPred
|
u |
Symbolic expression representing the predict input, sdpvar of size |
d |
Cell array of length numScenarios , where each cell contains a sdpvar representing the predicted disturbance in each scenari |
n_x |
Number of states |
n_u |
Number of inputs |
n_d |
Number of disturbances |
ode0 |
The ODE for performing |
odes |
Cell array, containing the ODEs for each time step in the horizon |
model_fun |
The function handle of the model function used to create the model |
implicitPrediction |
If false, x is expressed in terms of u and d . Otherwise they will be connected using equality constraints |
flrMatrices |
Matrices for fast linear representation, set only if FLR is supported but matrices are parameter variant |
x_flat |
Function @(x0, u_flat, d_flat, n, params)( .. ) that returns entire (flattend) state trajectory over prediction horizon based on x0 , the input vector and disturbance vector, set if either your model returns it's own x_flat or if FLR is time invariant |
- Prerequisites
- Installing PARODIS
- Creating an Ansatz
- Setting up an Agent
- Setting up a Simulation
- Setting up Figures
Pareto Optimization
Modules
- Simulation
- Agent
- Model
- Controllers
- Cost Functions
- Sources
- Plotting
Other