Overview
Comment:Updated for new ppp_qp (using qp_mu from Will Heath/Adrian Wills
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 63e8024414b5ff08f4c7862914ab3dc7bc2a88ecca8e7c471dab081bf99e9da6
User & Date: gawthrop@users.sourceforge.net on 2002-08-27 17:34:36.000
Other Links: branch diff | manifest | tags
Context
2002-08-28
15:48:01
Updated mttrc to make standalone C++ compilation configuration clearer. check-in: 7654be3275 user: geraint@users.sourceforge.net tags: origin/master, trunk
2002-08-27
17:34:36
Updated for new ppp_qp (using qp_mu from Will Heath/Adrian Wills check-in: 63e8024414 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
16:09:01
Added port_name to error message when multiple bonds are near a port. check-in: c7b42b1371 user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes
29
30
31
32
33
34
35
36

37
38
39
40

41
42
43
44
45
46
47
29
30
31
32
33
34
35

36
37
38
39

40
41
42
43
44
45
46
47







-
+



-
+







  t = [6:0.02:7];		# Time horizon
  A_w = 0;			# Setpoint
  A_u = ppp_aug(laguerre_matrix(3,2.0), A_w); # Input functions

  Q = ones(n_y,1);;
  

  ## Constaints
  ## Constraints
  Gamma = [];
  gamma = [];

  ## Constaints - u
  ## Constraints - u
  Tau_u = [0:0.5:2];
  one = ones(size(Tau_u));
  limit = 1.5;
  Min_u = -limit*one;
  Max_u =  limit*one;
  Order_u = 0*one;

72
73
74
75
76
77
78
79

80
81

82

83
84
85
86
87
88
89
90

91
92

93

94
95
96
97
98
99





100
101
102
103
104
105
72
73
74
75
76
77
78

79
80
81
82

83
84
85
86
87
88
89
90

91
92
93
94

95
96





97
98
99
100
101
102
103
104
105
106
107







-
+


+
-
+







-
+


+
-
+

-
-
-
-
-
+
+
+
+
+






  [ys,us] = ppp_ystar (A,B,C,D,x_0,A_u,U,T);

  ## Unconstrained OL simulation
  disp("Computing unconstrained ol response");
  [uu,Uu] = ppp_qp (x_0,W,J_uu,J_ux,J_uw,Us0,[],[]);
  [ysu,usu] = ppp_ystar (A,B,C,D,x_0,A_u,Uu,T);

  title("Constained and unconstrained y*");
  title("Constrained and unconstrained y*");
  xlabel("t");
  grid;
  figure(1);
  plot(T,ys,T,ysu)
  plot(T,ys,"-;y*: constrained;", T,ysu, "--;y*: unconstrained;")

  ## Non-linear - closed-loop
    disp("Computing constrained closed-loop response");
  [T,y,u,J] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \
			  Tau_u,Min_u,Max_u,Order_u, \
			  Tau_y,Min_y,Max_y,Order_y,W,x_0);

  title("y,y*,u and u*");
  title("Constrained closed-loop response");
  xlabel("t");
  grid;
  figure(2);
  plot(T,y,T,u,T,ys,T,us);
  plot(T,y,"-;y;", T,u,"--;u;");

  ## Compute derivatives.
  dt = t(2)-t(1);
  du = diff(u)/dt;
  dus = diff(us)/dt;
  T1 = T(1:length(T)-1);
#   ## Compute derivatives.
#   dt = t(2)-t(1);
#   du = diff(u)/dt;
#   dus = diff(us)/dt;
#   T1 = T(1:length(T)-1);
  ##plot(T1,du,T1,dus);
endfunction




18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32







-
+







       1  0  0
       0  1  0];
  B = [1 
       0 
       0];
  C = [0 -0.5  1];
  D = 0;
  [n_x,n_u,n_y] = abcddim(A,B,C,D)
  [n_x,n_u,n_y] = abcddim(A,B,C,D);

  ## Controller
  t = [4:0.02:5];		# Time horizon
  A_w = 0;			# Setpoint
  A_u = ppp_aug(laguerre_matrix(3,2.0), A_w); # Input functions
  Q = ones(n_y,1);;

