搜索
bottom↓
回复: 0

[求助]MWC移植问题

[复制链接]

出0入0汤圆

发表于 2014-4-6 11:48:02 | 显示全部楼层 |阅读模式
本帖最后由 qiguibao 于 2014-4-6 11:51 编辑

    最近将MWC的PID算法和互补滤波移植到了自己的STM32飞控上,用MWC飞控测试好用的PID参数,结果四旋翼震动很厉害,很快就侧翻。分析可以看出MWC代码的PID参数给的是挺大的,但MWC飞控却不震荡。代码参考的是MWC2.2,PID参数用的是MWC2.2的默认参数,默认参数飞行效果就不错。不知道大家有没有遇到类似的问题~


    移植的对应ROLL和PITCH的PID部分代码:


  1.         for(axis=0;axis<3;axis++)
  2.         {
  3.                 if(axis<2) //ROLL AND PITCH
  4.                 {                                                  
  5.                         errorAngle = (s32)(constrain(2*rcCommand[axis] ,-500,+500) - angle[axis]); //16 bits is ok here
  6.                         PTermACC = ((s32)errorAngle*dynPIDconf.P8[PIDLEVEL])/100;//2^7=128,// 32 bits is needed for calculation: errorAngle*P8[PIDLEVEL] could exceed 32768   16 bits is ok for result
  7.                         PTermACC = constrain(PTermACC,-dynPIDconf.D8[PIDLEVEL]*5,+dynPIDconf.D8[PIDLEVEL]*5);//角度P为90,对应于弧度的P大约是420
  8.                        
  9.                         errorAngleI[axis]     = constrain(errorAngleI[axis]+errorAngle,-10000,+10000);    // WindUp     //16 bits is ok here
  10.                         ITermACC              = ((s32)errorAngleI[axis]*dynPIDconf.I8[PIDLEVEL])>>12; //I=10,最大10000*10/4096=24  // 32 bits is needed for calculation:10000*I8 could exceed 32768   16 bits is ok for result
  11.                 }
  12.                 if ( axis<2 ) //ROLL AND PITCH
  13.                 {
  14.                         PTerm = PTermACC;
  15.                         ITerm = ITermACC;
  16.                 }
  17.                 else                   //YAW
  18.                 {
  19.                         PTerm = PTermGYRO;
  20.                         ITerm = ITermGYRO;
  21.                 }

  22.                 PTerm -= ((s32)gyroData[axis]*dynP8[axis])/10/8; // 32 bits is needed for calculation   
  23.                                    
  24.                 delta          = gyroData[axis] - lastGyro[axis];  // 16 bits is ok here, the dif between 2 consecutive gyro reads is limited to 800
  25.                 lastGyro[axis] = gyroData[axis];                                   //连续两次读取的数据差被限制在800以内
  26.                 deltaSum       = delta1[axis]+delta2[axis]+delta;
  27.                 delta2[axis]   = delta1[axis];
  28.                 delta1[axis]   = delta;
  29.                
  30.                 DTerm = ((s32)deltaSum*dynD8[axis])/32;        // 32 bits is needed for calculation
  31.                                    
  32.                 g_axisPID[axis] =  PTerm + ITerm - DTerm;
  33.         }
复制代码



    相关变量类型定义:
  1. u8 axis;
  2. s32 angle[3];
  3. s16 gyroData[3];
  4. s32 errorAngle;
  5. s32 delta,deltaSum;
  6. s32 PTerm,ITerm,DTerm;
  7. s32 PTermACC = 0 , ITermACC = 0 , PTermGYRO = 0 , ITermGYRO = 0;
  8. static s16 lastGyro[3] = {0,0,0};
  9. static s32 delta1[3]={0,0,0},delta2[3]={0,0,0};
  10. static s32 errorGyroI[3] = {0,0,0};
  11. static s32 errorAngleI[3] = {0,0,0};
复制代码

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-6 05:39

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表