找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 4708|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

ANO經(jīng)典飛控代碼分享

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ANO經(jīng)典飛控代碼分享。


單片機(jī)源程序如下:
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm32f10x.h"
  3. #include "sysconfig.h"
  4. #include "bsp.h"
  5. #include "led.h"
  6. #include "tim3.h"       
  7. #include "usart.h"
  8. #include "ANO_TC_STM32F1_I2C.h"
  9. #include "MPU6050.h"
  10. #include "moto.h"
  11. #include "spi.h"
  12. #include "nrf24l01.h"
  13. #include "tim_pwm_in.h"
  14. #include "rc.h"
  15. #include "imu.h"
  16. #include "control.h"
  17. #include "data_transfer.h"

  18. u8 SYS_INIT_OK=0;
  19. ////////////////////////////////////////////////////////////////////////////////
  20. void SYS_INIT(void)
  21. {
  22.         LED_INIT();
  23.         LED_FLASH();
  24.         Moto_Init();
  25.         Uart1_Init(115200);       
  26.         Tim3_Init(500);
  27. #ifdef CONTROL_USE_RC
  28.         Tim_Pwm_In_Init();
  29. #endif
  30.         Nvic_Init();
  31.         ANO_TC_I2C2_INIT(0xA6,400000,1,1,3,3);
  32.         MPU6050_Init();
  33.        
  34.         Spi1_Init();
  35.         Nrf24l01_Init(MODEL_TX2,40);
  36.         if(Nrf24l01_Check())       
  37.                 Uart1_Put_String("NRF24L01 IS OK !\r\n");
  38.         else                                                                        
  39.                 Uart1_Put_String("NRF24L01 IS NOT OK !\r\n");
  40.                
  41.         FLASH_Unlock();
  42.         EE_INIT();
  43.         EE_READ_ACC_OFFSET();
  44.         EE_READ_GYRO_OFFSET();
  45.         EE_READ_PID();
  46.        
  47.         Tim3_Control(1);
  48. }
  49. ////////////////////////////////////////////////////////////////////////////////
  50. u8 FLAG_ATT=0;
  51. T_int16_xyz                 Acc,Gyr;        //兩次綜合后的傳感器數(shù)據(jù)
  52. T_int16_xyz                        Acc_AVG;
  53. T_float_angle                 Att_Angle;        //ATT函數(shù)計(jì)算出的姿態(tài)角
  54. vs32                                Alt;
  55. T_RC_Data                         Rc_D;                //遙控通道數(shù)據(jù)
  56. T_RC_Control                Rc_C;                //遙控功能數(shù)據(jù)
  57. int main(void)
  58. {
  59.         static u8 att_cnt=0;
  60.         static u8 rc_cnt=0;
  61.         static T_int16_xyz mpu6050_dataacc1,mpu6050_dataacc2,mpu6050_datagyr1,mpu6050_datagyr2;
  62.         static u8 senser_cnt=0,status_cnt=0,dt_rc_cnt=0,dt_moto_cnt=0;
  63.        
  64.         SYS_INIT();
  65.        
  66.         while (1)
  67.         {                             
  68.                 if(FLAG_ATT)
  69.                 {
  70.                         FLAG_ATT = 0;
  71.                         att_cnt++;
  72.                         rc_cnt++;
  73.                        
  74.                         if(rc_cnt==20)
  75.                         {
  76.                                 rc_cnt = 0;
  77.                                 #ifdef CONTROL_USE_RC
  78.                                 Rc_GetValue(&Rc_D);
  79.                                 #endif
  80.                                 Rc_Fun(&Rc_D,&Rc_C);
  81.                         }
  82.                         if(att_cnt==1)
  83.                                 MPU6050_Dataanl(&mpu6050_dataacc1,&mpu6050_datagyr1);
  84.                         else
  85.                         {
  86.                                 att_cnt = 0;
  87.                                 MPU6050_Dataanl(&mpu6050_dataacc2,&mpu6050_datagyr2);
  88.                                 Acc.X = (mpu6050_dataacc1.X+mpu6050_dataacc2.X)/2;
  89.                                 Acc.Y = (mpu6050_dataacc1.Y+mpu6050_dataacc2.Y)/2;
  90.                                 Acc.Z = (mpu6050_dataacc1.Z+mpu6050_dataacc2.Z)/2;
  91.                                 Gyr.X = (mpu6050_datagyr1.X+mpu6050_datagyr2.X)/2;
  92.                                 Gyr.Y = (mpu6050_datagyr1.Y+mpu6050_datagyr2.Y)/2;
  93.                                 Gyr.Z = (mpu6050_datagyr1.Z+mpu6050_datagyr2.Z)/2;
  94.                                 Prepare_Data(&Acc,&Acc_AVG);
  95.                                 IMUupdate(&Gyr,&Acc_AVG,&Att_Angle);
  96.                                 Control(&Att_Angle,&Gyr,&Rc_D,Rc_C.ARMED);
  97.                                 if(Rc_C.ARMED)
  98.                                         LED1_ONOFF();
  99.                                 else
  100.                                         LED1_OFF;
  101.                                        
  102.                                 senser_cnt++;
  103.                                 status_cnt++;
  104.                                 dt_rc_cnt++;
  105.                                 dt_moto_cnt++;
  106.                                 if(senser_cnt==5)
  107.                                 {
  108.                                         senser_cnt = 0;
  109.                                         Send_Senser = 1;
  110.                                 }
  111.                                 if(status_cnt==5)
  112.                                 {
  113.                                         status_cnt = 0;
  114.                                         Send_Status = 1;
  115.                                 }
  116.                                 if(dt_rc_cnt==10)
  117. ……………………

  118. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
ANO-MR-F1-14422經(jīng)典pid.zip (415.29 KB, 下載次數(shù): 37)



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

使用道具 舉報(bào)

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表