找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4046|回复: 0
收起左侧

ANO经典飞控代码分享

[复制链接]
ID:232848 发表于 2017-9-13 12:43 | 显示全部楼层 |阅读模式
ANO经典飞控代码分享。
0.png

单片机源程序如下:
  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;        //两次综合后的传感器数据
  52. T_int16_xyz                        Acc_AVG;
  53. T_float_angle                 Att_Angle;        //ATT函数计算出的姿态角
  54. vs32                                Alt;
  55. T_RC_Data                         Rc_D;                //遥控通道数据
  56. T_RC_Control                Rc_C;                //遥控功能数据
  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. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
ANO-MR-F1-14422经典pid.zip (415.29 KB, 下载次数: 35)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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