mpu6050芯片四元數法計算風力擺擺動角度
所有資料51hei提供下載:
六軸.rar
(1009.29 KB, 下載次數: 71)
2017-8-10 19:30 上傳
點擊文件名下載附件
角度檢測 下載積分: 黑幣 -5
stm32f429單片機源程序如下(主程序):
- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "led.h"
- #include "key.h"
- #include "myiic.h"
- #include "mpu6050.h"
- #include "siyuanshu.h"
- /*簡單任務管理*/
- uint32_t Task_Delay[3]={0};
- //extern AHRS_EulerAngleTypeDef EulerAngle;
- int main(void)
- {
- u8 res=0;
- // float pitch_temp1 = 0.0;
- // float roll_temp1 = 0.0;
-
-
- extern float Pitch;
- extern float Roll;
-
- HAL_Init(); //初始化HAL庫
- Stm32_Clock_Init(360,25,2,8); //設置時鐘,180Mhz
- delay_init(180); //初始化延時函數
- uart_init(115200); //初始化USART
- LED_Init(); //初始化LED
- KEY_Init(); //初始化按鍵
- IIC_Init(); //初始iic
-
-
- /*
- short Acel[3];
- short Gyro[3];
- float Temp;
- */
-
- short aacx,aacy,aacz; //加速度傳感器原始數據
- short gyrox,gyroy,gyroz; //陀螺儀原始數據
- float temp; //溫度
-
- printf("\r\n 歡迎使用阿波羅 STM32 F429 開發板。\r\n");
- printf("\r\n 這是一個I2C外設(AT24C02)讀寫測試例程 \r\n");
- MPU_Init();
- res=MPU_Read_Byte(MPU_DEVICE_ID_REG); //讀取MPU6500的ID
- if (res==MPU_ADDR)
- {
- while(1)
- {
- // if(Task_Delay[0]==0)
- // {
- // LED1=0;
- //
- // Task_Delay[0]=1000;
- // }
- //
- // if(Task_Delay[1]==0)
- // {
- /*
- MPU6050ReadAcc(Acel);
- printf("加速度:%8d%8d%8d",Acel[0],Acel[1],Acel[2]);
- MPU6050ReadGyro(Gyro);
- printf(" 陀螺儀%8d%8d%8d",Gyro[0],Gyro[1],Gyro[2]);
- MPU6050_ReturnTemp(&Temp);
- printf(" 溫度%8.2f\r\n",Temp);
- Task_Delay[1]=500; //更新一次數據,可根據自己的需求,提高采樣頻率,如100ms采樣一次
- */
-
-
-
-
- temp=MPU_Get_Temperature(); //得到溫度值
- printf("溫度:%8f",temp);
- MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //得到加速度傳感器數據
- printf("加速度:%8d%8d%8d",aacx,aacy,aacz);
- MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //得到陀螺儀數據
- printf("陀螺儀:%8d%8d%8d\r\n",gyrox,gyroy,gyroz);
-
-
-
- // Task_Delay[1]=500; //更新一次數據,可根據自己的需求,提高采樣頻率,如100ms采樣一次
-
- // EulerAngle.Pitch = Kalman_Filter1(pitch_temp1,gyroy);
- // EulerAngle.Roll = Kalman_Filter2(roll_temp1,-gyrox);
- //
- // printf("俯仰角:%8f",EulerAngle.Pitch);
- // printf("橫滾角:%8f\r\n",EulerAngle.Roll);
-
-
-
- IMUupdate(gyrox,gyroy,gyroz,aacx,aacy,aacz);
-
-
-
- printf("俯仰角:%8f橫滾角:%8f\r\n", Pitch,Roll);
-
-
-
- delay_ms(100);
- // }
- }
- }
- else
- {
- printf("\r\n沒有檢測到MPU6050傳感器!\r\n");
- LED0=0;
- while(1);
- }
- }
-
復制代碼
|