m-rtijn / mpu6050

A Python module for accessing the MPU-6050 digital accelerometer and gyroscope on a Raspberry Pi.
MIT License
296 stars 143 forks source link

Calibration? #3

Open chrisspen opened 8 years ago

chrisspen commented 8 years ago

How do you enter the offsets acquired during calibration? Otherwise, the values read from the device are raw and meaningless.

m-rtijn commented 8 years ago

Because no procedure for calibration of the hardware is given in the datasheet, there is no calibration implemented.

What this module does lack is an implementation of the self test procedure (7.12 of the datasheet).

chrisspen commented 8 years ago

I'm not asking how to calibrate it. This Arduino sketch explains how to do that http://wired.chillibasket.com/2015/01/calibrating-mpu6050/

I'm asking how to enter the 6 offsets (three for the accelerometer and three for the gyroscope). These are registers on the device:

MPU6050_RA_XA_OFFS_H MPU6050_RA_YA_OFFS_H MPU6050_RA_ZA_OFFS_H MPU6050_RA_XG_OFFS_USRH MPU6050_RA_YG_OFFS_USRH MPU6050_RA_ZG_OFFS_USRH

If you don't enter these, the values read from the device will be useless.

m-rtijn commented 8 years ago

While developing this module I used the MPU-6050 Register Map and Descriptions file (Document number: RM-MPU-6000A-00, release date: 4.2, Release date: 2013-08-19) which does not include information about the offset registers. Because of this, there is currently no option to use these registers in this module, since I only just learned about their existence (thanks to you because you pointed this out).

m-rtijn commented 8 years ago

I've decided that because for most applications calibrating the MPU-6050 is not necessary, since the factory calibration will be precise enough, that I won't add support for these calibration features.

If you want to add these features to this project, you're welcome to do so.

EDIT (2023-04-27): I think it would be a useful feature to add, but I currently don't have working MPU6050 chips to test any code. If anybody is interested to add this via a PR, it would be really welcome :)

byapparov commented 3 years ago

@m-rtijn I am not sure if I am doing something wrong, but I get bias of 16 d/s on the X gyro data. that makes it pretty much unusable without calibration.

Would be great to understand what is the way to overcome this, right now I have done a wrapper that adjusts for errors

Artoria2e5 commented 1 year ago

@byapparov The Arduino-MPU6050 library (linked from the official site) does basically what you do: the readNormalizeGyro() function subtracts a fixed offset and performs thresholding, both set from calibration at program start calibrateGyro(). It has not been updated for the new registers, so that could be why.

m-rtijn commented 1 year ago

It seems that there also exists a Linux kernel module that implements interfacing with the MPU6050, that code can also be used as inspiration: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/iio/imu/inv_mpu6050?h=v6.3

It can even be used directly I think. You can follow for example the steps here: https://petermolnar.net/article/linux-i2c-iio-collectd/#detecting-i2c-devices (just ignore the part about using the USB i2c adapter, since the Raspberry Pi has i2c built-in).