kriswiner / MPU9250

Arduino sketches for MPU9250 9DoF with AHRS sensor fusion
1.03k stars 472 forks source link

data order for madgwick filter for mpu9255/mpu9250 #358

Closed shomedas closed 5 years ago

shomedas commented 5 years ago

I am trying to use MPU9255 with the code at https://github.com/kriswiner/ESP32/blob/master/MPU9250_MS5637/MPU9250_MS5637_AHRS.ino which uses the NED convention. The magnetometer and the accelerometer has been well calibrated using least squares. There is no drift and error is within 2degree on each axes. The quaternion value is 1,0,0,0 when the x axis of the accelerometer points north. The relative rotation(axis & angle found from the quaternion) between two orientations of the IMU are also correct. So far so good.

My question is wrt the madgwick order. As per your post in https://github.com/kriswiner/MPU9250/issues/345 & https://github.com/kriswiner/MPU9250/issues/341 the order for madgwick should be as follows(NWU convention in your post)

Once the board edge facing North is decided then it is a simply matter to find out which accel axis point North, then West, then Up. Then the filter should get the data as AN, AW, AU...same for the other two sensors.

So If i use NED convention to mpu9250 it should be (AN, AE, AD, GN,GE,GD, MN, ME,MD) If I align the MPU9255 with the x axis of the accelerometer pointing to north, the it should be (ax, -ay, az, gx, -gy, gz, my, -mx, mz). In your code why is it -ax, ay, az, gx, -gy, -gz, my, -mx, mz;

Please refer to the MPU9255 accelerometer and magnetometer image below: 9250_orientation

The board I am using is IMU

shomedas commented 5 years ago

I got my answer in another of your codes https://github.com/kriswiner/MPU9250/blob/master/MPU9250_MS5637_AHRS_t3.ino which says

So if we want te quaternions properly aligned we need to feed into the Madgwick function Ax, -Ay, -Az, Gx, -Gy, -Gz, My, -Mx, and Mz. But because gravity is by convention positive down, we need to invert the accel data, so we pass -Ax, Ay, Az, Gx, -Gy, -Gz, My, -Mx, and Mz into the Madgwick function to get North along the accel +x-axis, East along the accel -y-axis, and Down along the accel -z-axis.