資源簡(jiǎn)介
梯形曲線運(yùn)動(dòng)控制算法,只貼出PID梯形算法核心代碼和應(yīng)用示例,由于保密關(guān)系,不能上傳全部代碼,望各位見(jiàn)諒,本示例僅供學(xué)習(xí)參考交流使用
代碼片段和文件信息
/*
***************************************************************************************
*
*???????????????(c)?Copyright?2006-2008?wei?wei.qiu?china?zj.?hz?
*????????????????????????????All?Rights?Reserved
*
*
*???????????????????????????????????????????????????????????????????????????????????????????????
*
*--------------文件信息-----------------------------------------------------------------
*?文?件?名:?app_gpio.c
*?創(chuàng)?建?人:?邱衛(wèi)衛(wèi)
*?創(chuàng)建日期:?2014年01月08日
*?描????述:?主程序C語(yǔ)言入口?uC/OS-II啟動(dòng)
*----------?版本信息-------------------------------------------------------------------
*?版????本:?V1.0
*
*--------------------------------------------------------------------------------------
****************************************************************************************
void?get_encoder_TWO(void)//******************計(jì)算當(dāng)前實(shí)際速度V
{
??s32?CNT3_tempCNT3_last;
?
??cnt3?=?TIM3?->?CNT;
??CNT3_last?=?CNT3;
??CNT3_temp?=?rcnt3?*?ENCODE_PRD?+?cnt3;?
Position_PID.ActualPoint?=?CNT3_temp;
??V3?=?CNT3_temp?-?CNT3_last; ?
??while?(V3>Vbreak) ?
??{ ??????
???rcnt3--; ??????
???CNT3_temp?=?rcnt3?*?ENCODE_PRD?+?cnt3;
???V3?=?CNT3_temp?-?CNT3_last; ?
??} ?????
??while?(V3<-Vbreak) ???
??{ ??????
???rcnt3++; ??????
???CNT3_temp?=?rcnt3?*?ENCODE_PRD?+?cnt3;
???V3?=?CNT3_temp?-?CNT3_last; ?
??}
??CNT3?=?CNT3_temp; ?
??//POSITION?+=?CNT3;
}
void?PID_init(void)
{???
????Position_PID.SetPoint=0.0;
????Position_PID.ActualPoint=0.0;
??Position_PID.CurPoint?=0;
??Position_PID.CurVolt?=0;
??Position_PID.DecSpeedF=0;
????Position_PID.err=0.0;
????Position_PID.err_last=0.0;
????Position_PID.voltage=0.0;
????Position_PID.integral=0.0;
????Position_PID.Kp=0.01;
????Position_PID.Ki=0.30;
????Position_PID.Kd=0.1;?
??Position_PID.Integral_Index?=?50;//((float)MOTION_POINT/(float)7200)*60.0+2.0;
????TIM_Cmd(TIM2?ENABLE); ????
}
float?point_PID_realize(float?point)
{
???float?indexindex2=1.0err_temp;
???Position_PID.SetPoint?=?point;
???Position_PID.err=Position_PID.SetPoint-Position_PID.ActualPoint;
?index?=?Position_PID.SetPoint/2;?
?if(Position_PID.DecSpeedF?==?0)
?{
????if(((Position_PID.SetPoint-Position_PID.err)>=index)
?????||(Position_PID.voltage>=PWMPeriod))
????{
???????Position_PID.CurPoint?=?Position_PID.SetPoint-Position_PID.err;???//recode?
???????Position_PID.CurVolt??=?Position_PID.voltage;
???//Position_PID.integral?-=?24*Position_PID.SetPoint;
???????Position_PID.DecSpeedF?=0xAA;
????}
?}
???if(abs(Position_PID.err)>Vbreak)?//
???{
??????index=0.0;
???}?
?else?if(Position_PID.ActualPoint>=Position_PID.SetPoint)
?{
????index=0;
????Position_PID.DecSpeedF?=0;
??Position_PID.integral?=0;???????
???}
???else?if(abs(Position_PID.err)<=Position_PID.CurPoint)
?{
?
?
??//Position_PID.Kp?=?7.0;
??//Position_PID.voltage=Position_PID.Kp*Position_PID.err;????
??????//return?Position_PID.voltage;
?
?
評(píng)論
共有 條評(píng)論