1 | #include "ctrlbase.h" |
---|
2 | |
---|
3 | namespace bdm{ |
---|
4 | |
---|
5 | void LQG::set_system_parameters(const mat &A0, const mat &B0, const mat &C0){ |
---|
6 | dimx = A0.rows(); |
---|
7 | dimy = C0.rows(); |
---|
8 | dimu = B0.cols(); |
---|
9 | |
---|
10 | bdm_assert_debug ( A0.cols() == dimx, "LQG: A is not square" ); |
---|
11 | bdm_assert_debug ( B0.rows() == dimx, "LQG: B is not compatible" ); |
---|
12 | bdm_assert_debug ( C0.cols() == dimx, "LQG: C is not square" ); |
---|
13 | |
---|
14 | A=A0; |
---|
15 | B=B0; |
---|
16 | C=C0; |
---|
17 | pr=zeros(dimx+dimu+dimy, dimu+dimx+dimu+dimy); |
---|
18 | pr.set_submatrix(dimx, dimu+dimx, eye(dimu+dimy)); |
---|
19 | } |
---|
20 | |
---|
21 | void LQG::set_control_parameters(const mat &Qy0, const mat &Qu0, const vec y_req0, int horizon0){ |
---|
22 | bdm_assert_debug ( Qy0.cols() == dimy, "LQG: wrong dimensions of Qy " ); |
---|
23 | bdm_assert_debug ( Qu0.cols() == dimu, "LQG: wrong dimensions of Qu " ); |
---|
24 | bdm_assert_debug ( y_req0.length() == dimy, "LQG: wrong dimensions of y_req " ); |
---|
25 | |
---|
26 | Qy=Qy0; |
---|
27 | Qu=Qu0; |
---|
28 | y_req=y_req0; |
---|
29 | horizon = horizon0; |
---|
30 | prepare_qr(); |
---|
31 | } |
---|
32 | |
---|
33 | void LQG::prepare_qr(){ |
---|
34 | // set parameter matrix |
---|
35 | pr.set_submatrix(0,0,B); |
---|
36 | pr.set_submatrix(0,dimu, A); |
---|
37 | |
---|
38 | //penalization |
---|
39 | qux=zeros(dimu,dimx+2*dimu+dimy); |
---|
40 | qux.set_submatrix(0,0,Qu); |
---|
41 | qux.set_submatrix(0,dimx+dimu+dimy,Qu); |
---|
42 | |
---|
43 | qyx=zeros(dimy, dimx+dimy+dimu); |
---|
44 | qyx.set_submatrix(0,0,C); |
---|
45 | qyx.set_submatrix(0,dimx,-eye(dimy)); |
---|
46 | |
---|
47 | // |
---|
48 | s=1e-5*eye(4);//dimx+dimu+dimy); |
---|
49 | // parts of QR |
---|
50 | hqy=Qy*qyx*pr; |
---|
51 | |
---|
52 | // pre_qr |
---|
53 | pre_qr = concat_vertical(s*pr, concat_vertical(hqy, qux)); |
---|
54 | post_qr = zeros(pre_qr.rows(), pre_qr.cols()); |
---|
55 | } |
---|
56 | |
---|
57 | } |
---|