I using a MPU 6050 and raspberry pi pico for making an IMU. I have set the range of accelerometer as +- 2 g but there is a .96 g offset this severly limits the sensing range on the positive side. I have written a calibration program which works fine in which we explicitly add the offsets to the data `
def calibrate(i2c):
temp=0
accel_x,accel_y,accel_z,gyro_x,gyro_y,gyro_z=0,0,0,0,0,0
for i in range(10000):
temp += read_raw_data(i2c, TEMP_OUT_H) / 340.0 + 36.53
accel_x += read_raw_data(i2c, ACCEL_XOUT_H) / 16384.0
accel_y += read_raw_data(i2c, ACCEL_XOUT_H + 2) / 16384.0
accel_z += read_raw_data(i2c, ACCEL_XOUT_H + 4) / 16384.0
gyro_x += read_raw_data(i2c, GYRO_XOUT_H) / 131.0
gyro_y += read_raw_data(i2c, GYRO_XOUT_H + 2) / 131.0
gyro_z += read_raw_data(i2c, GYRO_XOUT_H + 4) / 131.0
print('calibration done')
t=temp/10000
a_x=accel_x/10000
a_y=accel_y/10000
a_z=accel_z/10000
g_x=gyro_x/10000
g_y=gyro_y/10000
g_z=gyro_z/10000
is there any way in which i can calibrate the sensor and still get full range?
The 0.96 g is gravitational acceleration and must be from the vertical axis (typically z-axis). This is not a sensor bias. Included in the accelerometer acceleration measurement is gravitational acceleration. And so the answer is no. Gravity will take up part of the measurement range.
To get a feel for typical accelerometer readings check out a sample dataset from https://imuengine.io/resources/. Copied here are the first few IMU entries from the automotive dataset where the z-axis nominally points down. Convert the units from m/s^2 to g's and you see the same approximate 1 g from gravity.
TimeFromStart (s) AccelX (m/s^2) AccelY (m/s^2) AccelZ (m/s^2) AngleRateX (rad/s) AngleRateY (rad/s) AngleRateZ (rad/s)
49.27 0.0065134831 0.1535978052 -9.8256081343 0.0033288721 0.0021099924 -0.000368629
49.28 -0.1163793611 0.1524602878 -9.7294434905 -0.0014737246 -0.001269474 -5.3143600000000004e-05
49.29 -0.1772884163 0.1816529664 -9.833201021 -0.0009057809 -0.0002318527 -0.0004045664
Measuring "acceleration minus gravity" is also possible but requires a layer of sensor fusion. The method shown in the original post falls apart if the sensor is tilted. Feel free to post a new question detailing the requirements if that is what you need then.