高级会员
- 积分
- 697
- 威望
- 376
- 贡献
- 195
- 兑换币
- 215
- 注册时间
- 2016-12-9
- 在线时间
- 63 小时
- 毕业学校
- JH
|
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 ;
}
有采集的速度,有目标速度,但是输出的速度达不到目标速度,总是在限幅速度输出,怎么破。求大神指教。 |
|