我实际上正在开发一个基于 freeRTOS 的机器人项目。我在控制机器人车轮速度的 PI 控制器上遇到了一些问题。
#define To 100 // 100 ms
#define Te 5 // 5 ms
#define Kp 0.01
#define Ti 10 //0.1*To
#define Ki 0.05/10 //Te/ti
void corrNum(int consigneVitesse) // takes speed as parameter
{
int eL,eR = 0; errors left and right
float cdeL = 0 ;
float UpL = 0 ;
int dutyL = 0 ;
float cdeR = 0 ;
float UpR = 0 ;
int dutyR = 0 ;
float UiL= 0 ;
float UiR = 0 ;
if(consigneVitesse)
{
tickL = quadEncoder_GetSpeedL();
tickR = quadEncoder_GetSpeedR();
eL = (int)(consigneVitesse - tickL);
eR = (int)(consigneVitesse - tickR);
UpL = Kp*eL ;
UpR = Kp*eR ;
UiL= UiL + Kp*Ki*eL ;
UiR= UiR + Kp*Ki*eR ;
UiL_prev = UiL ;
UiR_prev = UiR ;
cdeL = UpL + UiL ;
cdeR = UpR + UiR ;
dutyL = cdeL < 100 && cdeL > -100 ? (int)cdeL +100 : 200 ;
dutyR = cdeR < 100 && cdeR > -100 ? (int)cdeR +100 : 200 ;
motorLeft_SetDuty(dutyL);
motorRight_SetDuty(dutyR);
HAL_Delay(5); // sampling period 5 ms
term_printf("MOTOR LEFT ::::::> CMD : %d SPEED : %d Err : %d DUTY : %d\n\r",consigneVitesse,tickL,eL,dutyL`enter code here`);
term_printf("MOTOR RIGHT ::::::> CMD : %d SPEED : %d Err : %d DUTY : %d \n\r",consigneVitesse,tickR,eR,dutyR);;
tickL = 0 ;
tickR = 0;
}
else
{
motorLeft_SetDuty(100);
motorRight_SetDuty(100);
}
}`
问题是当误差达到0.0而不是稳定时开始振荡。