Unable to get consistent euler angles
prabodhprakash opened this issue · 9 comments
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
@prabodhprakash Hi, thank you for reporting. Please
- check if the device is the real MPU-9250 (see #52 )
- try
simple_with_calibration
example first - check if the averaged offsets/bias units are correct (calibration values shown in a console in examples are not the same as the value that should be set)
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
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
Hmm, I think there are two possibilities.
- Calibration is not enough (see #68 #62 )
- Your device is not MPU9250 but MPU9265(?) (maybe the magnetometer inside is not the same as MPU9250)
https://www.tenettech.com/product/gy-87-mpu-9265-3-axis-9-dof-attitude-gyro-magnetometer-accelerator-sensor-module
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.
I tried other libraries as well - but couldn't get it work :-(
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