Main /

CustomMPC

Main.CustomMPC History

Hide minor edits - Show changes to output

Added line 59:
[[#xu-constraints]]
Deleted line 125:
March 17, 2014, at 11:05 AM by 129.132.52.158 -
Changed lines 70-71 from:
!! Alternative formulation in YALMIP
If the concept of filters is not satisfactory to customize your MPC problem, it is still possible to formulate the problem completely in YALMIP. For more details on formulating the problems in YALMIP, see [[http://users.isy.liu.se/johanl/yalmip/pmwiki.php?n=Examples.StandardMPC|MPC examples in YALMIP]].
to:
!! Alternative formulations in YALMIP
If these modifications or [[UI.Filters| additional constraints]] are not satisfactory to customize your MPC problem, it is still possible to formulate the problem completely in YALMIP. For more details on formulating the problems in YALMIP, see [[http://users.isy.liu.se/johanl/yalmip/pmwiki.php?n=Examples.StandardMPC|MPC examples in YALMIP]].
March 17, 2014, at 11:01 AM by 129.132.52.158 -
Changed lines 68-125 from:
@]
to:
@]

!! Alternative formulation in YALMIP
If the concept of filters is not satisfactory to customize your MPC problem, it is still possible to formulate the problem completely in YALMIP. For more details on formulating the problems in YALMIP, see [[http://users.isy.liu.se/johanl/yalmip/pmwiki.php?n=Examples.StandardMPC|MPC examples in YALMIP]].
In the example below, it is shown how to formulate MPC problem where the upper/lower bounds on inputs are parametrized.

(:source lang=MATLAB -getcode:) [@
% parametrization of upper/lower bounds on the input using YALMIP

% dynamics x(k+1) = A*x(k) + Bu(k)
A = 0.9;
B = 1;

% penalties
Q = 5;
R = 0.1;

horizon = 5;

% variables
x = sdpvar(1,horizon+1);
u = sdpvar(1,horizon);
ub = sdpvar(1,1);
lb = sdpvar(1,1);

con = [];
obj = 0;
for i=1:horizon 
    % assing domain
    con = [con;  x(i+1) == A*x(i) + B*u(i) ];
   
    % input constraints
    con = [con;  lb <= u(i) <= ub ];
   
    % constraints on parameters
    con = [con;  -2 <= lb <= 0; lb <= ub; 0 <= ub <= 2];
       
    % state constraints
    con = [con; -10 <= x(i) <= 10 ];
         
  obj = obj + norm(Q*(x(i)-1),1) + norm(R*u(i),1);
end

% construct the optimization problem with [x0; lb; ub] as parameters and u
% as the decision variables
problem = Opt(con, obj, [x(1); lb; ub], u);

% solve the problem explicitly
res = problem.solve


% evaluate the primal solution u for a value of parameter [0;-1;1]
res.xopt.feval([0;-1;1],'primal')

% evaluate the primal solution u for a value of parameter [0;-1;0.5]
res.xopt.feval([0;-1;0.5],'primal')
@]

Changed line 3 from:
The MPT3's equivalent of @@mpt_ownmpc@@ is provided by @@MPCController/toYALMIP()@@ and @@MPCController/fromYALMIP()@@ methods.
to:
MPT3 allows to modify the cost function and the constraints of arbitrary MPC setups via [[http://users.isy.liu.se/johanl/yalmip/|YALMIP]]. The functionality is implemented in the @@MPCController/toYALMIP()@@ and @@MPCController/fromYALMIP()@@ methods.
Changed lines 6-8 from:
* prediction model @@x^+ = Ax + Bu@@ with @@A=0.9@@ and @@B=1@@
*
state constraints @@[-5, 5]@@
*
input constraints @@[-1, 1]@@
to:
* prediction model {$ x^+ = Ax + Bu $} with {$ A=0.9 $} and {$ B=1 $}
*
state constraints {$ -5 \le x \le 5 $}
*
input constraints {$ -1 \le u \le 1 $}
Changed lines 10-11 from:
* prediction horizon @@N=3@@
to:
* prediction horizon {$ N = 3 $}
Changed lines 26-27 from:
* @@-0.5 <= u <= 0.5@@ for the first element of the predicted input sequence
* @@-0.8 <= u <= 0.8@@ for the second element
to:
* {$ -0.5 \le u_0 \le 0.5 $} for {$u_0$} (the first element of the predicted input sequence)
* {$ -0.8 \le u_1 \le 0.8 $} for {$u_1$} (the second element)
Changed lines 57-68 from:
Note that nonconvex set constraints lead to mixed-integer problems which are difficult to solve.
to:
Note that nonconvex set constraints lead to mixed-integer problems which are difficult to solve.

!! Joint state-input constraints

To add the constraint {$ F x_k + G u_k \le b $} for each step of the prediction horizon, do:
(:source lang=MATLAB -getcode:) [@
Y = mpc.toYALMIP();
for k = 1:size(Y.variables.u, 2)
    Y.constraints = Y.constraints + [ F*Y.variables.x(:, k) + G*Y.variables.u(:, k) <= b ];
end
mpc.fromYALMIP(Y);
@]
September 09, 2013, at 07:34 AM by Michal Kvasnica -
Changed line 57 from:
Note nonconvex set constraints lead to mixed-integer problems which are difficult to solve.
to:
Note that nonconvex set constraints lead to mixed-integer problems which are difficult to solve.
September 09, 2013, at 07:30 AM by Michal Kvasnica -
Changed lines 46-57 from:
That's it!
to:
!! Multiple terminal sets
As an another example we show how to include a non-convex terminal set into MPC setups. The assumption here is that the non-convex set can be decomposed into a finite number of polyhedra, say @@P = [P1, P2, P3, P4]@@. To tell MPT3 to use @@P@@ as the terminal set, use

(:source lang=MATLAB -getcode:) [@
Y = mpc.toYALMIP();
Y.constraints = Y.constraints + [ ismember( Y.variables.x(:, end), P) ];
mpc.fromYALMIP(Y);
@]

Here, @@Y.variables.x(:, end)@@ denotes the final predicted state, while the @@ismember()@@ command tells MPT/YALMIP to ensure that the terminal state resides in one of the elements of the polyhedron array @@P@@.

Note nonconvex set constraints lead to mixed-integer problems which are difficult to solve.
July 26, 2013, at 07:52 PM by Michal Kvasnica -
Changed lines 19-20 from:
model.x.penalty = Penalty(1, 2); % 2 = quadratic penalty
model.u.penalty = Penalty
(1, 2);
to:
model.x.penalty = QuadFunction(1);
model.u.penalty = QuadFunction(1);
May 23, 2013, at 08:34 PM by Michal Kvasnica -
Added lines 1-46:
! Fine-tuning MPC setups via YALMIP

The MPT3's equivalent of @@mpt_ownmpc@@ is provided by @@MPCController/toYALMIP()@@ and @@MPCController/fromYALMIP()@@ methods.

As an illustrative example, consider the following scenario:
* prediction model @@x^+ = Ax + Bu@@ with @@A=0.9@@ and @@B=1@@
* state constraints @@[-5, 5]@@
* input constraints @@[-1, 1]@@
* unity quadratic penalties on states and inputs
* prediction horizon @@N=3@@

Such an MPC problem is formulated by:
(:source lang=MATLAB -getcode:) [@
model = LTISystem('A', 0.9, 'B', 1);
model.x.min = -5;
model.x.max = 5;
model.u.min = -1;
model.u.max = 1;
model.x.penalty = Penalty(1, 2); % 2 = quadratic penalty
model.u.penalty = Penalty(1, 2);
N = 3;
mpc = MPCController(model, N);
@]

Now suppose that we want the input constraints to be time-varying:
* @@-0.5 <= u <= 0.5@@ for the first element of the predicted input sequence
* @@-0.8 <= u <= 0.8@@ for the second element

This can be easily achieved by modifying the MPC problem via YALMIP. As a first step, you need to obtain the YALMIP representation of the MPC controller:
(:source lang=MATLAB -getcode:) [@
Y = mpc.toYALMIP();
@]
The variable @@Y@@ is a structure that contains the constraints, objective, and variables.

Now we can directly modify the constraints as desired:
(:source lang=MATLAB -getcode:) [@
Y.constraints = Y.constraints + [ -0.5 <= Y.variables.u(:, 1) <= 0.5 ];
Y.constraints = Y.constraints + [ -0.8 <= Y.variables.u(:, 2) <= 0.8 ];
@]

Finally, we tell the MPC controller to use the new constraints:
(:source lang=MATLAB -getcode:) [@
mpc.fromYALMIP(Y);
@]

That's it!