Changeset 738 for library/bdm/design
- Timestamp:
- 11/25/09 12:46:08 (15 years ago)
- Location:
- library/bdm/design
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/design/ctrlbase.cpp
r737 r738 7 7 } 8 8 9 void LQG::update_system() { 10 pr.set_submatrix ( 0, 0, S->_B() ); 11 pr.set_submatrix ( 0, dimu, S->_A() ); 12 13 //penalization 14 qux.set_submatrix ( 0, 0, Qu._Ch() ); 15 qux.set_submatrix ( 0, dimx + dimu + dimy, Qu._Ch() ); 16 17 qyx.set_submatrix ( 0, 0, S->_C() ); 18 qyx.set_submatrix ( 0, dimx, -eye ( dimy ) ); 19 20 // parts of QR 21 hqy = Qy.to_mat() * qyx * pr; 22 23 // pre_qr 24 pre_qr = concat_vertical ( s * pr, concat_vertical ( hqy, qux ) ); 25 } 26 9 27 void LQG::set_control_parameters ( const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0 ) { 10 28 Qy = Qy0; … … 38 56 } 39 57 58 void LQG::ricatti_step() { 59 pre_qr.set_submatrix ( 0, 0, s*pr ); 60 pre_qr.set_submatrix ( dimx + dimu + dimy, dimu + dimx, -Qy.to_mat() *y_req ); 61 if ( !qr ( pre_qr, post_qr ) ) { 62 bdm_warning ( "QR in LQG unstable" ); 63 } 64 triu ( post_qr ); 65 // hn(m+1:2*m+n+r,m+1:2*m+n+r); 66 s = post_qr.get ( dimu, 2 * dimu + dimx + dimy - 1, dimu, 2 * dimu + dimx + dimy - 1 ); 67 }; 68 69 void LQG::redesign() { 70 for ( td = horizon; td > 0; td-- ) { 71 update_system(); 72 ricatti_step(); 73 } 74 /* ws=hn(1:m,m+1:2*m+n+r); 75 wsd=hn(1:m,1:m); 76 Lklq=-inv(wsd)*ws;*/ 77 L = -inv ( post_qr.get ( 0, dimu - 1, 0, dimu - 1 ) ) * post_qr.get ( 0, dimu - 1, dimu, 2 * dimu + dimx + dimy - 1 ); 78 } 79 40 80 41 81 } -
library/bdm/design/ctrlbase.h
r737 r738 106 106 void set_system ( shared_ptr<StateSpace<chmat> > S0 ); 107 107 //! update internal whan system has changed 108 void update_system() { 109 pr.set_submatrix ( 0, 0, S->_B() ); 110 pr.set_submatrix ( 0, dimu, S->_A() ); 111 112 //penalization 113 qux.set_submatrix ( 0, 0, Qu._Ch() ); 114 qux.set_submatrix ( 0, dimx + dimu + dimy, Qu._Ch() ); 115 116 qyx.set_submatrix ( 0, 0, S->_C() ); 117 qyx.set_submatrix ( 0, dimx, -eye ( dimy ) ); 118 119 // parts of QR 120 hqy = Qy.to_mat() * qyx * pr; 121 122 // pre_qr 123 pre_qr = concat_vertical ( s * pr, concat_vertical ( hqy, qux ) ); 124 } 108 void update_system(); 125 109 //! set penalization matrices and control horizon 126 110 void set_control_parameters ( const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0 ); … … 137 121 //! function for future use which is called at each time td; Should call initialize()! 138 122 //! redesign one step of the 139 void ricatti_step() { 140 pre_qr.set_submatrix ( 0, 0, s*pr ); 141 pre_qr.set_submatrix ( dimx + dimu + dimy, dimu + dimx, -Qy.to_mat() *y_req ); 142 if ( !qr ( pre_qr, post_qr ) ) { 143 bdm_warning ( "QR in LQG unstable" ); 144 } 145 triu ( post_qr ); 146 // hn(m+1:2*m+n+r,m+1:2*m+n+r); 147 s = post_qr.get ( dimu, 2 * dimu + dimx + dimy - 1, dimu, 2 * dimu + dimx + dimy - 1 ); 148 }; 149 void redesign() { 150 for ( td = horizon; td > 0; td-- ) { 151 update_system(); 152 ricatti_step(); 153 } 154 /* ws=hn(1:m,m+1:2*m+n+r); 155 wsd=hn(1:m,1:m); 156 Lklq=-inv(wsd)*ws;*/ 157 L = -inv ( post_qr.get ( 0, dimu - 1, 0, dimu - 1 ) ) * post_qr.get ( 0, dimu - 1, dimu, 2 * dimu + dimx + dimy - 1 ); 158 } 123 void ricatti_step(); 124 125 void redesign(); 126 159 127 //! compute control action 160 128 vec ctrlaction ( const vec &state, const vec &ukm ) const {