[1243] | 1 | #ifndef PMSM_CTR_H |
---|
| 2 | #define PMSM_CTR_H |
---|
| 3 | |
---|
| 4 | #include <design/ctrlbase.h> |
---|
| 5 | #include "pmsm.h" |
---|
| 6 | |
---|
| 7 | /*! \defgroup PMSM |
---|
| 8 | @{ |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | using namespace bdm; |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | /*! PI Controller*/ |
---|
| 15 | class PI_ctrl: public Controller{ |
---|
| 16 | public: |
---|
| 17 | //!integral state |
---|
| 18 | double S; |
---|
| 19 | double Pd; |
---|
| 20 | double Pi; |
---|
| 21 | double minOut; |
---|
| 22 | double maxOut; |
---|
| 23 | |
---|
| 24 | PI_ctrl(double Pd0, double Pi0, double minOut0, double maxOut0): S(0.0), Pd(Pd0), Pi(Pi0),minOut(minOut0),maxOut(maxOut0){} |
---|
| 25 | virtual vec ctrlaction ( const vec &cond ) { |
---|
| 26 | double tmp; |
---|
| 27 | tmp = Pd*cond(0)+S; |
---|
| 28 | |
---|
| 29 | S += Pi*cond(0); |
---|
| 30 | |
---|
| 31 | if (tmp>maxOut) tmp=maxOut; |
---|
| 32 | if (tmp<minOut) tmp=minOut; |
---|
| 33 | return vec_1(tmp); |
---|
| 34 | } |
---|
| 35 | }; |
---|
| 36 | |
---|
[1251] | 37 | /*! \brief Root class for controllers of PMSM |
---|
| 38 | * |
---|
| 39 | * It defines the interface for controllers that connect to the pmsmDSctrl. |
---|
| 40 | * The adapt() function calls bayes() of an internal BM. Note that it is assumed that the estimator is compatible with PMSM system. |
---|
| 41 | * I.e. it must have rv={ia, ib} and rvc={ua,ub}, any other BM will not work. |
---|
| 42 | * |
---|
| 43 | */ |
---|
| 44 | class PMSMCtrl: public Controller{ |
---|
[1243] | 45 | protected: |
---|
[1251] | 46 | //! Est where rv and rcv are not used! |
---|
[1243] | 47 | shared_ptr<BM> Est; |
---|
[1251] | 48 | //! switch to use or not to use the internal estimator |
---|
| 49 | bool estim; |
---|
| 50 | |
---|
| 51 | // internal quantities filled by PMSMCtrl::ctrlaction() |
---|
| 52 | double isa; |
---|
| 53 | double isb; |
---|
| 54 | double ome; |
---|
| 55 | double the; |
---|
| 56 | double Ww; |
---|
| 57 | |
---|
[1243] | 58 | public: |
---|
| 59 | |
---|
[1251] | 60 | PMSMCtrl():Controller() { |
---|
[1243] | 61 | rv = RV("{ua ub }"); |
---|
[1251] | 62 | rvc = RV("{o_ia o_ib o_ua o_ub o_om o_th Ww }"); |
---|
[1243] | 63 | } |
---|
| 64 | |
---|
| 65 | void adapt(const itpp::vec& data){ |
---|
[1251] | 66 | if (estim){ |
---|
| 67 | vec y=data.get(0,1); |
---|
| 68 | vec u=data.get(2,3); |
---|
| 69 | Est->bayes(y,u); |
---|
| 70 | } |
---|
[1243] | 71 | } |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | virtual vec ctrlaction(const itpp::vec& cond) { |
---|
| 75 | |
---|
[1251] | 76 | if (estim){ |
---|
| 77 | vec x_est=Est->posterior().mean(); |
---|
| 78 | isa=x_est(0); |
---|
| 79 | isb=x_est(1); |
---|
| 80 | ome=x_est(2); |
---|
| 81 | the=x_est(3); |
---|
| 82 | } else { |
---|
| 83 | isa=cond(0);//x_est(0); |
---|
| 84 | isb=cond(1);//x_est(1); |
---|
| 85 | ome=cond(4);//x[2];//x_est(2); |
---|
| 86 | the=cond(5);//x_est(3); |
---|
| 87 | } |
---|
| 88 | Ww=cond(6); |
---|
| 89 | |
---|
| 90 | return empty_vec; // dummy return |
---|
| 91 | }; |
---|
| 92 | void from_setting(const libconfig::Setting& set){ |
---|
| 93 | Controller::from_setting(set); |
---|
| 94 | Est=UI::build<BM>(set,"estim",UI::optional); |
---|
| 95 | estim = Est; |
---|
| 96 | } |
---|
| 97 | void log_register ( logger &L, const string &prefix ) { |
---|
| 98 | Controller::log_register(L,prefix); |
---|
| 99 | if (estim) Est->log_register(L,prefix); |
---|
| 100 | } |
---|
| 101 | void log_write() const{ |
---|
| 102 | if (estim) Est->log_write(); |
---|
| 103 | } |
---|
| 104 | }; |
---|
| 105 | //UIREGISTER(PMSMCtrl); -- abstract |
---|
| 106 | |
---|
| 107 | class PMSM_PICtrl: public PMSMCtrl{ |
---|
| 108 | public: |
---|
| 109 | PI_ctrl Cwq; |
---|
| 110 | PI_ctrl Cuq; |
---|
| 111 | PI_ctrl Cud; |
---|
| 112 | |
---|
| 113 | PMSM_PICtrl():PMSMCtrl(), |
---|
| 114 | Cwq(3.0, 3.0*0.000125/0.1, -1200, 1200), |
---|
| 115 | Cuq(20.0, 20.0*0.000125/0.005, -1200, 1200), |
---|
| 116 | Cud(20.0, 20.0*0.000125/0.005, -1200, 1200) {} |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | virtual vec ctrlaction(const itpp::vec& cond) { |
---|
| 120 | PMSMCtrl::ctrlaction(cond); // fills isa,isb,om,the |
---|
| 121 | |
---|
[1243] | 122 | double Isd = isa*cos(the)+isb*sin(the); |
---|
| 123 | double Isq = isb*cos(the)-isa*sin(the); |
---|
| 124 | |
---|
| 125 | double Iqw=(Cwq.ctrlaction(vec_1(Ww-ome)))(0); // conversion from vec |
---|
| 126 | |
---|
| 127 | double ud = (Cud.ctrlaction(vec_1(-Isd)))(0); |
---|
| 128 | double uq = (Cuq.ctrlaction(vec_1(Iqw-Isq)))(0); |
---|
| 129 | |
---|
| 130 | const double Ls0=0.003465; // inductance |
---|
| 131 | const double Fmag0= 0.1989; // Magnetic?? |
---|
[1251] | 132 | |
---|
[1243] | 133 | ud-=Ls0*ome*Iqw; // har |
---|
| 134 | uq+=Fmag0*ome; |
---|
| 135 | |
---|
| 136 | double Um = sqrt(ud*ud+uq*uq); |
---|
| 137 | double beta = atan(uq/ud); |
---|
| 138 | if (ud<0) beta += M_PI; |
---|
| 139 | beta +=the; |
---|
| 140 | |
---|
| 141 | vec uab(2); |
---|
| 142 | uab(0)=Um*cos(beta); // usx = usa |
---|
| 143 | uab(1)=Um*sin(beta); // usy |
---|
| 144 | |
---|
| 145 | return uab; |
---|
| 146 | }; |
---|
| 147 | }; |
---|
| 148 | UIREGISTER(PMSM_PICtrl); |
---|
| 149 | |
---|
| 150 | /*!@}*/ |
---|
| 151 | #endif //PMSM_CTR_H |
---|