uchar PIDCalc(uint setpoint,uint nextpoint)
{
int idata Error;
int idata dError;
int idata freecont;
uchar idata com;
//pid算法部分
Error = (int)(setpoint - nextpoint) ;
SumError = (int)(SumError + Error);
dError = (int)(lasrError - PrevError);
PrevError = lasrError;
lasrError = Error;
freecont += (int)(Error * KPConst);
freecont += (int)(SumError * KIConst);
freecont += (int)(dError * KDConst);
if(freecont <= 0)
{
com = 0;
}
else if(freecont > 200)
{
com = 200;
}
else
{
com = (freecont & 0xff);
}
return (com);
}
好心的大哥大姐,帮我看看,这个程序中什么地方出错了?本人最后获得的返回值总是错误的!!! |