PIDCalc( PID *pp, int NextPoint )
{
int dError,Error;
Error = pp->SetPoint*10 - NextPoint; // 偏差,设定值减去当前采样值
dError = Error-pp->LastError; // 当前微分,偏差相减
pp->PrevError = pp->LastError; // 保存
pp->LastError = Error;
return (pp->Proportion * Error // 比例项
- pp->Derivative * dError // 微分项
);
} |