52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66







-
+







  [T,y,u,J] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \
			   Tau,Min,Max,Order, \
			   [],[],[],[], W,x_0);

  title("y,y*,u and u*");
  xlabel("t");
  grid;
  plot(T,y,T,u,T,ys,T,us);
  plot(T,y,"1;y;", T,u,"2;u;", T,ys,"3;y*;", T,us,"4;u*;");

  ## Compute derivatives.
  dt = t(2)-t(1);
  du = diff(u)/dt;
  dus = diff(us)/dt;
  T1 = T(1:length(T)-1);
  ##plot(T1,du,T1,dus);
38
39
40
41
42
43
44
45

46
47
48

49
50
51

52

53

54
55
56
57
58
59


60
61
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







-
+


-
+


-
+

+
-
+





-
+
+


  x_0 = zeros(n_x,1);		# Initial state


  ## Closed-loop intermittent solution
  Delta_ol = 0.5		# Intermittent time

  disp("Intermittent control simulation");
  [T,y,u,J] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \
  [T,y,u] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \
			  [],[],[],[], \
			  [],[],[],[],W,x_0,Delta_ol);

size(T)
  ## Exact closed-loop
  disp("Exact closed-loop");
  [k_x,k_w] = ppp_lin (A,B,C,D,A_u,A_w,t,Q);
  [k_x,k_w] = ppp_lin (A,B,C,D,A_u,A_w,t,Q)
  [ye,Xe] = ppp_sm2sr(A-B*k_x, B, C, D, T, k_w*W, x_0); # Compute Closed-loop control

  ue = k_w*ones(size(T))*W - k_x*Xe';
  ue = k_w*ones(size(T))*W - k_x*Xe;


  title("y and u, exact and intermittent");
  xlabel("t");
  grid;
  plot(T,y,T,u,T,ye,T,ue);
  plot(T,y,"1;y (intermittent);", T,u,"2;u (intermittent);",\
       T,ye,"3;y (exact);", T,ue,"4;u (exact);");

endfunction
69
70
71
72
73
74
75

76

77
78
79

80
81
82

83
84

85
86
87

88
89
90
91
92
93
69
70
71
72
73
74
75
76

77
78
79

80
81
82

83
84

85
86
87

88
89
90
91
92
93
94







+
-
+


-
+


-
+

-
+


-
+






  ## Unconstrained OL simulation
  [uu,Uu] = ppp_qp (x_0,W,J_uu,J_ux,J_uw,Us0,[],[]);
  [ysu,usu] = ppp_ystar (A,B,C,D,x_0,A_u,Uu,T);

  title("Constained and unconstrained y*");
  xlabel("t");
  grid;
  figure(1);
  plot(T,ys,T,ysu)
  plot(T,ys,"-;y* (constrained);", T,ysu,"--;y* (unconstrained);")

  ## Non-linear - closed-loop
  delta_ol = 0.1;
  delta_ol = 0.1; mu = 1e-4;
  [T,y,u,J] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \
			  Tau_u,Min_u,Max_u,Order_u, \
			  Tau_y,Min_y,Max_y,Order_y,W,x_0,delta_ol);
			  Tau_y,Min_y,Max_y,Order_y,W,x_0,delta_ol,mu);

  title("y,y*,u and u*");
  title("y and u");
  xlabel("t");
  grid;
  plot(T,y,T,u,T,ysu,T,usu);
  plot(T,y,"1;y (constrained);", T,u,"2;u (constrained);");

endfunction




79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94

95
96

97

98
99
100
101
102
103
104
79
80
81
82
83
84
85

86
87
88
89
90
91
92
93

94
95
96
97

98
99
100
101
102
103
104
105







-
+







-
+


