資源簡介
PI控制算法是控制系統中常用的簡單有效的方法,用C語言實現數字PI軟件算法,適用于各類嵌入式系統中

代碼片段和文件信息
/**
??******************************************************************************
??*?@file???:?PI_Controller.c
??*?@author?:?wind
??*?@version:1.0.0
??*?@date???:20150418
??*?@brief??:
??******************************************************************************
??*/
/*?---------------------------------------------------------------------------*/
/************聲明和定義,通常放在頭文件中********/
typedef?struct
{
int?SetValue;????????//設置值
int?An; //當前誤差e(n)的系數,=kp+ki
int?Bn_1; //前一項誤差e(n-1)的系數,=?-kp
int?Limit; //限制最大最小值
int?Errorn_1; //e(n-1)
int?DeltaUn; //輸出增量△u(n);
int?Un_output; //輸出值?u(n)
}PI_Typedef;
void?PI_StructInit(PI_Typedef?*PI_Structint?Kpint?Kiint?limit);
void?PI_Controller(PI_Typedef?*PI_Structint?NewInputint?*Output);
/*****************************************************************/
void?PI_StructInit(PI_Typedef?*PI_Structint?Kpint?Kiint?limit)
{
PI_Struct->SetValue?=?0;
PI_Struct->An?=?Kp+Ki;
PI_Struct->Bn_1?=?-Kp;
PI_Struct->Limit?=?limit;
PI_Struct->DeltaUn?=?0;
PI_Struct->Errorn_1?=?0;
}
void?PI_Controller(PI_Typedef?*PI_Structint?NewInputint?*Output)
{
int?Errorn?=0;
Errorn?=?PI_Struct->SetValue?-?NewInput;//計算e(n)
PI_Struct->DeltaUn?=?(PI_Struct->An)*Errorn+(PI_Struct->Bn_1)*(PI_Struct->Errorn_1);//計算增量
PI_Struct->Errorn_1?=?Errorn;//保存誤差e(n)作為下一次計算的e(n-1)
//限制增量的范圍
if(PI_Struct->DeltaUn?>?PI_Struct->Limit)
{PI_Struct->DeltaUn?=?PI_Struct->Limit;}
else?if(PI_Struct->DeltaUn?-PI_Struct->Limit)
{PI_Struct->DeltaUn?=?-PI_Struct->Limit;}
PI_Struct->Un_output?+=?PI_Struct->DeltaUn;?//計算輸出u(n)=u(n-1)+△u(n)并保存作下一次運算
*Output?=?PI_Struct->Un_output;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1787??2015-04-18?21:54??PI_Controller.c
?????文件??????15663??2015-04-18?21:50??PID.docx
-----------?---------??----------?-----??----
????????????????17450????????????????????2
- 上一篇:VegaPrime_MFC
- 下一篇:畫直角坐標系
評論
共有 條評論