mixpp: ctrlbase.h Source File

ctrlbase.h

Go to the documentation of this file.
00001
00013 #ifndef CTRL_BASE
00014 #define CTRL_BASE
00015 
00016
00017 #include "../base/bdmbase.h"
00018 #include "../estim/kalman.h"
00019
00020 namespace bdm {
00021
00025 class Controller : public root {
00026   public:
00028     RV rv;
00029 protected:
00031     RV rvc;
00032 public:
00034     virtual void adapt ( const vec &data ) {};
00036     virtual void redesign() {};
00038     virtual vec ctrlaction ( const vec &cond ) {
00039         return vec ( 0 );
00040     }
00041
00042     void from_setting ( const Setting &set ) {
00043         shared_ptr<RV> rv_ptr = UI::build<RV>( set, "rv", UI::optional );
00044         if( rv_ptr ) rv = *rv_ptr;
00045         shared_ptr<RV> rvc_ptr = UI::build<RV>( set, "rvc", UI::optional );
00046         if( rvc_ptr ) rvc = *rvc_ptr;
00047     }
00049     const RV& _rv() {
00050         return rv;
00051     }
00053     const RV& _rvc() {
00054         return rvc;
00055     }
00057     virtual void log_register ( logger &L, const string &prefix ) { }
00059     virtual void log_write ( ) const { }
00060
00061 };
00062
00065 class LQG : public Controller {
00066 protected:
00068     shared_ptr<StateSpace<chmat> > S;
00070     vec y_req;
00072     vec u_req;
00073
00075     int horizon;
00077     chmat Qy;
00079     chmat Qu;
00081     int td;
00083     mat L;
00084
00087     int dimx;
00089     int dimy;
00091     int dimu;
00092
00094     mat pr;
00096     mat qux;
00098     mat qyx;
00100     mat s;
00102     mat qy;
00104     mat hqy;
00106     mat pre_qr;
00108     mat post_qr;
00110
00111 public:
00113     void set_system ( shared_ptr<StateSpace<chmat> > S0 );
00115     void update_system();
00117     void set_control_parameters ( const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0 );
00119     void set_control_Qy ( const mat &Qy0 ) {
00120         Qy = Qy0;
00121     }
00123     void initial_belmann() {
00124         s = 1e-5 * eye ( dimx + dimu + dimy );
00125     };
00127     void validate();
00130     void ricatti_step();
00131
00132     void redesign();
00133
00135     vec ctrlaction ( const vec &state, const vec &ukm ) {
00136         vec pom = concat ( state, ones ( dimy ), ukm );
00137         return L*pom;
00138     }
00140     mat _L() const {
00141         return L;
00142     }
00143 } ;
00144
00145
00146 } // namespace
00147
00148 #endif //CTRL_BASE

Generated on 2 Dec 2013 for mixpp by  doxygen 1.4.7