CCALM 发表于 2013-11-3 17:41

初写PID,问题多多

求大神帮我纠正下我的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);
}

dictionary 发表于 2013-11-12 08:08

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;

那么多float
先想办法去掉这些 float 再说 好了

290399937 发表于 2013-11-12 08:21

表示.什么pid算法 !没弄过!我只弄过求平均!哈哈。要好好折腾!

meilidianzhi 发表于 2013-12-7 01:06

我的也没成功

qbwww 发表于 2021-9-26 15:30

更新陀螺仪数据
页: [1]
查看完整版本: 初写PID,问题多多