智能车制作
标题:
编码器
[打印本页]
作者:
arfer
时间:
2015-4-14 22:23
标题:
编码器
编码器如何使能呢??
gpio_Interrupt_init(PORTC,5, GPI_DOWN, RING) ;
写这个编码器还是不能传回来脉冲
这个程序用到什么算法?能解释一下吗
int16_t SpeedPID(uint16_t speedCount,uint16_t AmSpeed){
// uint8_t i;
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 ;
SpeedKP = 2;
SpeedKI = 0;
SpeedKD = 1;
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;
}
// uart_putchar(UART0,SpeedDifference0);
// uart_putchar(UART0,SpeedPWMKP);
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 ;
}
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2