標(biāo)題:
STM32F103風(fēng)力擺系統(tǒng)程序,陀螺儀使用基于DMP的MPU6050可自行增加卡爾曼濾波
[打印本頁]
作者:
超大俠
時(shí)間:
2023-11-21 17:01
標(biāo)題:
STM32F103風(fēng)力擺系統(tǒng)程序,陀螺儀使用基于DMP的MPU6050可自行增加卡爾曼濾波
基于STM32F103的風(fēng)力擺系統(tǒng),陀螺儀使用基于DMP的MPU6050可自行增加卡爾曼濾波
單片機(jī)源程序如下:
#include "sys.h"
#include "delay.h"
#include "key.h"
#include "mpu6050.h"
#include "inv_mpu.h"
#include "inv_mpu_dmp_motion_driver.h"
#include "USART2.h"
#include "pwm.h"
#include "PID.h"
#include "TIM.h"
#include "KEY.h"
#include "outputdata.h"
u8 RUN_MODE=0;
u8 Print=0;
float pitch,roll,yaw; //歐拉角
short aacx,aacy,aacz; //加速度傳感器原始數(shù)據(jù)
short gyrox,gyroy,gyroz; //陀螺儀原始數(shù)據(jù)
Pid_struct motor13_parameter,motor24_parameter; // 電機(jī)pid參數(shù)
void NVIC_Config(void);
int main(void)
{
short temp; //溫度
SystemInit();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_Config();
delay_init(); //延時(shí)函數(shù)初始化
PWM_Init(3000,0); //0分頻。PWM頻率=72000/(4000*1)=14Khz
PWM_Init_2(3000,0);
USART1_Config();
KEY_Init();
Speed_PIDInit(&motor13_parameter,30,0.2,100); // 電機(jī)pid 參數(shù)初始化
Speed_PIDInit(&motor24_parameter,60,0.2,200);
MPU_Init();
delay_ms(500);
while(mpu_dmp_init()); //初始化MPU6050_DMP
TIM4_Init(10000-1,71); //定時(shí)器初始化
uprintf(USART1," 系統(tǒng)啟動(dòng)成功!\r\n");
while(1)
{
// MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //得到加速度傳感器數(shù)據(jù)
// MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //得到陀螺儀數(shù)據(jù)
KEY_Scan();
if(Print==1){ // 發(fā)送曲線到上位機(jī)
OutData[0]=pitch;
OutData[1]=roll;
OutData[2]= motor13_parameter.out_duty/100;
OutPut_Data();
} } }
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure; //復(fù)位NVIC寄存器為默認(rèn)值
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //設(shè)置中斷優(yōu)先級組
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA
| RCC_APB2Periph_GPIOB
| RCC_APB2Periph_GPIOC
// | RCC_APB2Periph_GPIOD
// | RCC_APB2Periph_AFIO
| RCC_APB2Periph_TIM1
// | RCC_APB2Periph_ADC1
| RCC_APB2Periph_USART1
, ENABLE );
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3
| RCC_APB1Periph_TIM4
| RCC_APB1Periph_TIM2
, ENABLE);
//復(fù)位NVIC寄存器為默認(rèn)值
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //搶占優(yōu)先級2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //響應(yīng)優(yōu)先級0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
復(fù)制代碼
原理圖: 無
仿真: 無
代碼:
MPU6050_DMP_Stm32.7z
(289.75 KB, 下載次數(shù): 18)
2023-11-22 19:19 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1