欢迎来到天天文库
浏览记录
ID:32594737
大小:59.52 KB
页数:8页
时间:2019-02-13
《2012飞思卡尔智能车速度pid调试》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Ctl_P二Kp*SpeedError;//计算比例项Ctl_I二Ki*SpeedError+Ctl_I;if(Ctl」〈-1000)〃积分项限幅Ctl_I=-1000;1000)Ctl_I=1000;//T_Ctl_I=Ctl_I;//T_Ctl_P=Ctl_P;PWM1input二(8*(Ctl_P+Ct1_I)+3*PWM1inputCachc[01+PBllinputCachc[1])/12;voidSpeedCount(void)SpeedCache[3]=SpeedCache[2];Sp
2、ccdCachc[2]=SpccdCachc[1];SpeedCache[1]=SpeedCache[0];SpeedCache[0]=SpeedBack;//缓存NEW_SpeedCache[3]=NEW_SpeedCache[2];NEWSpccdCachc[2]=NEW_SpccdCachc[1];NEWSpeedCache[1]=NEW_SpeedCache[0];NEW_SpeedCache[0]=NEW_SpeedBack;if(PACNT3、erFlow=l;}"if(PA_0verFlow==0){"SpccdBack=PACNT-LastPulscCountcr;//计算当前速度;}elseif(PA_OverFlow==l){"Counter;SpccdBack=65535*PA_0vcrFlow+PACNT-LastPulscPA_0verFlow=0;}"if(NEW_PACNT4、=NEW_PACNT-NEW_LastPulseCounter;//计算当前速度;}elseif(NEW_PA_OvcrF1ow==1){""NEW_SpeedBack=65535*NEW_PA_0verFlow+NEW_PACNT-NEWLastPulseCounter;NEW_PA_0verFlow=0;}NEW_LastPulseCounter=NEW_PACNT;LastPulseCounter二PACNT;SpccdBack=SpccdBack/PulscCountDcn;NEWSpeed5、Back=NEWSpeedBack/PulseCountDen;)voidSpeedControl(void){〃速度控制intErrorSum=0;intSpeedCtl;inttri_speed=20;staticucharSpeedUp;staticucharSpeedDown;uintden;staticuintStraightTime;staticuintStraightLineCounter;SteerlncrementError[2]=SteerlncrementError[l];St6、eerlncrementError[l]=SteerlncrementError[0];SteerlncrementEiror[0]二SteerlncrementCache[O]・SteerlncrementCache[2];ErrorSum=SteerlncrementError[0]*的+SteerlncrementError[1]+SteerlncrementError[2];SpeedCtl=m_abs(Steerlncrement+ErrorSum);if(SpeedCtl<55){〃507、Speedllp=1;讦(SpeedDown二二2)StraightCounter=0;StraightCounter++;SpeedDown=0;StraightCounter++;}elseif(SpeedCtl<65)SpeedUp=0;SpeedDown=0;StraightCounter=0;}else{SpeedDown=1;if(SpeedUp==l){StraightCounter=0;StraightCounter=StraightCounter-2;SpeedUp=0;}Stra8、ightCounter=StraightCounter-2;}denm_abs(SteerlncrementCache[0]SteerlncrementCache[l])/2;if(den==0)den=1;SpeedAdjust=(int)m_sqrt((long)SPEED_MAXSPEED_MAX*100/den);if(SpeedAdjust>(SPEED_MAX-l))SpeedAdjust二SPEED_MAX-1;elseif(SpeedAdjust<(S
3、erFlow=l;}"if(PA_0verFlow==0){"SpccdBack=PACNT-LastPulscCountcr;//计算当前速度;}elseif(PA_OverFlow==l){"Counter;SpccdBack=65535*PA_0vcrFlow+PACNT-LastPulscPA_0verFlow=0;}"if(NEW_PACNT4、=NEW_PACNT-NEW_LastPulseCounter;//计算当前速度;}elseif(NEW_PA_OvcrF1ow==1){""NEW_SpeedBack=65535*NEW_PA_0verFlow+NEW_PACNT-NEWLastPulseCounter;NEW_PA_0verFlow=0;}NEW_LastPulseCounter=NEW_PACNT;LastPulseCounter二PACNT;SpccdBack=SpccdBack/PulscCountDcn;NEWSpeed5、Back=NEWSpeedBack/PulseCountDen;)voidSpeedControl(void){〃速度控制intErrorSum=0;intSpeedCtl;inttri_speed=20;staticucharSpeedUp;staticucharSpeedDown;uintden;staticuintStraightTime;staticuintStraightLineCounter;SteerlncrementError[2]=SteerlncrementError[l];St6、eerlncrementError[l]=SteerlncrementError[0];SteerlncrementEiror[0]二SteerlncrementCache[O]・SteerlncrementCache[2];ErrorSum=SteerlncrementError[0]*的+SteerlncrementError[1]+SteerlncrementError[2];SpeedCtl=m_abs(Steerlncrement+ErrorSum);if(SpeedCtl<55){〃507、Speedllp=1;讦(SpeedDown二二2)StraightCounter=0;StraightCounter++;SpeedDown=0;StraightCounter++;}elseif(SpeedCtl<65)SpeedUp=0;SpeedDown=0;StraightCounter=0;}else{SpeedDown=1;if(SpeedUp==l){StraightCounter=0;StraightCounter=StraightCounter-2;SpeedUp=0;}Stra8、ightCounter=StraightCounter-2;}denm_abs(SteerlncrementCache[0]SteerlncrementCache[l])/2;if(den==0)den=1;SpeedAdjust=(int)m_sqrt((long)SPEED_MAXSPEED_MAX*100/den);if(SpeedAdjust>(SPEED_MAX-l))SpeedAdjust二SPEED_MAX-1;elseif(SpeedAdjust<(S
4、=NEW_PACNT-NEW_LastPulseCounter;//计算当前速度;}elseif(NEW_PA_OvcrF1ow==1){""NEW_SpeedBack=65535*NEW_PA_0verFlow+NEW_PACNT-NEWLastPulseCounter;NEW_PA_0verFlow=0;}NEW_LastPulseCounter=NEW_PACNT;LastPulseCounter二PACNT;SpccdBack=SpccdBack/PulscCountDcn;NEWSpeed
5、Back=NEWSpeedBack/PulseCountDen;)voidSpeedControl(void){〃速度控制intErrorSum=0;intSpeedCtl;inttri_speed=20;staticucharSpeedUp;staticucharSpeedDown;uintden;staticuintStraightTime;staticuintStraightLineCounter;SteerlncrementError[2]=SteerlncrementError[l];St
6、eerlncrementError[l]=SteerlncrementError[0];SteerlncrementEiror[0]二SteerlncrementCache[O]・SteerlncrementCache[2];ErrorSum=SteerlncrementError[0]*的+SteerlncrementError[1]+SteerlncrementError[2];SpeedCtl=m_abs(Steerlncrement+ErrorSum);if(SpeedCtl<55){〃50
7、Speedllp=1;讦(SpeedDown二二2)StraightCounter=0;StraightCounter++;SpeedDown=0;StraightCounter++;}elseif(SpeedCtl<65)SpeedUp=0;SpeedDown=0;StraightCounter=0;}else{SpeedDown=1;if(SpeedUp==l){StraightCounter=0;StraightCounter=StraightCounter-2;SpeedUp=0;}Stra
8、ightCounter=StraightCounter-2;}denm_abs(SteerlncrementCache[0]SteerlncrementCache[l])/2;if(den==0)den=1;SpeedAdjust=(int)m_sqrt((long)SPEED_MAXSPEED_MAX*100/den);if(SpeedAdjust>(SPEED_MAX-l))SpeedAdjust二SPEED_MAX-1;elseif(SpeedAdjust<(S
此文档下载收益归作者所有