⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bc_user2.c.bak

📁 感应电动机的实例仿真例子
💻 BAK
字号:
 #include <math.h>
__declspec(dllexport)

#define Pi  3.14159265359
#define Iqsemax  20
#define Iqsemin  -20
#define Vqsemax  180
#define Vqsemin  -180
#define Vdsemax  75
#define Vdsemin  -75

void bc_user2 (t, delt, in, out)
double t, delt;
double *in, *out;
{
static double Ts =1./10000. , Tsv=1./1000.; 


                          

//---------------------------------//
//------------system---------------//
//---------------------------------//

static double P=4.,Jm=0.0071,Lm=0.076,Lrl=0.003,Lsl=0.003,Rr=0.93 ,Rs=0.533;
static double Lsigma=0.,Ls=0.,Lr=0.,Lamdref=0.44954,Te=0;




//---------------------------------//
//------------Voltage--------------//
//---------------------------------//

static double Vdc=0.;
static double Vqse_ref=0.,Vqse_ref_a=0.,Vqse_ref_b=0.,Vqse_ref_c=0.,Vqse_ref_integ=0.;
static double Vdse_ref=0.,Vdse_ref_a=0.,Vdse_ref_b=0.,Vdse_ref_c=0.,Vdse_ref_integ=0.;
static double Vds_ref=0.,Vqs_ref=0.;
static double Vasi_ref=0., Vbsi_ref=0., Vcsi_ref=0.;
static double Eqse=0.,Edse=0.;



//---------------------------------//
//------------Current--------------//
//---------------------------------//

static double Iqse_ref=0.,Iqse_ref_integ=0.,Iqse_ref_a=0.;
static double Idse_ref=0, Iqse_err=0.,Idse_err=0.;
static double Ia=0.,Ib=0.,Ic=0.,Iqs=0.,Ids=0.,Iqse=0,Idse=0.;



//---------------------------------//
//------------speed----------------//
//---------------------------------//

static double Wrad_ref=0.,Wrad=0.,Wrpm_ref=0.,Wrpm=0.,Wrad_err=0.,direction=0.;

//---------------------------------//
//------------gain-----------------//
//---------------------------------//

static double Ki_sc=0., Kp_sc=0.,Kt=0.,Wc_sc=150.,Tfactor=0.;
static double Ki_c=0.,Kp_c=0.,Wc=2000.;

//---------------------------------//
//------------slip / angle---------//
//---------------------------------//

static double Wsl=0.,theta=0.,We=0.;





//---------------------------------//
//-------Space Vector PWM----------//
//---------------------------------//

double Ta=0.,Tb=0.,Tc=0.;
double Tmax=0.,Tmin=0.,Teff=0.,Tzero=0.,Toffs=0.;
double Tga=0.,Tgb=0.,Tgc=0. ,Sa=0.,Sb=0.,Sc=0.;
static double Tmode=0.,mode=0.,seq=1.;


//---------------------------------//
//------------etc------------------//
//---------------------------------//
static double Pout=0.,count=0.,a=0.;


//-----------------------------------//
//--------- Counter ------------------//
//------------------------------------//

static double cnt=0.;


//---------------------------------//
//--------system input-------------//
//---------------------------------//


   Ia=in[0];
   Ib=in[1];
   Wrpm=in[2];
   Vdc=in[3];




//----------------------------------------------------------------//
//------------------------parameter calculation-------------------//
//----------------------------------------------------------------//
   Lr=Lm+Lrl;
   Ls=Lm+Lsl;
   Lsigma=Ls-(Lm*Lm/Lr);



//----------------------------------------------------------------//
//------------------------speed gain calculation------------------//
//----------------------------------------------------------------//

     Kp_sc=Jm*Wc_sc;
     Ki_sc=Kp_sc*Wc_sc/5 ;


     Kp_c=Wc*Lsigma;
     Ki_c=(Rs+Rr*(Lm*Lm)/(Lr*Lr))*Wc;

//--------------------------------------------------------------//
//--------------------- Build up ------------------------------//
//--------------------------------------------------------------//

      cnt=cnt+1.;
      if (cnt<440)
      Iqse_ref=0.;
      else
      {

//----------------------------------------------------------------//
//---------------------speed controller---------------------------//
//----------------------------------------------------------------//
direction=t;
if(direction<0.7)
	  {if(Wrpm_ref<=900) 
        Wrpm_ref=Wrpm_ref+1.;}
 else
 	{     
    if(direction>=0.7) 
        if(direction<1.45)
           {if(Wrpm_ref>=-900)
   	        Wrpm_ref=Wrpm_ref-1.;}
   	      else
   	       {if(Wrpm_ref<=0)
              Wrpm_ref=Wrpm_ref+1.;}
  }
      
       Wrpm_ref=Wrpm_ref; 
       Wrad_ref = Wrpm_ref*(2.*Pi)/60.;
       Wrad = Wrpm*(2.*Pi)/60.;
       //    Ki_sc=220.;
       //  Kp_sc=12.;

       count=count+1.;
       if (count==9.) {
       Wrad_err=Wrad_ref-Wrad;
       Iqse_ref_integ=Iqse_ref_integ+Ki_sc*Ts*9.*(Wrad_err-(1./Kp_sc)*(Iqse_ref_a-Iqse_ref));
       Iqse_ref_a=Iqse_ref_integ+Kp_sc*Wrad_err;
       Iqse_ref=((Iqse_ref_a>Iqsemax)? Iqsemax : (Iqse_ref_a<Iqsemin) ? Iqsemin : Iqse_ref_a);

       count=1.;}
       else Iqse_ref=Iqse_ref;
 
}

//----------------------------------------------------------------//
//--------------------exitation current---------------------------//
//----------------------------------------------------------------//

  Idse_ref=Lamdref/Lm;
      //Idse_ref=13.;
//----------------------------------------------------------------//
//--------------------slip & theta calculation--------------------//
//----------------------------------------------------------------//

   a=Iqse_ref/Lamdref;
   Wsl=a*(Rr*Lm)/Lr;
   We=Wsl+Wrad*(P/2.);
   theta=theta+ We*Ts;





//----------------------------------------------------------------//
//------------------3 phase --> 2 phase---------------------------//
//----------------------------------------------------------------//
	Ic = -Ia-Ib;
  	Ids = Ia;
	Iqs = (Ib-Ic)/sqrt(3);

	Idse = Ids*cos(theta) + Iqs*sin(theta);  //Synchronous Frame
	Iqse = -Ids*sin(theta)+ Iqs*cos(theta);



//----------------------------------------------------------------//
//--------------------back emf calculation------------------------//
//----------------------------------------------------------------//

   Edse=-We*Lsigma*Iqse_ref;
   Eqse=We*Ls*Idse_ref;


//----------------------------------------------------------------//
//--------------------Current Controller--------------------------//
//----------------------------------------------------------------//



//q_axis current controller//
   Iqse_err=Iqse_ref-Iqse;
   Vqse_ref_integ=Vqse_ref_integ+Ki_c*Ts*(Iqse_err-(1./Kp_c)*(Vqse_ref_c-Vqse_ref));
   Vqse_ref_a=Vqse_ref_integ+Kp_c*Iqse_err;
   Vqse_ref_b=Eqse;
   Vqse_ref_c=Vqse_ref_a+Vqse_ref_b;
   Vqse_ref=((Vqse_ref_c>Vqsemax)?Vqsemax : (Vqse_ref_c<Vqsemin)?Vqsemin : Vqse_ref_c);

//d_axis current controller//
   Idse_err=Idse_ref-Idse;
   Vdse_ref_integ=Vdse_ref_integ+Ki_c*Ts*(Idse_err-(1./Kp_c)*(Vdse_ref_c-Vdse_ref));
   Vdse_ref_a=Vdse_ref_integ+Kp_c*Idse_err;
   Vdse_ref_b=Edse;
   Vdse_ref_c=Vdse_ref_a+Vdse_ref_b;
   Vdse_ref=((Vdse_ref_c>Vdsemax)?Vdsemax : (Vdse_ref_c<Vdsemin)?Vdsemin : Vdse_ref_c);




//----------------------------------------------------------------//
//----- Rotating-to-stationary co-ordinate transformation---------//
//----------------------------------------------------------------//

	Vds_ref =  Vdse_ref * cos(theta) - Vqse_ref * sin(theta);
	Vqs_ref =  Vdse_ref * sin(theta) + Vqse_ref * cos(theta);



//----------------------------------------------------------------//
//------------ 2 phase ---> 3 phase-------------------------------//
//----------------------------------------------------------------//

          Vasi_ref =  Vds_ref;
          Vbsi_ref = -(1./2.)* Vds_ref + sqrt(3.)/2. * Vqs_ref;
          Vcsi_ref = -(1./2.)* Vds_ref - sqrt(3.)/2.* Vqs_ref;

//----------------------------------------------------------------//
//------------ imaginary phase time calculation-------------------//
//----------------------------------------------------------------//

          Ta = Vasi_ref*Ts/(Vdc+0.000000000001);
	      Tb = Vbsi_ref*Ts/(Vdc+0.000000000001);
	      Tc = Vcsi_ref*Ts/(Vdc+0.000000000001);

//----------------------------------------------------------------//
//---------------3-element Sort Algorithm-------------------------//
//----------------------------------------------------------------//

          Tmax = Ta;
          Tmin = Ta;
          if(Tb>Tmax)	Tmax = Tb;
          if(Tb<Tmin)	Tmin = Tb;
          if(Tc>Tmax)	Tmax = Tc;
          if(Tc<Tmin)	Tmin = Tc;

//----------------------------------------------------------------//
//-----------------Effective Time Calculation---------------------//
//----------------------------------------------------------------//

          Teff = Tmax-Tmin;
	      Tzero = Ts-Teff;
	      Toffs = Tzero/2. - Tmin;

//----------------------------------------------------------------//
//---------------------OverModulation-----------------------------//
//----------------------------------------------------------------//

          if(Tzero < 0.){
          	Ta *= Ts/Teff;
          	Tb *= Ts/Teff;
         	Tc *= Ts/Teff;
          	Toffs = -Tmin*Ts/Teff;
             }

         Tga = Ta + Toffs;
    	 Tgb = Tb + Toffs;
    	 Tgc = Tc + Toffs;

         seq=-seq;


         if(seq>0.){
            Tga = Ts - Tga;
	        Tgb = Ts - Tgb;
         	Tgc = Ts - Tgc;
            } 



//----------------------------------------------------------------//
//---------------------motor output-----------------------------//
//----------------------------------------------------------------//

   Pout=3/2*(Vdse_ref*Idse_ref+Vqse_ref*Iqse_ref);
  
//----------------------------------------------------------------//
//------------------------system output---------------------------//
//----------------------------------------------------------------//

//----------------------------------------------------------------//
//------------------------system output---------------------------//
//----------------------------------------------------------------//   
   
         out[0]  = Tga ;
         out[1]  = Tgb ;
         out[2]  = Tgc ;
         out[3] = seq;
    	 out[4]=Wrpm;
         out[5]=Wrpm_ref;
         //out[6]=Iqse;
         //out[7]=Idse;
	     out[6]=Iqse;
         out[7]=Idse;
        out[8]=Iqse_ref ;
        out[9]=Idse_ref;
	//	 out[8]=Eqse;
        // out[9]=Edse;
    	// out[10]=Vasi_ref;
    	 out[10]=Pout;
    	 out[11]=Te;

     
    
    
    
      



   }








⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -