-
Notifications
You must be signed in to change notification settings - Fork 6
/
compute_X_LQR.m
44 lines (31 loc) · 1.08 KB
/
compute_X_LQR.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
% BRRIEF:
% Template for explicit invariant set computation. You MUST NOT change
% the output.
% INPUT:
% Q, R: State and input weighting matrix, dimension (3,3)
% OUTPUT:
% A_x, b_x: Describes polytopic X_LQR = {x| A_x * x <= b_x}
function [A_x, b_x] = compute_X_LQR(Q, R)
param = compute_controller_base_parameters;
K = dlqr(param.A, param.B, Q, R);
system = LTISystem('A', param.A - param.B*K);
% compute invariant set
%https://www.mpt3.org/UI/Filters
poly = Polyhedron([-K; K; eye(3); -eye(3)], [param.Ucons(:,2); -param.Ucons(:,1); param.Xcons(:,2); -param.Xcons(:,1)]);
system.x.with('setConstraint');
system.x.setConstraint = poly;
InvSet = system.invariantSet();
plot = false;
if plot
figure(9)
init1 = plot3(-2.25, 1.75, 0.75,'g.'); hold on
set(init1,'MarkerSize',40);
init2 = plot3(1.5, 2.75, -0.25,'b.'); hold on
set(init2,'MarkerSize',40);
InvSet.plot();
hold off
end
% set matrices
A_x = InvSet.A;
b_x = InvSet.b;
end