I am using i2cdev library
Code:(i did not know this code is correct or not)
#include <Arduino.h>
#include <MPU6050.h>
#include <kalman.h>
#include <stdint.h>
#define ACCELLSB 2048
#define GYROLSB 16.4
#define CONSOLE
#define CALIBRATE
#ifdef CALIBRATE
int16_t Accel_X_offset;
int16_t Accel_Y_offset;
int16_t Accel_Z_offset;
int16_t Gyro_X_offset;
int16_t Gyro_Y_offset;
int16_t Gyro_Z_offset;
#endif
MPU6050 mpu6050;
Kalman AngleX;
Kalman AngleY;
void setup()
{
mpu6050.initialize();
mpu6050.setFullScaleAccelRange(MPU6050_ACCEL_FS_16);
mpu6050.setFullScaleGyroRange(MPU6050_GYRO_FS_2000);
#ifdef CALIBRATE
mpu6050.CalibrateAccel();
mpu6050.CalibrateGyro();
Accel_X_offset = mpu6050.getXAccelOffset();
Accel_Y_offset = mpu6050.getYAccelOffset();
Accel_Z_offset = mpu6050.getZAccelOffset();
Gyro_X_offset = mpu6050.getXGyroOffset();
Gyro_Y_offset = mpu6050.getYGyroOffset();
Gyro_Z_offset = mpu6050.getZGyroOffset();
#endif
int16_t AccelX, AccelY, AccelZ;
int16_t GyroX, GyroY, GyroZ;
mpu6050.getMotion6(&AccelX,&AccelY,&AccelZ,&GyroX,&GyroY,&GyroZ);
// I am going to use this values in kalman filter
#ifdef CALIBRATE
AccelX -= Accel_X_offset;
AccelY -= Accel_Y_offset;
AccelZ -= Accel_Z_offset;
GyroX -= Gyro_X_offset;
GyroY -= Gyro_Y_offset;
GyroZ -= Gyro_Z_offset;
#endif
}
void loop()
{
}
What is the correct way to calibrate mpu6050(Correct me what i am wrong or this is correct)?
Thanks.