求大神帮我纠正下我的PID:
void pid_control()
{
float P=7,I=0,D=3; //灵敏 力度 3.9 2.9/0.954
float rool=0,pitch=0;
// float roolb=0,pitchb=0; //上上一次角度
float roola=0,pitcha=0; //上一次角度
float Pmax=300;
float Rmax=300;
lb();
IMUupdate(AX,AY,GZ,GX,GY,AZ );//更新陀螺仪数据
/*
俯仰角PID---------------------------------------------------------------------------------
*/
pitch = P * Pitch + I * pitcha - D * GX ;
// pitchb=pitcha;
pitcha=Pitch;
if(pitch>Pmax) pitch=Pmax;
if(pitch<-Pmax) pitch=-Pmax;
PP=pitch;
/*
翻滚角PID---------------------------------------------------------------------------------
*/
rool = -P * Rool + I * roola - D * GY ;
// roolb=roola;
roola=Rool;
if(rool>Rmax) rool=Rmax;
if(rool<-Rmax) rool=-Rmax;
RR=rool;
M1=- rool - pitch;
M2=+ rool + pitch;
M3=- rool + pitch;
M4=+ rool - pitch;
MOTO_PWM(M1,M2,M3,M4);
} |