Changeset 1289 for applications/pmsm

Show
Ignore:
Timestamp:
03/10/11 14:03:12 (13 years ago)
Author:
vahalam
Message:
 
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • applications/pmsm/pmsm_ctrl.h

    r1279 r1289  
    408408                 
    409409                //create prediction 
    410                 p_isa.zeros(); 
     410                /*p_isa.zeros(); 
    411411                p_isb.zeros(); 
    412412                p_ome.zeros(); 
     
    498498UIREGISTER(PMSM_LQCtrl_dq); 
    499499 
     500class PMSM_LQCtrl_dq2: public PMSMCtrl{ 
     501public: 
     502/* 
     503PMSMCtrl: 
     504        double isa; 
     505        double isb; 
     506        double ome; 
     507        double the; 
     508        double Ww; 
     509*/       
     510 
     511//PMSM parameters 
     512        const double a; 
     513        const double b; 
     514        const double c; 
     515        const double d; 
     516        const double e; 
     517         
     518//input penalty 
     519        double r; 
     520         
     521//time step 
     522        const double Dt; 
     523         
     524//receding horizon 
     525        int rec_hor; 
     526         
     527//system matrices 
     528        mat A; //5x5 
     529        mat B; //5x2 
     530        //mat C; //2x5 
     531        mat Q; //5x5 
     532        mat R; //2x2     
     533         
     534//control matrix 
     535        mat L; 
     536        vec uab,udq; 
     537        vec icond; 
     538         
     539//control maximum 
     540        const double MAXu; 
     541         
     542//lqg controler class 
     543        LQG_universal lq;        
     544         
     545//prediction 
     546        vec p_isd, p_isq, p_ome, p_the; 
     547                 
     548        PMSM_LQCtrl_dq2():PMSMCtrl(), a(0.9898), b(0.0072), c(0.0361), d(1.0), e(0.0149), 
     549                                r(0.005), Dt(0.000125), rec_hor(10),                                    //for r is a default value rewrited by pcp.txt file value 
     550                                A(5, 5), B(5, 2), Q(5, 5), R(2, 2), 
     551                                uab(2), udq(2), icond(6), MAXu(100.0)   {                        
     552                //set fix matrices elements & dimensions 
     553                A.zeros(); 
     554                        A(0, 0) = A(1, 1) = a; 
     555                        A(2, 1) = e; 
     556                        A(2, 2) = d; 
     557                        A(2, 4) = d - 1; 
     558                        A(3, 2) = A(3, 4) = Dt; 
     559                        A(3, 3) = A(4, 4) = 1.0; 
     560                B.zeros(); 
     561                        B(0, 0) = B(1, 1) = c; 
     562                //C.zeros(); 
     563                //      C(0, 0) = C(1, 1) = 1.0; 
     564                Q.zeros(); 
     565                        Q(2, 2) = 1.0; 
     566                R.zeros(); 
     567                                                                 
     568        } 
     569                 
     570         
     571        virtual vec ctrlaction(const itpp::vec& cond) { 
     572                PMSMCtrl::ctrlaction(cond); // fills isa,isb,ome,the,Ww 
     573                 
     574                int i; 
     575                 
     576                lq.resetTime(); 
     577        //cout << "OK" << endl; 
     578                //create prediction 
     579                p_isd.zeros(); 
     580                p_isq.zeros(); 
     581                p_ome.zeros(); 
     582                p_the.zeros(); 
     583                p_isd(0) = isa*cos(the) + isb*sin(the);//isa; 
     584                p_isq(0) = isb*cos(the) - isa*sin(the);//isb; 
     585                p_ome(0) = ome; 
     586                p_the(0) = the; 
     587        //cout << "OKkkk" << endl;       
     588                for(i = 0; i < rec_hor-1; i++){ 
     589                        /*p_isa(i+1) = a*p_isa(i) + b*p_ome(i)*sin(p_the(i)) + c*0;//uab(0); //use last used control 
     590                        p_isb(i+1) = a*p_isb(i) - b*p_ome(i)*cos(p_the(i)) + c*0;//uab(1); 
     591                        p_ome(i+1) = d*p_ome(i) + e*(p_isb(i)*cos(p_the(i)) - p_isa(i)*sin(p_the(i))); 
     592                        p_the(i+1) = p_the(i) + Dt*p_ome(i);*/ 
     593                        p_isd(i+1) = a*p_isd(i) + p_isq(i)*p_ome(i)*Dt + c*udq(0); 
     594                        //cout << "OKaa" << endl; 
     595                        p_isq(i+1) = -p_isd(i)*p_ome(i)*Dt + a*p_isq(i) - b*p_ome(i) + c*udq(1); 
     596                        p_ome(i+1) = d*p_ome(i) + e*p_isq(i); 
     597                        p_the(i+1) = p_the(i) + Dt*p_ome(i); 
     598                        //cout << "1"; 
     599                } 
     600                 
     601                //create control matrix 
     602                for(i = rec_hor; i > 0; i--){            
     603                        //set variable matrices elements (A matrix only) 
     604                        /*A(0, 2) = b*sin(p_the(i)); 
     605                        A(0, 3) = b*(p_ome(i))*cos(p_the(i)); 
     606                        A(0, 4) = b*sin(p_the(i)); 
     607                        A(1, 2) = -b*cos(p_the(i)); 
     608                        A(1, 3) = b*(p_ome(i))*sin(p_the(i)); 
     609                        A(1, 4) = -b*cos(p_the(i)); 
     610                        A(2, 0) = -e*sin(p_the(i)); 
     611                        A(2, 1) = e*cos(p_the(i)); 
     612                        A(2, 3) = -e*(p_isa(i)*cos(p_the(i)) + p_isb(i)*sin(p_the(i)));*/ 
     613                        A(0, 1) = Dt*p_ome(i); 
     614                        A(0, 2) = Dt*p_isq(i); 
     615                        A(0, 4) = Dt*p_isq(i); 
     616                        A(1, 0) = -Dt*p_ome(i); 
     617                        A(1, 2) = -Dt*p_isd(i); 
     618                        A(1, 4) = -Dt*p_isq(i); 
     619                         
     620                        lq.Models(0).A = A;              
     621                        lq.redesign(); 
     622                } 
     623                lq.redesign(); 
     624                 
     625                L = lq.getL(); 
     626                //icond(0) = isa; 
     627                //icond(1) = isb; 
     628                icond(0) = isa*cos(the) + isb*sin(the); 
     629                icond(1) = isb*cos(the) - isa*sin(the); 
     630                icond(2) = ome - Ww; 
     631                icond(3) = the; 
     632                icond(4) = Ww; 
     633                icond(5) = 1; 
     634                vec tmp = L*icond;                   
     635                 
     636                //uab = tmp(0,1); 
     637                udq = tmp(0,1); 
     638                 
     639                uab = udq; //set size 
     640                uab(0) = udq(0)*cos(the) - udq(1)*sin(the); 
     641                uab(1) = udq(1)*cos(the) + udq(0)*sin(the); 
     642                 
     643                if(uab(0) > MAXu) uab(0) = MAXu; 
     644                else if(uab(0) < -MAXu) uab(0) = -MAXu; 
     645                if(uab(1) > MAXu) uab(1) = MAXu; 
     646                else if(uab(1) < -MAXu) uab(1) = -MAXu; 
     647                 
     648                return uab; 
     649        }; 
     650        void from_setting(const Setting &set){ 
     651                PMSMCtrl::from_setting(set); 
     652                UI::get(r,set, "r", UI::optional); 
     653                UI::get(rec_hor,set, "h", UI::optional); 
     654        } 
     655 
     656        void validate(){ 
     657                R(0,0)=R(1,1)=r; 
     658 
     659                p_isd.set_length(rec_hor+1); 
     660                p_isq.set_length(rec_hor+1); 
     661                p_ome.set_length(rec_hor+1); 
     662                p_the.set_length(rec_hor+1); 
     663 
     664                Array<quadraticfn> qloss(2); 
     665                qloss(0).Q.setCh(Q); 
     666                qloss(0).rv = RV("x", 5, 1); 
     667                qloss(1).Q.setCh(R); 
     668                qloss(1).rv = RV("u", 2, 0);             
     669                lq.Losses = qloss;               
     670 
     671                                //set lq 
     672                lq.rv = RV("u", 2, 0);                   
     673                lq.set_rvc(RV("x", 5, 0)); 
     674                lq.horizon = rec_hor;    
     675                 
     676                Array<linfnEx> model(2); 
     677                model(0).A = A; 
     678                model(0).B = vec("0 0 0 0 0"); 
     679                model(0).rv = RV("x", 5, 0); 
     680                model(0).rv_ret = RV("x", 5, 1); 
     681                model(1).A = B; 
     682                model(1).B = vec("0 0"); 
     683                model(1).rv = RV("u", 2, 0); 
     684                model(1).rv_ret = RV("x", 5, 1); 
     685                lq.Models = model; 
     686                 
     687                lq.finalLoss.Q.setCh(Q); 
     688                lq.finalLoss.rv = RV("x", 5, 1); 
     689                 
     690                lq.validate(); 
     691                                                 
     692                uab.zeros(); 
     693                udq.zeros(); 
     694 
     695        } 
     696}; 
     697UIREGISTER(PMSM_LQCtrl_dq2); 
     698 
    500699/*!@}*/ 
    501700#endif //PMSM_CTR_H