Changeset 508 for library/bdm/design/ctrlbase.h
- Timestamp:
- 08/12/09 16:47:33 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/design/ctrlbase.h
r491 r508 11 11 */ 12 12 13 #include <bdmbase.h> 13 #include "../base/bdmbase.h" 14 15 namespace bdm{ 14 16 15 17 //! Base class of designers of control strategy … … 17 19 public: 18 20 //! Redesign control strategy 19 virtual redesign(){it_error("Not implemented"); };21 virtual void redesign(){it_error("Not implemented"); }; 20 22 //! apply control strategy to obtain control input 21 23 virtual vec apply(const vec &cond){it_error("Not implemented"); return vec(0);} 22 } 24 }; 23 25 24 26 //! Linear Quadratic Gaussian designer for constant penalizations and constant target … … 31 33 int dimu; 32 34 //! dimension of output 33 /int dimy;35 int dimy; 34 36 35 37 //! matrix A of the linear system … … 39 41 //! matrix C of the linear system 40 42 mat C; 41 //! expected value of x at time t42 vec xt;43 43 //! required value of the output y at time t (assumed constant) 44 44 vec y_req; … … 77 77 //! set system parameters from given matrices 78 78 void set_system_parameters(const mat &A, const mat &B, const mat &C); 79 //! set penalization matrices and control horizon 80 void set_control_parameters(const mat &Qy0, const mat &Qu0, const vec y_req0, int horizon0); 79 81 //! set system parameters from Kalman filter 80 void set_system_parameters(const Kalman &K); 81 //! set current state 82 void set_state(const vec &xt0){xt=xt0;}; 83 //! refresh temporary storage 84 //! function for future use which is called at each time td; 85 virtual update_state(){}; 82 // void set_system_parameters(const Kalman &K); 83 //! refresh temporary storage - inefficient can be improved 84 void prepare_qr(); 85 //! function for future use which is called at each time td; Should call prepare_qr()! 86 virtual void update_state(){}; 86 87 //! redesign one step of the 87 88 void ricatti_step(){ 88 89 pre_qr.set_submatrix(0,0,s*pr); 89 pre_qr.set_submatrix(dimx , dimu+dimx, -Qy*y_req);90 post_qr=qr(pre_qr);90 pre_qr.set_submatrix(dimx+dimu+dimy, dimu+dimx, -Qy*y_req); 91 if (!qr(pre_qr,post_qr)) it_warning("QR in LQG unstable"); 91 92 triu(post_qr); 92 93 // hn(m+1:2*m+n+r,m+1:2*m+n+r); 93 s=post_qr.get(dimu, 2*dimu+dimx+dimy , dimu, 2*dimu+dimx+dimy);94 s=post_qr.get(dimu, 2*dimu+dimx+dimy-1, dimu, 2*dimu+dimx+dimy-1); 94 95 }; 95 96 void redesign(){ … … 101 102 wsd=hn(1:m,1:m); 102 103 Lklq=-inv(wsd)*ws;*/ 103 L = -inv(post_qr.get(0,dimu-1, 0,dimu-1)) * post_qr.get(0,dimu , dimu, 2*dimu+dimx+dimy);104 L = -inv(post_qr.get(0,dimu-1, 0,dimu-1)) * post_qr.get(0,dimu-1, dimu, 2*dimu+dimx+dimy-1); 104 105 } 105 vec apply(const vec &state, const vec &ukm){vec pom=concat_vertical(state, ones(dimy,1), ukm); return L*pom;} 106 } 106 vec apply(const vec &state, const vec &ukm){vec pom=concat(state, ones(dimy), ukm); return L*pom;} 107 } ; 108 109 } // namespace