root/library/bdm/design/ctrlbase.h

Revision 1243, 4.0 kB (checked in by smidl, 13 years ago)

Contrallable PMSM DS + PI control

  • Property svn:eol-style set to native
Line 
1/*!
2  \file
3  \brief Base classes for designers of control strategy
4  \author Vaclav Smidl.
5
6  -----------------------------------
7  BDM++ - C++ library for Bayesian Decision Making under Uncertainty
8
9  Using IT++ for numerical operations
10  -----------------------------------
11*/
12
13#ifndef CTRL_BASE
14#define CTRL_BASE
15
16
17#include "../base/bdmbase.h"
18#include "../estim/kalman.h"
19
20namespace bdm {
21
22//! Base class for adaptive controllers
23//! The base class is, however, non-adaptive, method \c adapt() is empty.
24//! \note advanced Controllers will probably include estimator as their internal attribute (e.g. dual controllers)
25class Controller : public root {
26  public:
27    //! identifier of the designed action;
28    RV rv;
29protected:
30    //! identifier of the conditioning variables - data needed ;
31    RV rvc;
32public:
33    //! function processing new observations and adapting control strategy accordingly
34    virtual void adapt ( const vec &data ) {};
35    //! function redesigning the control strategy
36    virtual void redesign() {};
37    //! returns designed control action
38    virtual vec ctrlaction ( const vec &cond ) {
39        return vec ( 0 );
40    }
41
42    void from_setting ( const Setting &set ) {
43        shared_ptr<RV> rv_ptr = UI::build<RV>( set, "rv", UI::optional );
44        if( rv_ptr ) rv = *rv_ptr;
45        shared_ptr<RV> rvc_ptr = UI::build<RV>( set, "rvc", UI::optional );
46        if( rvc_ptr ) rvc = *rvc_ptr;
47    }
48    //! access function
49    const RV& _rv() {
50        return rv;
51    }
52    //! access function
53    const RV& _rvc() {
54        return rvc;
55    }
56    //! register this controller with given datasource under name "name"
57    virtual void log_register ( logger &L, const string &prefix ) { }
58    //! write requested values into the logger
59    virtual void log_write ( ) const { }
60
61};
62
63//! Linear Quadratic Gaussian designer for constant penalizations and constant target
64//! Its internals are very close to Kalman estimator
65class LQG : public Controller {
66protected:
67    //! StateSpace model from which we read data
68    shared_ptr<StateSpace<chmat> > S;
69    //! required value of the output y at time t (assumed constant)
70    vec y_req;
71    //! required value of the output y at time t (assumed constant)
72    vec u_req;
73
74    //! Control horizon, set to maxint for infinite horizons
75    int horizon;
76    //! penalization matrix Qy
77    chmat Qy;
78    //! penalization matrix Qu
79    chmat Qu;
80    //! time of the design step - from horizon->0
81    int td;
82    //! controller parameters
83    mat L;
84
85    //!@{ \name temporary storage for ricatti - use initialize
86    //! convenience parameters
87    int dimx;
88    //! convenience parameters
89    int dimy;
90    //! convenience parameters
91    int dimu;
92
93    //!  parameters
94    mat pr;
95    //! penalization
96    mat qux;
97    //! penalization
98    mat qyx;
99    //! internal quadratic form
100    mat s;
101    //! penalization
102    mat qy;
103    //! pre_qr part
104    mat hqy;
105    //! pre qr matrix
106    mat pre_qr;
107    //! post qr matrix
108    mat post_qr;
109    //!@}
110
111public:
112    //! set system parameters from given matrices
113    void set_system ( shared_ptr<StateSpace<chmat> > S0 );
114    //! update internal whan system has changed
115    void update_system();
116    //! set penalization matrices and control horizon
117    void set_control_parameters ( const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0 );
118    //! set penalization matrices and control horizon
119    void set_control_Qy ( const mat &Qy0 ) {
120        Qy = Qy0;
121    }
122    //! refresh temporary storage - inefficient can be improved
123    void initial_belmann() {
124        s = 1e-5 * eye ( dimx + dimu + dimy );
125    };
126    //! validation procedure
127    void validate();
128    //! function for future use which is called at each time td; Should call initialize()!
129    //! redesign one step of the
130    void ricatti_step();
131
132    void redesign();
133
134    //! compute control action
135    vec ctrlaction ( const vec &state, const vec &ukm ) {
136        vec pom = concat ( state, ones ( dimy ), ukm );
137        return L*pom;
138    }
139    //! access function
140    mat _L() const {
141        return L;
142    }
143} ;
144
145
146} // namespace
147
148#endif //CTRL_BASE
Note: See TracBrowser for help on using the browser.