智能车制作
标题:
速度增量式PID
[打印本页]
作者:
GZFSJK
时间:
2017-4-9 12:15
标题:
速度增量式PID
int16_t SpeedKP = 4 ;
int16_t SpeedKI = 0 ;
int16_t SpeedKD = 2 ;
//int16_t SpeedPWM = 0 ;
int16_t SpeedPID(uint16_t speedCount,uint16_t AmSpeed)// 比较经典的增量式PID
{ // 请参考相关PID的资料
// 在此不做展开
static int16_t LastSpeedCut0,LastSpeedCut1,LastSpeedCut2 ,SpeedLastPWMK ;
int16_t SpeedPWMKP ,SpeedPWMKI ,SpeedPWMKD,SpeedPWMK ;
int16_t SpeedPWMOUT;
int16_t SpeedDifference0=0;
int16_t speedDEARE1,speedDEARE2,DSpeed ;
LastSpeedCut0 = (int16_t) speedCount ;
DSpeed =(int16_t) AmSpeed ;
SpeedDifference0 = DSpeed - LastSpeedCut0 ;
speedDEARE1 = LastSpeedCut0 - LastSpeedCut1;
speedDEARE2 = LastSpeedCut2+LastSpeedCut0-2*LastSpeedCut1;
LastSpeedCut2 = LastSpeedCut1;
LastSpeedCut1 = LastSpeedCut0;
SpeedPWMKP = SpeedKP*SpeedDifference0;
if(SpeedPWMKP>KPPLUSMAX)
{
SpeedPWMKP = KPPLUSMAX;
}
else if (SpeedPWMKP <KPNEGATIVEMAX)
{
SpeedPWMKP = KPNEGATIVEMAX;
}
SpeedPWMKI = SpeedKI* speedDEARE1;
if(SpeedPWMKI > KIPLUSMAX)
{
SpeedPWMKI = KIPLUSMAX;
}
else if(SpeedPWMKI < KINEGATIVEMAX)
{
SpeedPWMKI = KINEGATIVEMAX;
}
SpeedPWMKD = SpeedKD* speedDEARE2;
if(SpeedPWMKD > KDPLUSMAX)
{
SpeedPWMKD = KDPLUSMAX;
}
else if(SpeedPWMKD < KDNEGATIVEMAX)
{
SpeedPWMKD = KDNEGATIVEMAX;
}
SpeedPWMK = SpeedPWMKD+SpeedPWMKI+SpeedPWMKP ;
if(SpeedPWMK > KWPLUSMAX)
{
SpeedPWMK = KWPLUSMAX;
}
else if(SpeedPWMK < KWNEGATIVEMAX)
{
SpeedPWMK = KWNEGATIVEMAX;
}
SpeedPWMOUT = SpeedLastPWMK + SpeedPWMK;
if(SpeedPWMOUT < 0 )
{
SpeedPWMOUT = 0 ;
}
else if(SpeedPWMOUT > KOUPLUSMAX)
{
SpeedPWMOUT = KOUPLUSMAX ;
}
SpeedLastPWMK = SpeedPWMOUT ;
// uart_putchar(UART0,SpeedPWMOUT);
// uart_putchar(UART0,SpeedPWMK);
return SpeedPWMOUT ;
}
有采集的速度,有目标速度,但是输出的速度达不到目标速度,总是在限幅速度输出,怎么破。求大神指教。
作者:
zhou1994
时间:
2017-4-9 13:13
这变量命名,肯定过不了code review
作者:
yyuiopxx
时间:
2017-4-9 13:21
我想问的是,楼主有没有好的调参经验分享一下呗;感谢!
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2