|
发表于 2011-4-24 09:41:35
|
显示全部楼层
请教PID算法
void PIDInit(void)
{
sPID.vi_Ref = 0 ; //速度设定值
sPID.vi_FeedBack = 0 ; //速度反馈值
sPID.vi_PreError = 0 ; //前一次,速度误差,,vi_Ref - vi_FeedBack
sPID.vi_PreDerror = 0 ; //前一次,速度误差之差,d_error-PreDerror;
sPID.v_Kp = VV_KPVALUE;
sPID.v_Ki = VV_KIVALUE;
sPID.v_Kd = VV_KDVALUE;
sPID.vl_PreU = 0 ; //电机控制输出值
}
unsigned int v_PIDCalc( PID *pp )
{
signed long error,d_error,dd_error;
error = (signed long)(pp->vi_Ref - pp->vi_FeedBack); // 偏差计算
d_error = error - pp->vi_PreError;
dd_error = d_error - pp->vi_PreDerror;
pp->vi_PreError = error; //存储当前偏差
pp->vi_PreDerror = d_error;
if( ( error < VV_DEADLINE ) && ( error > -VV_DEADLINE ) ); //设置调节死区
//速度PID计算
pp->vl_PreU += (signed long)( pp -> v_Kp * d_error + pp -> v_Ki * error + pp->v_Kd*dd_error);
else if( pp->vl_PreU >= VV_MAX ) //速度PID,防止调节最高溢出
pp->vl_PreU = VV_MAX;
else if( pp->vl_PreU <= VV_MIN ) //速度PID,防止调节最低溢出
pp->vl_PreU = VV_MIN;
else
;
return ( pp->vl_PreU ); // 返回预调节占空比
}
看不懂上面的程序是什么意思?尤其是‘->’什么意思?
谢谢指教!!!! |
|