hideakitai / MPU9250

Arduino library for MPU9250 Nine-Axis (Gyro + Accelerometer + Compass) MEMS MotionTracking™ Device
MIT License
277 stars 91 forks source link

Unable to get consistent euler angles #69

Closed prabodhprakash closed 2 years ago

prabodhprakash commented 2 years ago

Hardware: MPU9250: https://www.xcluma.com/mpu-9250-gy-9250-mpu9250-nine-axis-sensor-module-i2c-spi-communication?search=9250

ESP8266MOD: https://handsontec.com/index.php/product/esp8266-remote-serial-wifi-module/

Connection:

ESP8266MOD         MPU9250
5V------------------VCC
GND-----------------GND
D2------------------SDA
D1------------------SCL

To setup biases: I calibrated my sensor 5 times using calibration.ino and averaged out the values.

Code:

#include "MPU9250.h"

MPU9250 mpu;

void setup() {
    Serial.begin(115200);
    Wire.begin();
    delay(2000);

    if (!mpu.setup(0x68)) {  // change to your own address
        while (1) {
            Serial.println("MPU connection failed. Please check your connection with `connection_check` example.");
            delay(5000);
        }
    }

    mpu.setAccBias(66.23, 16.95, -240.16);
    mpu.setGyroBias(5.08, 6.27, -10.43);
    mpu.setMagBias(290.34, 147.44, -441.84);
    mpu.setMagScale(0.90, 1.16, 0.97);
    mpu.setMagneticDeclination(-1.14);
    mpu.setFilterIterations(10);
}

void loop() {
    if (mpu.update()) {
        static uint32_t prev_ms = millis();
        if (millis() > prev_ms + 250) {
            print_roll_pitch_yaw();
            prev_ms = millis();
        }
    }
}

void print_roll_pitch_yaw() {
    Serial.print("Euler X, Y, Z: ");
    Serial.print(mpu.getEulerX(), 2);
    Serial.print(", ");
    Serial.print(mpu.getEulerY(), 2);
    Serial.print(", ");
    Serial.println(mpu.getEulerZ(), 2);
}

Problem: Unable to get consistent euler angles in any direction.

If I rotate the sensor perpendicular - the expectation is that one of the (x, y, z) should change by 90 - however, on some axis it changes by 180 and on other axis it changes less than 90.

Kindly help

hideakitai commented 2 years ago

@prabodhprakash Hi, thank you for reporting. Please

prabodhprakash commented 2 years ago

hey @hideakitai while I check for authenticity of the sensor, I tried the program with simple_with_calibration and here's the result.

I just rotated the sensor from flat surface to perpendicular:

13:03:30.111 -> Euler X, Y, Z: 169.65, -68.10, 115.76
13:03:30.369 -> Euler X, Y, Z: 170.00, -67.95, 115.63
13:03:30.665 -> Euler X, Y, Z: 8.40, -56.15, -85.78
13:03:30.960 -> Euler X, Y, Z: 1.80, -16.44, -95.47
13:03:31.220 -> Euler X, Y, Z: 60.62, -80.69, -157.60
13:03:31.513 -> Euler X, Y, Z: 31.70, -67.39, -125.73
13:03:31.774 -> Euler X, Y, Z: 21.75, -50.76, -114.71
13:03:32.068 -> Euler X, Y, Z: 14.58, -31.50, -109.42
13:03:32.366 -> Euler X, Y, Z: 7.53, -13.79, -108.78
13:03:32.623 -> Euler X, Y, Z: 4.43, -7.42, -112.28
13:03:32.921 -> Euler X, Y, Z: 3.68, -5.85, -115.80

The EulerX changes by almost 180 degrees

hideakitai commented 2 years ago

How about NOT perpendicular angles? In the perpendicular angles, you may encounter a gimbal lock

https://stackoverflow.com/questions/41933779/madgwick-imu-90-degrees-angles?utm_source=pocket_mylist

https://electronics.stackexchange.com/questions/532805/imu-madgwick-filter-pitch-effect-on-roll-and-yaw?utm_source=pocket_mylist

prabodhprakash commented 2 years ago

other angles are also not working fine - like when I rotate by 45-degrees - the rotation is either very high or very low. It is consistent across axis (like always very high or low) - but never correct.

On Thu, 21 Oct 2021 at 1:28 PM, Hideaki Tai @.***> wrote:

How about NOT perpendicular angles? In the perpendicular angles, you may encounter a gimbal lock

https://stackoverflow.com/questions/41933779/madgwick-imu-90-degrees-angles?utm_source=pocket_mylist

https://electronics.stackexchange.com/questions/532805/imu-madgwick-filter-pitch-effect-on-roll-and-yaw?utm_source=pocket_mylist

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hideakitai/MPU9250/issues/69#issuecomment-948356416, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3WRT5BWIJHACGAAFS3PPDUH7B3DANCNFSM5GNMB7NQ .

-- Prabodh Prakash

hideakitai commented 2 years ago

Hmm, I think there are two possibilities.

prabodhprakash commented 2 years ago

The sensor has this written:

9250/9255/6500/6555 and if you open this link: https://www.xcluma.com/mpu-9250-gy-9250-mpu9250-nine-axis-sensor-module-i2c-spi-communication?search=9250

Prabodh Prakash

On Thu, Oct 21, 2021 at 2:51 PM Hideaki Tai @.***> wrote:

Hmm, I think there are two possibilities.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hideakitai/MPU9250/issues/69#issuecomment-948421800, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3WRTZETCVAVLAOZ2NOVJLUH7LQFANCNFSM5GNMB7NQ .

hideakitai commented 2 years ago

I don't know if this is truly MPU-9250, but I can't support it if it isn't (not compatible with MPU-9250). If you are confident about your calibration, how about trying another MPU9250 library? It may work fine with yours.

prabodhprakash commented 2 years ago

I tried other libraries as well - but couldn't get it work :-(

hideakitai commented 2 years ago

I'm sorry to hear that... I don't think it's a problem with this library, so I'm closing this issue. But I wish you good luck with your project! You can fuse raw sensor values manually with an external library like this : MadgwickAHRS