void _CYCLIC PIDRegulation(void)
{
//
// typedef struct
//
// {
//
// float setpoint; //设定值
//
// float proportiongain; //比例系数
//
// float integralgain; //积分系数
//
// float derivativegain; //微分系数
//
// float lasterror; //前一拍偏差
//
// float preerror; //前两拍偏差
//
// float deadband; //死区
//
// float result; //输出值
//
// }PID;
//接下来实现PID控制器:
//void PIDRegulation(PID,processValue)
//{
// float thisError;
//
// float increment;
//
// float pError,dError,iError;
thisError=PID.setpoint-processValue; //得到偏差值
pError=thisError-PID.lasterror;
iError=thisError;
dError=thisError-2*(PID.lasterror)+PID.preerror;
increment=PID.proportiongain*pError+PID.integralgain*iError+PID.derivativegain*dError; //增量计算
PID.preerror=PID.lasterror; //存放偏差用于下次运算
PID.lasterror=thisError;
PID.result+=increment;
//}
}