• 大小: 2KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-05-18
  • 语言: C/C++
  • 标签: mpu9250  .C  

资源简介

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


评论

共有 条评论