1.微分先行PID控制算法框图
2.微分先行PID控制算法公式
3.微分先行PID控制公式用C语言实现
微分先行的PID算法实现,包括位置型和增量型两种实现方式。
(1)位置型
void PIDRegulation(PID *vPID, float processValue)
{
float thisError;
float c1,c2,c3,temp;
thisError=vPID->setpoint-processValue;
vPID->integral+=thisError;
temp= vPID-> gama * vPID-> derivativegain + vPID-> proportiongain;
c3= vPID-> derivativegain/temp;
c2=( vPID-> derivativegain+ vPID-> proportiongain)/temp;
c1= vPID-> gama*c3;
vPID->derivative=c1* vPID-> derivative+c2* processValue+c3* vPID-> lastPv;
vPID->result=vPID->proportiongain*thisError+vPID->integralgain*vPID->integral+vPID-> derivative;
vPID->lasterror=thisError;
vPID-> lastPv= processValue;
}
/*定义结构体和公用体*/
typedef struct
{
float setpoint; //设定值
float proportiongain; //比例系数
float integralgain; //积分系数
float derivativegain; //微分系数
float lasterror; //前一拍偏差
float result; //输出值
float integral; //积分值
float derivative; //微分项
float lastPv; //前一拍的测量值
float gama; //微分先行滤波系数
}PID;
(2)增量型
void PIDRegulation(PID *vPID, float processValue)
{
float thisError;
float increment;
float pError,iError;
float c1,c2,c3,temp;
float deltaPv;
temp= vPID-> gama * vPID-> derivativegain + vPID-> proportiongain;
c3= vPID-> derivativegain/temp;
c2=( vPID-> derivativegain+ vPID-> proportiongain)/temp;
c1= vPID-> gama*c3;
deltaPv= processValue- vPID-> lastDeltaPv
vPID-> deltadiff =c1* vPID-> deltadiff +c2* deltaPv +c3* vPID-> lastDeltaPv;
thisError=vPID->setpoint-processValue; //得到偏差值
pError=thisError-vPID->lasterror;
iError=thisError;
increment=vPID->proportiongain*pError+vPID->integralgain*iError+ vPID-> deltadiff; //增量计算
vPID->preerror=vPID->lasterror; //存放偏差用于下次运算
vPID->lastDeltaPv=deltaPv;
vPID->lastPv= processValue;
vPID->lasterror=thisError;
vPID->result+=increment;
}
/*定义结构体和公用体*/
typedef struct
{
float setpoint; //设定值
float proportiongain; //比例系数
float integralgain; //积分系数
float derivativegain; //微分系数
float lasterror; //前一拍偏差
float preerror; //前两拍偏差
float deadband; //死区
float result; //输出值
float deltadiff; /*微分增量*/
float integralValue; /*积分累计量*/
float gama; /*微分先行滤波系数*/
float lastPv; /*上一拍的过程测量值*/
float lastDeltaPv; /*上一拍的过程测量值增量*/
}PID;
微分先行PID控制是只对输出量进行微分,而对给定指令不起微分作用,因此它适合于给定指令频繁升降和高频干扰的场合,可以避免指令的改变导致超调过大。
文章评论