| 40 | | vec state; |
| | 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 | |
| | 58 | public: |
| | 59 | |
| | 60 | PMSMCtrl():Controller() { |
| | 61 | rv = RV("{ua ub }"); |
| | 62 | rvc = RV("{o_ia o_ib o_ua o_ub o_om o_th Ww }"); |
| | 63 | } |
| | 64 | |
| | 65 | void adapt(const itpp::vec& data){ |
| | 66 | if (estim){ |
| | 67 | vec y=data.get(0,1); |
| | 68 | vec u=data.get(2,3); |
| | 69 | Est->bayes(y,u); |
| | 70 | } |
| | 71 | } |
| | 72 | |
| | 73 | |
| | 74 | virtual vec ctrlaction(const itpp::vec& cond) { |
| | 75 | |
| | 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{ |
| 45 | | |
| 46 | | PMSM_PICtrl(): Cwq(3.0, 3.0*0.000125/0.1, -1200, 1200), |
| 47 | | Cuq(20.0, 20.0*0.000125/0.005, -1200, 1200), |
| 48 | | Cud(20.0, 20.0*0.000125/0.005, -1200, 1200) |
| 49 | | { |
| 50 | | rv = RV("{ua ub }"); |
| 51 | | rvc = RV("{o_ia o_ib o_ua o_ub Ww o_om o_th }"); |
| 52 | | } |
| | 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 | |
| 54 | | void adapt(const itpp::vec& data){ |
| 55 | | vec y=data.get(0,1); |
| 56 | | vec u=data.get(2,3); |
| 57 | | Est->bayes(y,u); |
| 58 | | |
| 59 | | } |
| 60 | | |
| 61 | | |
| 62 | | virtual vec ctrlaction(const itpp::vec& cond) { |
| 63 | | vec x_est=Est->posterior().mean(); |
| 64 | | double isa=cond(0);//x_est(0); |
| 65 | | double isb=cond(1);//x_est(1); |
| 66 | | double ome=cond(5);//x[2];//x_est(2); |
| 67 | | double the=cond(6);//x_est(3); |
| 68 | | double Ww=cond(4); |
| | 119 | virtual vec ctrlaction(const itpp::vec& cond) { |
| | 120 | PMSMCtrl::ctrlaction(cond); // fills isa,isb,om,the |