Changeset 696

Show
Ignore:
Timestamp:
11/03/09 00:03:27 (14 years ago)
Author:
smidl
Message:

Cleanup Controller/Designer

Location:
library
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/design/ctrlbase.h

    r676 r696  
    1616namespace bdm{ 
    1717 
    18 //! Low-level class for design of control strategy 
    19 class Designer  { 
     18        //! Base class for adaptive controllers  
     19        //! The base class is, however, non-adaptive, method \c adapt() is empty. 
     20        //! \note advanced Controllers will probably include estimator as their internal attribute (e.g. dual controllers) 
     21        class Controller : public root { 
     22                protected: 
     23                        //! identifier of the designed action; 
     24                        RV rv; 
     25                        //! identifier of the conditioning variables; 
     26                        RV rvc; 
     27                public: 
     28                        //! function processing new observations and adapting control strategy accordingly 
     29                        virtual void redesign(const vec &data){}; 
     30                        //! returns designed control action 
     31                        virtual vec ctrlaction(const vec &cond){return vec(0);} 
     32                         
     33                        void from_setting(const Setting &set){ 
     34                                UI::get(rv,set,"rv",UI::optional); 
     35                                UI::get(rvc,set,"rvc",UI::optional); 
     36                        } 
     37                        //! access function 
     38                        const RV& _rv() {return rv;} 
     39                        //! access function 
     40                        const RV& _rvc() {return rvc;} 
     41                        //! register this controller with given datasource under name "name" 
     42                        virtual void log_register (logger &L,  int level, const string &prefix ) { } 
     43                        //! write requested values into the logger 
     44                        virtual void log_write ( ) const { } 
     45                         
     46        }; 
    2047         
    21         public: 
    22                 //! Redesign control strategy  
    23                 virtual void redesign() { 
    24                         bdm_error("Not implemented"); 
    25                 } 
    26  
    27                 //! apply control strategy to obtain control input 
    28                 virtual vec apply(const vec &cond) { 
    29                         bdm_error("Not implemented"); 
    30                         return vec(); 
    31                 } 
    32 }; 
    33  
    3448//! Linear Quadratic Gaussian designer for constant penalizations and constant target 
    3549//! Its internals are very close to Kalman estimator 
    36 class LQG : public Designer { 
     50class LQG : public Controller { 
    3751        protected: 
    3852                //! StateSpace model from which we read data 
     
    113127                } 
    114128                //! compute control action 
    115                 vec apply(const vec &state, const vec &ukm){vec pom=concat(state, ones(dimy), ukm); return L*pom;} 
     129                vec ctrlaction(const vec &state, const vec &ukm){vec pom=concat(state, ones(dimy), ukm); return L*pom;} 
    116130        } ; 
    117131 
    118         //! Base class for adaptive controllers  
    119         //! The base class is however non-adaptive, method \c adapt() is empty. 
    120         //! \note advanced Controllers will probably include estimator as their internal attribute (e.g. dual controllers) 
    121         class Controller : public root { 
    122                 protected: 
    123                 //! identifier of the system output; 
    124                 RV yrv; 
    125                 //! identifier of the system input; 
    126                 RV urv; 
    127                 //! description of data needed for \c ctrlaction , required for automatic connection to DS 
    128                 RV drv; 
    129                 //! vector of logger IDs 
    130                 ivec LIDs; 
    131                 public: 
    132                         //! function processing new observations and adapting control strategy accordingly 
    133                         virtual void adapt(const vec &data){}; 
    134                         //! returns designed control action 
    135                         virtual vec ctrlaction(const vec &data){return vec(0);} 
    136                          
    137                         void from_setting(const Setting &set){ 
    138                                 UI::get(yrv,set,"yrv",UI::optional); 
    139                                 UI::get(yrv,set,"urv",UI::optional); 
    140                         } 
    141                         //! access function 
    142                         const RV& _urv() {return urv;} 
    143                         //! access function 
    144                         const RV& _yrv() {return yrv;} 
    145                         //! access function 
    146                         const RV& _drv() {return drv;} 
    147                         //! register this controller with given datasource under name "name" 
    148                         virtual void log_register (logger &L,  int level, const string &prefix ) { } 
    149                         //! write requested values into the logger 
    150                         virtual void log_write ( ) const { } 
    151                          
    152         }; 
    153132                         
    154133} // namespace 
  • library/tests/LQG_test.cpp

    r689 r696  
    1414 
    1515        reg.redesign(); 
    16         double reg_apply=reg.apply("0.5, 1.1","0.0")(0); /*convert vec to double*/ 
     16        double reg_apply=reg.ctrlaction("0.5, 1.1","0.0")(0); /*convert vec to double*/ 
    1717        CHECK_CLOSE(reg_apply, -0.248528137234392, 0.0001); 
    1818}