-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test_checkConstraints.m
89 lines (82 loc) · 2.34 KB
/
Test_checkConstraints.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
%Run main_DDSMPC one before, to have all necessary variables
%Is origin feasible point for quadprog?
xk_measured = x0;
[A, b, Aeq, beq, lb, ub] = linconstraints(sys, data, constraints, controller.K, xk_measured);
alpha0 = zeros(size(mpc_init.H,1),1);
if all(A*alpha0<=b)
disp("Inequality consraint okay")
else
idx_problem = find(A*alpha0>b);
disp("Inequality consraint does not hold for xualpha0, problem with constraint "+num2str(idx_problem))
%
for k = 1:length(idx_problem)
xualpha_idx_problem = find(A(idx_problem(k),:));
disp("Problem "+num2str(idx_problem(k))+" concerns element "+num2str(xualpha_idx_problem)+" of xualpha")
end
disp("Up to "+num2str(sys.n*(params.L+1))+" are state constraints, up to "+num2str(sys.n*(params.L+1)+sys.m*(params.L))+" are input constraints")
end
%% Check First step Constraint
%Show allowed 1st steps
figure
sys.X.plot()
hold on
constraints.polyfs.plot('Color','b','alpha',1)
constraints.polyinit.plot('Color','g','alpha',0.1)
constraints.Xf.plot('Color', 'yellow','alpha',1)
xlabel('x1')
ylabel('x2')
title("Constraint sets")
legend('X','First Step Constraint','Feasible Initial set','Terminal set')
% %Input set
%BU = (-sys.B)*sys.input.U;
% figure
% subplot(2,1,1)
% BU.projection(1:2).plot()
% xlabel('x1')
% ylabel('x2')
% title("Input set BU")
% subplot(2,1,2)
% BU.projection(3:4).plot()
% xlabel('x3')
% ylabel('x4')
% title("Input set BU")
%
% %Minus
%minusInput = constraints.polyfs+(BU);
% figure
% subplot(2,1,1)
% minusInput.projection(1:2).plot()
% xlabel('x1')
% ylabel('x2')
% title("FS minus InputSet")
% subplot(2,1,2)
% minusInput.projection(3:4).plot()
% xlabel('x3')
% ylabel('x4')
% title("FS minus InputSet")
%Check where we would need to start to reach that
%constraints.polyinit = inv(sys.A)*minusInput;
figure
subplot(2,1,1)
constraints.polyinit.plot()
xlabel('x1')
ylabel('x2')
title("Initial states from which FirstStep-Set reachable, projected")
subplot(2,1,2)
constraints.polyinit.projection(3:4).plot()
xlabel('x3')
ylabel('x4')
title("Initial states from which FirstStep-Set reachable, projected")
clear BU minusInput
%% Check Terminal set
figure
subplot(2,1,1)
constraints.Xf.projection(1:2).plot()
xlabel('x1')
ylabel('x2')
title("Terminal set, projected")
subplot(2,1,2)
constraints.Xf.projection(3:4).plot()
xlabel('x3')
ylabel('x4')
title("Terminal set, projected")