标题: PID增量式 位置式代码 [打印本页]

作者: RMLS    时间: 2019-6-11 08:57
标题: PID增量式 位置式代码
//位置式PID
int32 PID_Realize(PID *sptr, float *PID, int32 NowData, int32 Point)
{
int32 iError, // 当前误差
   Realize; // 最后得出的实际增量
iError = Point - NowData; //计算当前误差
sptr->SumError += PID[KI] * iError; //误差积分
if (sptr->SumError >= PID[KT])
{
  sptr->SumError = PID[KT];
}
else if (sptr->SumError <= -PID[KT])
{
  sptr->SumError = -PID[KT];
}
Realize = PID[KP] * iError
   + sptr->SumError
   + PID[KD] * (iError - sptr->LastError)*100;
sptr->PrevError = sptr->LastError; // 更新前次误差
sptr->LastError = iError;     // 更新上次误差
sptr->LastData  = NowData;   // 更新上次数据
return Realize; // 返回实际值
}
//增量式PID
int32 PID_Increase(PID *sptr, float *PID, int32 NowData, int32 Point)
{
int32 iError, //当前误差
  Increase; //最后得出的实际增量
iError = Point - NowData; // 计算当前误差
Increase =  PID[KP] * (iError - sptr->LastError)
     + PID[KI] * iError
     + PID[KD] * (iError - 2 * sptr->LastError + sptr->PrevError);

sptr->PrevError = sptr->LastError; // 更新前次误差
sptr->LastError = iError;     // 更新上次误差
sptr->LastData  = NowData;   // 更新上次数据
return Increase; // 返回增量
}





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1