找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2146|回復(fù): 0
收起左側(cè)

STM32F103C8T6的姿態(tài)傳感器源程序

[復(fù)制鏈接]
ID:618513 發(fā)表于 2019-10-13 17:58 | 顯示全部樓層 |閱讀模式
  1. #include "delay.h"
  2. #include "sys.h"
  3. #include "usart.h"

  4. #include "serial.h"
  5. #include "led.h"
  6. #include "motor.h"
  7. #include "cap.h"
  8. #include "timer.h"

  9. #include "mpu6050.h"
  10. #include "mpuiic.h"
  11. #include "inv_mpu.h"
  12. #include "inv_mpu_dmp_motion_driver.h"

  13. extern u16 ADV[128];
  14. extern u8 CCD_Zhongzhi;
  15. extern u8 CCD_Yuzhi;

  16. extern u16  TIM2CH1_CAPTURE_STA;                                                   
  17. extern u16        TIM2CH1_CAPTURE_VAL;


  18. extern u16  TIM1CH1_CAPTURE_STA;                                                   
  19. extern u16        TIM1CH1_CAPTURE_VAL;

  20. u8 count_flag=0;


  21. int main(void)
  22. {
  23.         u8 num;
  24.         float pitch,roll,yaw;                 //歐拉角
  25.         short aacx,aacy,aacz;                //加速度傳感器原始數(shù)據(jù)
  26.         short gyrox,gyroy,gyroz;        //陀螺儀原始數(shù)據(jù)
  27.         short temp;                                        //溫度       
  28.        
  29.         SystemInit();        //初始化RCC 設(shè)置系統(tǒng)主頻為72MHZ
  30.         delay_init();             //延時初始化
  31.         uart_init(115200);
  32.         MPU_Init();                                        //初始化MPU6050  
  33.         mpu_dmp_init();
  34.         while(mpu_dmp_init())//初始化dmp,初始化不過報錯
  35.         {
  36.                 printf("%d",mpu_dmp_init());
  37.         }  
  38.        
  39.         while(1)
  40.         {
  41.                         if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)
  42.                         {
  43.                                 temp=MPU_Get_Temperature();        //得到溫度值
  44.                                 MPU_Get_Accelerometer(&aacx,&aacy,&aacz);        //得到加速度傳感器數(shù)據(jù)
  45.                                 MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz);        //得到陀螺儀數(shù)據(jù)

  46.                         }
  47.                 num++;
  48.                 if(num == 50) //每500msLED0閃爍一次
  49.                 {
  50.                         num = 0;
  51. //                        printf("%d %d %d\r\n",gyrox,gyroy,gyroz);
  52. //                        printf("%d %d %d\r\n",aacx,aacy,aacz);
  53.                         printf("x:%3.3f y:%3.3f z:%3.3f\r\n",pitch,roll,yaw);
  54. //                        printf("temp:%d\r\n",temp);
  55.                         printf("\r\n");
  56.                 }
  57.                 delay_ms(10);
  58.         }
  59. }
復(fù)制代碼


串口.7z

245.13 KB, 下載次數(shù): 12, 下載積分: 黑幣 -5

回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

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

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