summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2023-05-24 16:33:10 +0200
committerNao Pross <np@0hm.ch>2023-05-24 16:33:10 +0200
commit25806301cf5fff5998e55a382214027be22f7c52 (patch)
tree82b7e8f2dda7fdc052bc5e312730106bb5ad08d8
parentTake deliverables for from LQR to MPC from yuanxu (diff)
downloadmpc_pe-25806301cf5fff5998e55a382214027be22f7c52.tar.gz
mpc_pe-25806301cf5fff5998e55a382214027be22f7c52.zip
Take deliverables for MPC with theoretical closed-loop guarantees
According to table 8 - MPC_TE - MPC_TE/eval (contained in MPC_TE.m) - MPC_TS - MPC_TS/eval (contained in MPC_TE.m)
Diffstat (limited to '')
-rw-r--r--templates/MPC_TE.m28
-rw-r--r--templates/MPC_TS.m30
2 files changed, 55 insertions, 3 deletions
diff --git a/templates/MPC_TE.m b/templates/MPC_TE.m
index e0b55d2..747c7ee 100644
--- a/templates/MPC_TE.m
+++ b/templates/MPC_TE.m
@@ -15,7 +15,33 @@ classdef MPC_TE
function obj = MPC_TE(Q,R,N,params)
% YOUR CODE HERE
opts = sdpsettings('verbose',1,'solver','quadprog');
- obj.yalmip_optimizer = optimizer(constraints,objective,opts,X0,{U{1} objective});
+
+ % Create yalmip variables
+ U = sdpvar(repmat(params.model.nu,N,1),ones(1,N));
+ X = sdpvar(repmat(params.model.nx,N+1,1),ones(1,N+1));
+
+ % Build cost function and constraints
+ objective = 0;
+ constraints = [];
+ for k=1:N+1
+ if k <= N
+ % These constraints are for the index in 1, ..., N
+ objective = objective + X{k}' * Q * X{k} + U{k}' * R * U{k};
+ constraints = [constraints, ...
+ X{k+1} == params.model.A * X{k} + params.model.B * U{k}, ...
+ params.constraints.InputMatrix * U{k} <= params.constraints.InputRHS, ...
+ ];
+ end
+
+ % These contrains are for 1, ..., N+1
+ constraints = [constraints, ...
+ params.constraints.StateMatrix * X{k} <= params.constraints.StateRHS, ...
+ ];
+ end
+ % Terminal constraint
+ constraints = [constraints, X{N+1} == zeros(size(X{N+1}))];
+
+ obj.yalmip_optimizer = optimizer(constraints,objective,opts,X{1},{U{1} objective});
end
function [u, ctrl_info] = eval(obj,x)
diff --git a/templates/MPC_TS.m b/templates/MPC_TS.m
index 05f92ff..cbe7b45 100644
--- a/templates/MPC_TS.m
+++ b/templates/MPC_TS.m
@@ -15,8 +15,34 @@ classdef MPC_TS
function obj = MPC_TS(Q,R,N,H,h,params)
% YOUR CODE HERE
opts = sdpsettings('verbose',1,'solver','quadprog');
- obj.yalmip_optimizer = optimizer(constraints,objective,opts,X0,{U{1} objective});
- end
+
+ % Create yalmip optimization variables
+ U = sdpvar(repmat(params.model.nu,N,1),ones(1,N));
+ X = sdpvar(repmat(params.model.nx,N+1,1),ones(1,N+1));
+
+ % Build cost function and constraints
+ Pinf = idare(params.model.A, params.model.B, Q, R);
+ objective = X{N+1}' * Pinf * X{N+1};
+ constraints = [];
+ for k=1:N+1
+ if k <= N
+ % These constraints are for the index in 1, ..., N
+ objective = objective + X{k}' * Q * X{k} + U{k}' * R * U{k};
+ constraints = [constraints, ...
+ X{k+1} == params.model.A * X{k} + params.model.B * U{k}, ...
+ params.constraints.InputMatrix * U{k} <= params.constraints.InputRHS, ...
+ ];
+ end
+
+ % These contrains are for 1, ..., N+1
+ constraints = [constraints, ...
+ params.constraints.StateMatrix * X{k} <= params.constraints.StateRHS, ...
+ ];
+ end
+ % Terminal constraint
+ constraints = [constraints, H*X{N+1} <= h];
+
+ obj.yalmip_optimizer = optimizer(constraints,objective,opts,X{1},{U{1} objective}); end
function [u, ctrl_info] = eval(obj,x)
%% evaluate control action by solving MPC problem, e.g.