Overview
Comment:Updated for liuping's qp_hild.m
Used on IP experiment
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: efb6c42d89ea0a7bbbf92ac11a5bf22a59a0099a76bcdcf725af77b4988a7765
User & Date: gawthrop@users.sourceforge.net on 2004-10-20 21:58:12.000
Other Links: branch diff | manifest | tags
Context
2005-01-06
12:28:36
Minor typos. check-in: b064c9ddbc user: geraint@users.sourceforge.net tags: origin/master, trunk
2004-10-20
21:58:12
Updated for liuping's qp_hild.m
Used on IP experiment
check-in: efb6c42d89 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
2004-10-14
21:42:44
Changed timing - now works with inverted pendulum. check-in: d896096f57 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes
1

2
3

4
5
6









7
8
9
10
11
12
13

14
15
16
17









18
19
20
21
22

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
-
+

-
+



+
+
+
+
+
+
+
+
+







+
-
-
-
-
+
+
+
+
+
+
+
+
+





function [P,A_u,A_w,k] = ppp_are (A,B,C,D,Q,R)
function [P,A_u,A_w,k] = ppp_are (A,B,C,D,Q,R,A_type)

  ## usage:  [P,A_u,A_w] = ppp_are (A,B,C,D,Q,R)
  ## usage:  [P,A_u,A_w] = ppp_are (A,B,C,D,Q,R,A_type)
  ##
  ## 

  if nargin<1
    disp("usage:  [P,A_u,A_w] = ppp_are (A,B,C,D,Q,R,A_type)");
    return
  endif
  
  if nargin<7
    A_type = "feedback";
  endif
  

  ## Steady-state Linear Quadratic solution
  ## using Algebraic Riccati equation (ARE)
  Q_x =  C'*Q*C;			# Weighting on x
  [k, P, poles] = lqr (A, B, Q_x, R); # Algebraic Riccati solution

  ## Basis functions
  if strcmp(A_type,"companion")
  A_u = compan(poly(poles));

  ## Avoid spurious imag parts due to rounding
  A_u = real(A_u);		
    A_u = compan(poly(poles));
  elseif strcmp(A_type,"feedback")
    A_u = A-B*k;
  else
    error(sprintf("A_type must be %s, not %s", "companion or feedback", A_type));
  endif
  
    ## Avoid spurious imag parts due to rounding
    A_u = real(A_u);		

  ## Setpoint basis functions
  A_w = 0;

endfunction
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
11
12
13
14
15
16
17


18
19
20
21
22
23
24







-
-







  ## Control = 0:  step test
  ## Control = 1:  PPP open-loop
  ## Control = 2:  PPP closed-loop
  ## w is the (constant) setpoint
  ## par_control and par_observer are structures containing parameters
  ## for the observer and controller

  disp("Special version");

  ##Defaults
  if nargin<1			# Default name to dir name
    names = split(pwd,"/");
    [n_name,m_name] = size(names);
    Name = deblank(names(n_name,:));
  endif

1

2
3
4
5
6
7
8

1
2
3
4
5
6
7
8
-
+







function [u,U,iterations] = ppp_qp (x,W,J_uu,J_ux,J_uw,Us0,Gamma,gamma,mu,test)
function [u,U,n_active] = ppp_qp (x,W,J_uu,J_ux,J_uw,Us0,Gamma,gamma,mu,test)

  ## usage:  [u,U] = ppp_qp (x,W,J_uu,J_ux,J_uw,Gamma,gamma)
  ## INPUTS:
  ##      x: system state    
  ##      W: Setpoint vector
  ##      J_uu,J_ux,J_uw: Cost derivatives (see ppp_lin)
  ##      Us0: value of U* at tau=0 (see ppp_lin)
41
42
43
44
45
46
47

48


49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
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







+
-
+
+






-
+









  if (n != n_U)||(m != n_x)
    error("J_ux should be %ix%i not %ix%i",n_U,n_x,n,m);
  endif


  if length(gamma)>0		# Constraints exist: do the QP algorithm
    ## QP solution for weights U	
##    [U,iterations] = qp_mu(J_uu,(J_ux*x-J_uw*W),Gamma,gamma,mu,[],[],0,test);
    [U,iterations] = qp_mu(J_uu,(J_ux*x - J_uw*W),Gamma,gamma,mu,[],[],0,test);
    [U,n_active] = qp_hild(J_uu,(J_ux*x - J_uw*W),Gamma,gamma);	# 
##    iterations = 0;

    ##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;
    n_active = 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

endfunction

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