43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
[Gamma_y,gamma_y] = ppp_output_constraint (A,B,C,D,x_0,A_u,Tau_y,Min_y,Max_y,Order_y);
## Composite constraints - t=0
Gamma = [Gamma_u; Gamma_y];
gamma = [gamma_u; gamma_y];
## Design the controller
disp("Designing controller");
[k_x,k_w,K_x,K_w,Us0,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww] = ppp_lin (A,B,C,D,A_u,A_w,t,Q);
## Set up various time vectors
dt = t(2)-t(1); # Time increment
## Make sure Delta_ol is multiple of dt
Delta_ol = floor(Delta_ol/dt)*dt;
|
|
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
[Gamma_y,gamma_y] = ppp_output_constraint (A,B,C,D,x_0,A_u,Tau_y,Min_y,Max_y,Order_y);
## Composite constraints - t=0
Gamma = [Gamma_u; Gamma_y];
gamma = [gamma_u; gamma_y];
## Design the controller
## disp("Designing controller");
[k_x,k_w,K_x,K_w,Us0,J_uu,J_ux,J_uw,J_xx,J_xw,J_ww] = ppp_lin (A,B,C,D,A_u,A_w,t,Q);
## Set up various time vectors
dt = t(2)-t(1); # Time increment
## Make sure Delta_ol is multiple of dt
Delta_ol = floor(Delta_ol/dt)*dt;
|
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
X = [];
u = [];
Iterations = [];
du = [];
J = [];
tick= time;
i = 0;
disp("Simulating ...");
for t=T_cl # Outer loop at Delta_ol
##disp(sprintf("Time %g", t));
## Output constraints
[Gamma_y,gamma_y] = ppp_output_constraint (A,B,C,D,x,A_u,Tau_y,Min_y,Max_y,Order_y);
## Composite constraints
Gamma = [Gamma_u; Gamma_y];
|
|
|
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
X = [];
u = [];
Iterations = [];
du = [];
J = [];
tick= time;
i = 0;
## disp("Simulating ...");
for t=T_cl # Outer loop at Delta_ol
##disp(sprintf("Time %g", t));
## Output constraints
[Gamma_y,gamma_y] = ppp_output_constraint (A,B,C,D,x,A_u,Tau_y,Min_y,Max_y,Order_y);
## Composite constraints
Gamma = [Gamma_u; Gamma_y];
|
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
## Save the last values
X = [X x]; # Save state
u = [u ut]; # Save input
Iterations = [Iterations iterations]; # Save iteration count
tock = time;
Elapsed_Time = tock-tick
y = C*X + D*u; # System output
T = 0:dt:t+Delta_ol; # Overall time vector
endfunction
|
|
|
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
## Save the last values
X = [X x]; # Save state
u = [u ut]; # Save input
Iterations = [Iterations iterations]; # Save iteration count
tock = time;
Elapsed_Time = tock-tick;
y = C*X + D*u; # System output
T = 0:dt:t+Delta_ol; # Overall time vector
endfunction
|