在mpu6050零偏校正代码中,acc的z轴数据为何要减去2048?
void MPU6050_Offset(void)
{
if(ACC_Offset)
{
//¾²Ì¬Éú´æÆÚ£¬Ö»ÔÚº¯ÊýµÚÒ»´Îµ÷ÓÃʱ³õʼ»¯
static int32_t ACC_X=0,ACC_Y=0,ACC_Z=0;//ÐèÒªÀÛ¼ÆÁãƯ£¬ËùÒÔ32룬·ÀÖ¹Òç³ö
static uint8_t count_acc=0;
if(count_acc == 0)
{
offset_acc.x = 0;
offset_acc.y = 0;
offser_acc.z = 0;
ACC_X = 0;//¾²Ì¬±äÁ¿£¬ÐèÒªÊÖ¶¯»Ö¸´Îª0
ACC_Y = 0;
ACC_Z = 0;
count_acc = 1;
return;//?µÚÒ»´Î¼ÆËãÁãÆ«Ö»ÐèÒªÉèÖóõʼֵ¾Í¿ÉÒÔÍ˳öº¯ÊýÁË
}
else
{
count_acc++;
ACC_X += acc.x;
ACC_Y += acc.y;
ACC_Z += acc.z;
}
if(count_acc == 251)//ÀÛ¼Æ250msµÄÁãµãƯÒÆÁ¿£¬Çóƽ¾ùÿ´Î²âÊý¾ÝµÄÁãƯ
{
count_acc--;
offset_acc.x = ACC_X/count_acc;
offset_acc.y = ACC_Y/count_acc;
offset_acc.z = ACC_Z/count_acc-2048;//£¿
count_acc = 0;
ACC_Offset = 0;
EEPROM_SAVE_ACC_OFFSET();//УÕý½á¹û´æ·ÅÔÚflash»òeeprom
}
LED3_ON;//»úÉíÖÜΧµÄÒ¹¼äµÆÁÁ
}
if(GYRO_Offset)//ͬÀí£¬¿´acc¶Î×¢ÊÍ
{
static int32_t GYRO_X=0,GYRO_Y=0,GYRO_Z=0;
static uint8_t count_gyro=0;
if(count_gyro)
{
offset_gyro.x = 0;
offset_gyro.y = 0;
offset_gyro.z = 0;
GYRO_X = 0;
GYRO_Y = 0;
GYRO_Z = 0;
count_gyro = 1;
return;
}
else
{
count_gyro++;
GYRO_X += gyro.x;
GYRO_Y += gyro.y;
GYRO_Z += gyro.z;
}
if(count_gyro == 251)
{
count_gyro--;
offset_gyro.x = GYRO_X/count_gyro;
offset_gyro.y = GYRO_Y/count_gyro;
offset_gyro.z = GYRO_Z/count_gyro;//?
count_gyro = 0;
GYRO_Offset = 0;
EEPROM_SAVE_GYRO_OFFSER();
}
LED3_ON;
} |