开发平台CW6.3.2
多项式计算:Y = 46.65X^4-262.08X^3+545.6X^2-513.84X+242.41
实现方法(见代码):1.使用double pow(double x, double y) 2.直接使用常用的公式 部分代码如下:
全局变量byte flag;
float IncrementPid_adjust(PID *pPID,float SetPoint,float Test_Value)
{
float Increment;
float NextPoint;//下一个UR
float Duty;
pPID->SetValue = SetPoint;
pPID->ActualValue = Test_Value;
pPID->Error = pPID->SetValue-pPID->ActualValue;
Increment = (pPID->Kp)*((pPID->Error)-(pPID->Last_Error))+
(pPID->Ki)*(pPID->Error)+
(pPID->Kd)*(pPID->Error-2*pPID->Last_Error+pPID->Prev_Error);//这个是增量式PID的灵魂
// adjust_shuzhi-=Increment;//根据实际应用的时候adjust_shuzhi的值太大了,所以有点像下降型pid调节。
NextPoint = pPID->ActualValue + Increment;
if (NextPoint < 0.5)
{
NextPoint = 0.5;
}
else if (NextPoint > 2.0)
{
NextPoint = 2.0;
}
else
{
;
}
//Duty = 46.65*pow(NextPoint,4) - 262.08*pow(NextPoint,3)+ 545.6*pow(NextPoint,2)-513*NextPoint +242.41;//方法1
Duty = ((NextPoint*NextPoint*NextPoint*NextPoint*(float)46.65)- //方法2
((float)262.08*NextPoint*NextPoint*NextPoint) +
((float)545.6*NextPoint*NextPoint)-
((float)513.84*NextPoint) +
242.41);
pPID->Prev_Error=pPID->Last_Error;
pPID->Last_Error=pPID->Error;
return Duty;
}
调用该函数时,flag会被改变,这该如何解决?
非常感谢!
|