久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2387|回復: 0
打印 上一主題 下一主題
收起左側

STM32小四軸自用調試代碼分享 無HMC5883程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:762171 發表于 2020-5-27 09:39 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
新人出來,多多關照,有興趣自取

單片機源程序如下:
  1. #include "sys.h"
  2. #include "nrf24l01.h"
  3. #include "mpu6050.h"
  4. #include "motor.h"
  5. #include "led.h"
  6. #include "nrfreport.h"
  7. #include "flycontro.h"
  8. #include "mpudat.h"

  9. /**
  10. 微型四軸代碼,2016/1/22,chrain
  11. 無HMC5883程序

  12. */





  13. int U8toInt(u8 a,u8 b);
  14. void FLY_Contro(void);
  15. int main(void)
  16. {
  17.         int PWM;
  18. //        PWMA =PWMB =PWMC =PWMD =0;
  19.         SystemInit();
  20.         delay_init();
  21.         LED_Init();  //LED初始化
  22.   
  23.         if(NRF24L01_Init())
  24.         LED1 = LED2 = LED3 = LED4 = 1;
  25.   delay_ms(1000);
  26.         LED1 = LED2 = LED3 = LED4 = 1;
  27.         MPU_Init();  //陀螺儀初始化

  28.         PID_init();
  29.         delay_ms(1000);
  30.   Motor_Init();//電機初始化
  31.   timer_Init();
  32. //        MPU6050_offset();
  33. //        LED1 = LED2 = LED3 = LED4 = 0;
  34. //       
  35. //        RxBuf[0]=RxBuf[1]=RxBuf[2]=RxBuf[3]=0;
  36. //        PWMA = PWMB = PWMC = PWMD =0;

  37. //        PWM_Init();
  38. //        PID_init();           //PID參數初始化
  39.         while(1)
  40.          {
  41.          if(RxBuf[0]&0xA0)                   LED1 = LED2 = LED3 = LED4 = 1;
  42.    else  LED_Circleflsah ();
  43.                  
  44.                  
  45.         if(RxBuf[2]>140|RxBuf[2]<115)
  46.                 Ycontrdat  =  (125 - RxBuf[2])/12.0;
  47.         else
  48.                 Ycontrdat =0;
  49.        
  50.   if(RxBuf[1]>130|RxBuf[1]<120)
  51.                 Xcontrdat  =  (RxBuf[1] - 125)/12.0;
  52.         else
  53.                 Xcontrdat =0;
  54.        
  55.         TargeContrdat.X        =  U8toInt(RxBuf[5],RxBuf[6])/100.0;
  56.         TargeContrdat.Y        =  U8toInt(RxBuf[7],RxBuf[8])/100.0;
  57.         TargeContrdat.Z        =  U8toInt(RxBuf[9],RxBuf[10])/100.0;
  58.                

  59. if(RxBuf[0] == 0XA1)       
  60. {       
  61.   PID_Kp.X =          U8toInt(RxBuf[11],RxBuf[12])/100.0;
  62.         PID_Kp.Y =          U8toInt(RxBuf[13],RxBuf[14])/100.0;
  63.         PID_Kp.Z =          U8toInt(RxBuf[15],RxBuf[16])/100.0;
  64.                  
  65.   PID_Ki.X =          U8toInt(RxBuf[17],RxBuf[18])/100.0;
  66.         PID_Ki.Y =          U8toInt(RxBuf[19],RxBuf[20])/100.0;
  67.         PID_Ki.Z =          U8toInt(RxBuf[21],RxBuf[22])/100.0;
  68.                
  69.         PID_Kd.X =          U8toInt(RxBuf[23],RxBuf[24])/100.0;
  70.         PID_Kd.Y =          U8toInt(RxBuf[25],RxBuf[26])/100.0;
  71.         PID_Kd.Z =          U8toInt(RxBuf[27],RxBuf[28])/100.0;         
  72. }                 
  73.           delay_ms(20);
  74.                  
  75. //        NRF_Report_STATUS(Angle.X*100,Angle.Y*100,Angle.Z*100,Accel.X,Accel.X,Accel.Z,Gyro.X,Gyro.Y,Gyro.Z);
  76.    NRF_Report_STATUS(Angle.Y*100,Ycontrdat*100,Angle.Z*100,
  77.                                  Angle.Y*100,Ycontrdat*100,Accel.Z,
  78.                                  Gyro.X,Gyro.Y,Gyro.Z);

  79.                 PWM = 256 - RxBuf[3];
  80. if(RxBuf[0]&0xA0)
  81. {
  82.          if(PWM > 30)
  83.                  {
  84.                         if(PWM>250) PWM =249;
  85.           
  86.        Fly_PWM = (PWM-30)*2.2;
  87.      }else
  88.                   {
  89.                                 Fly_PWM =0;
  90.                                 Angle.Z =0;
  91.                         }
  92. }else
  93.                   {
  94.                                 Fly_PWM =0;
  95.                                 Angle.Z =0;
  96.                         }
  97. // Prepare_Data(&Acc,&Acc_AVG);
  98.   //  IMUupdate(&Gyr,&Acc_AVG,&Angle);        

  99. //  LED2 =1;
  100. //  delay_ms(100);
  101.         //        LED1=~LED1;
  102.                  
  103.                  
  104.                  
  105. //          NRF24l01_Report_STATUS((int)(Angle.rol *100),(int)(Angle.pit *100),(int)(Angle.yaw*100),0,0);
  106. //               
  107. //i++;               
  108. //if(i>10)
  109. //{       
  110. //        TxBuf[15] = (Moto_A>>8)&0x00ff;               
  111. //  TxBuf[16] = Moto_A&0x00ff;
  112. //  TxBuf[17] = (Moto_B>>8)&0x00ff;
  113. //  TxBuf[18] = Moto_B&0x00ff;
  114. //  TxBuf[19] = (Moto_C>>8)&0x00ff;
  115. //        TxBuf[20] = Moto_C&0x00ff;
  116. //  TxBuf[21] = (Moto_D>>8)&0x00ff;
  117. //  TxBuf[22] = Moto_D&0x00ff;
  118. //        i=0;
  119. }
  120.                


  121. //   FLY_Contro();


  122. //         if(RxBuf[1]>0)        
  123. //                 Fly_PWM = RxBuf[1]*5;
  124. //                else
  125. //                 Fly_PWM=0;       
  126. //               
  127. //               
  128. //               

  129. // }
  130. }




  131. void FLY_Contro(void)
  132. {
  133. //float RolContro,PitContro;
  134. //float temp;
  135. //static float Rol_weitiao=0,Pit_weitiao=0;

  136. //       
  137. //       
  138. //         
  139. ////PIT控制
  140. //                 if(RxBuf[5]<115)  
  141. //                  {
  142. //                         PitContro = (115-RxBuf[5])/5.0;         
  143. //                         if(PitContro >= 20) PitContro=20.0;                                  
  144. //      }else if(RxBuf[5]>125)        //         if(TxBuf[3]<115) //TxBuf[3]>125
  145. //                  {
  146. //       PitContro = (125-RxBuf[5])/5.0;                       
  147. //       if(PitContro<=-20) PitContro=-20;                               
  148. //      }
  149. ////ROll控制                       
  150. //   if(RxBuf[4]<115)  
  151. //                  {
  152. //                         RolContro = (115-RxBuf[4])/5.0;         
  153. //                         if(RolContro >= 20) RolContro=20.0;                                  
  154. //      }else if(RxBuf[4]>125)        //         if(TxBuf[3]<115) //TxBuf[3]>125
  155. //                  {
  156. //       RolContro = (125- RxBuf[4])/5.0;                       
  157. //       if(RolContro<=-20) RolContro=-20;                               
  158. //      }
  159. //                       

  160. //                       
  161. //         Roll.Targe   =          RolContro + Rol_weitiao;       
  162. //         Pitch.Targe   =  -PitContro + Pit_weitiao;               
  163. //               

  164. //        if(RxBuf[9]==1)
  165. // {
  166. //  temp = U8toInt(RxBuf[10],RxBuf[11]);  //ROll微調
  167. // //       Pit_PID.Kp  = temp/100.0;
  168. //              Rol_weitiao= temp/4.0;  
  169. //        temp = U8toInt(RxBuf[12],RxBuf[13]);  //PIt微調
  170. //                  Pit_weitiao= temp/4.0;  
  171. ////        Pit_PID.Kd= temp/100.0;         
  172. // }
  173. //        RxBuf[9]=0;                                

  174. }












  175. int U8toInt(u8 a,u8 b)
  176. {
  177. int temp=0;
  178. //    b = temp&0x00ff;
  179. //    a = (temp>>8)&0x00ff;                 
  180.                 temp = (a<<8)|b;
  181.     if(temp>32768)temp-=65536;       
  182.     return temp;
  183. }





  184. //void PWM_Init(void)
  185. //{
  186. // GPIO_InitTypeDef GPIO_InitStructure;
  187. ……………………

  188. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有程序51hei提供下載:
四軸測試代碼.7z (247.22 KB, 下載次數: 14)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 一级片av| 午夜免费| 免费成人午夜 | av一区二区三区 | 国产欧美日韩在线播放 | 99精品福利视频 | 在线午夜 | 亚洲高清在线观看 | 五月激情六月婷婷 | 久久成人国产 | 亚洲另类春色偷拍在线观看 | 久草免费在线视频 | 国产精品久久久久久一区二区三区 | 三级在线免费观看 | 一区二区三区日 | 欧美日韩亚洲视频 | 国产精品不卡一区 | 免费黄色a级毛片 | 91在线观看 | 中文字幕第十页 | 国产精品影视在线观看 | 麻豆国产一区二区三区四区 | 国产99小视频| 亚洲视屏 | 久久免费视频2 | 黄色在线免费观看 | 欧美午夜一区二区三区免费大片 | 最新日韩在线 | 久久成人一区 | 美女黄网站视频免费 | 久久国产精品网站 | 天天干狠狠操 | 青青久草 | 欧美激情在线精品一区二区三区 | 日韩一区二区福利 | 日韩一区二区免费视频 | 日日爱夜夜操 | 亚洲人人| 天天影视亚洲综合网 | 久久久久黑人 | 国产日韩欧美一区二区 |