资源简介
STM32F407读取MPU9250源代码,含有磁力计ak8963校准算法,加速度 陀螺仪数据读取及校准算法,
代码片段和文件信息
#include “mpu9250.h“
#include “delay.h“
#include “struct_all.h“
uint8_t ACC_GYRO_Offset1 = 0;//不自动校正
uint8_t MAG_Offset1=0MAG_Offset2=0;//不自动校正
float Hxs=1.0fHys=1.0fHzs=1.0f;
void Init_MPU9250(void)
{ I2C_ByteWrite(GYRO_ADDRESSPWR_MGMT_10x00); delay_ms(4);
I2C_ByteWrite(GYRO_ADDRESSSMPLRT_DIV0x00); delay_ms(4);
I2C_ByteWrite(GYRO_ADDRESSCONFIG0x03); delay_ms(4);
I2C_ByteWrite(GYRO_ADDRESSGYRO_CONFIG0x18);delay_ms(4);
I2C_ByteWrite(GYRO_ADDRESSACCEL_CONFIG0x18);delay_ms(4);
I2C_ByteWrite(GYRO_ADDRESSACCEL_CONFIG_20x02);delay_ms(4);
I2C_ByteWrite(GYRO_ADDRESS0x370x02); delay_ms(4);
I2C_ByteWrite(MAG_ADDRESS0x0A0x16); delay_ms(4);
}
/******************************************************************************
函数原型: void Do_ACC_GYRO_Offset(void)
功 能: MPU9250零偏校正
*******************************************************************************/
void Do_ACC_GYRO_Offset(void)
{
ACC_GYRO_Offset1=1;
}
void Do_MAG_Offset(void)
{
MAG_Offset1=1;
}
void ACC_GYRO_Offset(void)
{ static int32_t ACC_X=0ACC_Y=0ACC_Z=0;
static int32_t GYRO_X=0GYRO_Y=0GYRO_Z=0;
static uint8_t count_acc_gyro=0;
if(ACC_GYRO_Offset1)
{ if(count_acc_gyro==0)
{ LED2=1;
conf.offset_acc.x = 0;conf.offset_gyro.x = 0;
conf.offset_acc.y = 0;conf.offset_gyro.y = 0;
conf.offset_acc.z = 0;conf.offset_gyro.z = 0;
ACC_X = 0;GYRO_X = 0;
ACC_Y = 0;GYRO_Y = 0;
ACC_Z = 0;GYRO_Z = 0;
count_acc_gyro = 1;
}
else
{
count_acc_gyro++;
ACC_X += acc.x;GYRO_X += gyro.x;
ACC_Y += acc.y;GYRO_Y += gyro.y;
ACC_Z += acc.z;GYRO_Z += gyro.z;
}
if(count_acc_gyro==251)
{ count_acc_gyro--;
conf.offset_acc.x = ACC_X/count_acc_gyro;conf.offset_gyro.x = GYRO_X/count_acc_gyro;
conf.offset_acc.y = ACC_Y/count_acc_gyro;conf.offset_gyro.y = GYRO_Y/count_acc_gyro;
conf.offset_acc.z = ACC_Z/count_acc_gyro-2048;conf.offset_gyro.z = GYRO_Z/count_acc_gyro;
conf.angleTrim[ROLL]=0; conf.angleTrim[PITCH]=0;
SPIROM_SAVE_PID_BOX();
count_acc_gyro = 0;
ACC_GYRO_Offset1 = 0;
LED2=0;
}
}
}
void MAG_Offset(void)
{ static int16_t X_maxX_minY_maxY_minZ_maxZ_min;
static uint16_t count_mag=0;
if(MAG_Offset1)
{ if(count_mag==0)
{ LED1=1;
conf.offset_mag.x = 0;conf.offset_mag.y = 0;
Hxs=1;Hys=1;
count_mag=1;
}
else if(count_mag==1)
{ X_max=mag.x;X_min=mag.x;Y_max=mag.y;Y_min=mag.y;
count_mag=2;
}
else
{ count_mag++;
if(mag.x>X_max) X_max=mag.x;
if(mag.x if(mag.y>Y_max) Y_max=mag.y;
if(mag.y }
if(count_mag==721)
{ Hxs= 1 ;
Hys=(float)(X_max-X_min)/(Y_max-Y_min);
conf.offset_mag.x =Hxs*(X_max+X_min)/2;
conf.offset_mag.y =Hys*(Y_max+Y_min)/2;
c
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5034 2019-01-07 01:22 mpu9250.c
文件 1477 2018-07-06 12:37 mpu9250.h
----------- --------- ---------- ----- ----
6511 2
- 上一篇:基于单片机的json编解码源码.zip
- 下一篇:基于pic单片机的数字pfc源码
相关资源
- stm32 BootLoader程序(main.c)
- json读取(json.c)
- 高性能服务器代码(50_06th_server_thre
- socket客户端.c
- socket服务端.c
- 代码雨.cpp
- crc16/32计算(crc16_32.c)
- libevent(timeout.cpp)
- fluent UDF求解圆柱涡致振动问题(VIV
- 密码学 重合指数计算(IC.cpp)
- 弹跳的小球(test.c)
- 学生成绩管理系统.c
- 输出n的阶乘.cpp
- opencv2 3D标定.cpp
- c 操作sqlite数据库.cpp
- C语言标准库函数大全.chm
- 校园闲置物品管理系统.c(控制台)
- 扫雷游戏.cpp
- c++爱心表白(心.cpp)
- CC++词典手册.chm
- stm32 实现Fatfs对U盘文件操作(main.c)
- 《一个月挑战C++》.chm
- 算法表达式求值.cpp
- PID算法.c
- 链表的基本操作.c
- 链表实现学生管理系统(main.c)
- 银行家算法分配资源的模拟实现(m
- 常见排序算法比较.cpp
- 无向图M着色.cpp
- 单片机控制绕线机.c
评论
共有 条评论