+
-
+







  ## Unconstrained OL simulation
  [uu,Uu] = ppp_qp (x_0,W,J_uu,J_ux,J_uw,Us0,[],[]);
  [ysu,usu] = ppp_ystar (A,B,C,D,x_0,A_u,Uu,T);

  title("Constrained and unconstrained y*");
  xlabel("t");
  grid;
  plot(T,ys,T,ysu)
  plot(T,ys,"-;y* (constrained);", T,ysu,"--;y* (unconstrained);");

  ## Non-linear - closed-loop
  disp("Closed-loop simulation");
  [T1,y,u,J] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, \
			   Tau_u,Min_u,Max_u,Order_u, \
			   Tau_y,Min_y,Max_y,Order_y,W,x_0);

  title("y,y*,u and u*");
  title("y and u");
  xlabel("t");
  grid;
  plot(T,y,"1;y (constrained);", T,u,"2;u (constrained);");
  plot(T1,y,T,ys,T1,u,T,us);

endfunction






34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50

51
52
53
54
55
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49

50
51
52
53
54
55







-
+








-
+





  i_u = 1;
  
  ## Simulation
  W=1;
  x_0 = 0;

  ## Linear
  [ol_poles,cl_poles,ol_zeros,cl_zeros,k_x,k_w] = ppp_lin_plot (A,B,C,D,A_u,A_w,t);
  ppp_lin_plot (A,B,C,D,A_u,A_w,t);
  
  ## Non-linear
  movie = 0;
  [T,y,u,J] = ppp_qp_sim (A,B,C,D,A_u,A_w,t,Q, Tau,Min,Max,Order, \
	      [],[],[],[], W,x_0);
  title("y,u_1,u_2");
  xlabel("t");
  grid;
  plot(T,y,T,u);
  plot(T,y,"-;y;", T,u(1,:),"--;u_1;", T,u(2,:),".-;u_2;");

endfunction



1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







function [ol_poles,cl_poles,ol_zeros,cl_zeros,k_x,k_w,K_x,K_w,cond_uu] =  ppp_lin_plot (A,B,C,D,A_u,A_w,t,Q,W,x_0)

  ## usage:   [ol_poles,cl_poles,ol_zeros,cl_zeros,k_x,k_w,K_x,K_w] = ppp_lin_plot (A,B,C,D,A_u,A_w,t,Q,W,x_0)
  ## usage:   [ol_poles,cl_poles,ol_zeros,cl_zeros,k_x,k_w,K_x,K_w,cond_uu] = ppp_lin_plot (A,B,C,D,A_u,A_w,t,Q,W,x_0)
  ##
  ## Linear PPP (Predictive pole-placement) computation with plotting
  ## INPUTS:
  ## A,B,C,D: system matrices
  ## A_u: composite system matrix for U* generation 
  ##      one square matrix (A_ui) row for each system input
  ##      each A_ui generates U*' for ith system input.
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50







-
+







  endif
  

  [n_t,m_t] = size(t);

  ## Default Q
  if nargin<8
    Q = ones(n_y,1);
    Q = ones(n_y,1)
  endif

  ## Default W
  if nargin<9
    W = ones(n_W,1)
  endif

43
44
45
46
47
48
49

50
51
52
53
54
55
56
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57







+







    [U,iterations] = qp_mu(J_uu,(J_ux*x - J_uw*W),Gamma,gamma,mu); # QP solution for weights U	

    ##U = qp(J_uu,(J_ux*x - J_uw*W),Gamma,gamma); # QP solution for weights U
    ##U = pd_lcp04(J_uu,(J_ux*x - J_uw*W),Gamma,gamma); # QP solution for weights U
    u = Us0*U;			# Control signal
  else			# Do the unconstrained solution
    ## Compute the open-loop gains
    iterations = 0;
    K_w = J_uu\J_uw;
    K_x = J_uu\J_ux;

    ## Closed-loop control
    U = K_w*W - K_x*x;		# Basis functions weights - U(t)
    u = Us0*U;			# Control u(t)
  endif
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
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");
  ## 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
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 ...");
  ## 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
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
  Elapsed_Time = tock-tick;
  y = C*X + D*u;		# System output

  T = 0:dt:t+Delta_ol;		# Overall time vector

endfunction




MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]