增量式PID控制算法

来源:互联网 发布:云计算 国家政策汇总 编辑:程序博客网 时间:2024/05/01 07:11

原转载 blog.ednchina.com/tengjingshu 

转载 http://www.cnblogs.com/farbeyond/p/5204676.html


1. 当执行机构需要的不是控制量的绝对值,而是控制量的增量(例如去驱动步进电动机)时,需要用PID的“增量算法”。

 

      增量式PID控制算法可以通过(2-4)式推导出。由(2-4)可以得到控制器的第k-1个采样时刻的输出值为:

(2-5)

将(2-4)与(2-5)相减并整理,就可以得到增量式PID控制算法公式为:

 

(2-6)

其中

 

         由(2-6)可以看出,如果计算机控制系统采用恒定的采样周期T,一旦确定A、B、C,只要使用前后三次测量的偏差值,就可以由(2-6)求出控制量。

增量式PID控制算法与位置式PID算法(2-4)相比,计算量小得多,因此在实际中得到广泛的应用。

位置式PID控制算法也可以通过增量式控制算法推出递推计算公式:

 (2-7)

(2-7)就是目前在计算机控制中广泛应用的数字递推PID控制算法。

 

2. 增量式PID控制算法C51程序

/*==================================================================================================== PID Function The PID (比例、积分、微分) function is used in mainly control applications. PIDCalc performs one iteration of the PID algorithm. While the PID function works, main is just a dummy program showing a typical usage. =====================================================================================================*/typedef struct PID{int SetPoint; //设定目标 Desired Valuelong SumError; //误差累计double Proportion; //比例常数 Proportional Constdouble Integral; //积分常数 Integral Constdouble Derivative; //微分常数 Derivative Constint LastError; //Error[-1]int PrevError; //Error[-2]} PID;  static PID sPID;static PID *sptr = &sPID;/*==================================================================================================== Initialize PID Structure PID参数初始化 =====================================================================================================*/void IncPIDInit(void){sptr->SumError = 0;sptr->LastError = 0; //Error[-1]sptr->PrevError = 0; //Error[-2]sptr->Proportion = 0; //比例常数 Proportional Constsptr->Integral = 0; //积分常数Integral Constsptr->Derivative = 0; //微分常数 Derivative Constsptr->SetPoint = 0;} /*==================================================================================================== 增量式PID计算部分 =====================================================================================================*/int IncPIDCalc(int NextPoint){register int iError, iIncpid; //当前误差iError = sptr->SetPoint - NextPoint; //增量计算iIncpid = sptr->Proportion * iError //E[k]项- sptr->Integral * sptr->LastError //E[k-1]项+ sptr->Derivative * sptr->PrevError; //E[k-2]项//存储误差,用于下次计算sptr->PrevError = sptr->LastError;sptr->LastError = iError;//返回增量值return(iIncpid);}





原创粉丝点击