forked from ajinkya-khade/ACC_Vehicle_MPC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genConstraints.m
49 lines (40 loc) · 1.39 KB
/
genConstraints.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
%genConstraints
% This script generates all equality and inequality constrints for QP.
%
% Author : Ajinkya Khade, [email protected]
% Initializing matrices to store input constraints
Umaxbar = kron(ones(Nc*nu,1),umax);
Uminbar = kron(ones(Nc*nu,1),umin);
% Anonymous function to calculate state and constraints
Scbar = @(sivd, v0) kron(ones(Np,1),[sivd;v0]);
% Initialize equality and inequlity contraint matrices
[Lineq, Mineq, Leq, Meq] = deal(cell(2,1));
%% Inequality Constraints
if ineqMode == 0
% No Constraints
Lineq = [];
Mineq = @(e,sivd,v0) []; % when inequality constraints have to be removed
elseif ineqMode == 1
% All Constraints
Lineq = [Cbar*Bbar; ...
eye(Nc*nu); ...
-eye(Nc*nu)];
Mineq = @(e,sivd,v0) [Scbar(sivd,v0) - Cbar*Abar*e; ...
Umaxbar; ...
-Uminbar];
elseif ineqMode == 2
% Only Control Constraints
Lineq = [eye(Nc*nu); ...
-eye(Nc*nu)];
Mineq = @(e,sivd,v0) [Umaxbar; ...
-Uminbar];
end
%% Equality Constraints
psi = zeros(nx,1); % terminal state constraint
if eqMode == 0
Leq = [];
Meq = @(e) []; % when equality constraints have to be removed
elseif eqMode == 1
Leq = Bbar(end-nx+1:end,:);
Meq = @(e) (psi - Abar(end-nx+1:end,:)*e);
end