1
\$\begingroup\$

I am having some trouble to understand the axis orientation of my MPU9250 chip. So this is my chip:

MPU9250

My understanding is that the positive x and y axis are as per what has been marked in the chip and positive z axis is the upward direction, so when the sensor is lying flat the reading should be -1g in the z axis, which is what is happening.

Now if I point the positive x axis towards earth, then x axis reading should be +1g right?

So for this orientation I am getting -1g in the y axis, where I am expecting the x axis to be +1g.

x axis towards earth

reading for x axis towards earth

And when I point the positive y axis towards earth, I am getting -1g reading in the x axis.

y axis towards earth

reading for y axis towards earth

I am using this driver for the chip and following are my code snippets:

float ax = imu.accel_x_mps2();
float ay = imu.accel_y_mps2();
float az = imu.accel_z_mps2();

Serial.print(ax);
Serial.print(",");
Serial.print(ay);
Serial.print(",");
Serial.println(az);

Is my understanding of how the axes work or is there something wrong with the chip or incompatibility with the driver?

\$\endgroup\$
6
  • \$\begingroup\$ Your photo isn't clear, I can't see pin 1 on the chip. Does it match the datasheet, ie pin 1 top right in your first photo, closest to "SDA"? \$\endgroup\$
    – tomnexus
    Commented Sep 4, 2023 at 4:42
  • \$\begingroup\$ How the chip is mounted on PCB is not very clesr from the pictures. How the chip is oriented on PCB and what does the chip data sheet says about the axes being oriented? \$\endgroup\$
    – Justme
    Commented Sep 4, 2023 at 4:42
  • \$\begingroup\$ @tomnexus, robu.in/wp-content/uploads/2017/09/download-1-2.jpg you can check the clear image of the chip here. \$\endgroup\$ Commented Sep 4, 2023 at 4:46
  • \$\begingroup\$ @Justme, In the first photo the chip is lying flat on my table, the readings are x=0, y=0, z=-1g. In the second photo it's lying on the side, i.e. the x axis arrow in the chip is pointing towards earth and in the third photo the y axis arrow is pointing towards the earth. \$\endgroup\$ Commented Sep 4, 2023 at 4:48
  • \$\begingroup\$ Ok so the chip and the board are consistent. It must be the driver. Also calling the driver into question, lying on the bench, Z should read +1 g. It's accelerating at 1 g in the direction of +z. \$\endgroup\$
    – tomnexus
    Commented Sep 4, 2023 at 5:06

1 Answer 1

1
\$\begingroup\$

From your photo, the chip and the board markings look consistent with the datasheet

The problem is likely to be with the driver. It's possible someone redefined the axes to suit themselves, when they wrote it.

Z also looks wrong. When lying on the bench, Z should read +1 g, because the acceleration it feels is 1 g in the direction of +z. Slightly counterintuitive, it helps to imagine accelerating it more and thinking about the forces it will feel. See this answer too.

Simplest would be to swap the axes in your software and carry on. Otherwise, open the driver source code, and the datasheet, and dig through until you find the mistake.


The driver code does say, most suspiciously:

/* Convert to float values and rotate the accel / gyro axis */ accel_[0] = static_cast(accel_cnts_2) * accel_scale_ * G_MPS2_;

accel_2 = static_cast(accel_cnts_[0]) * accel_scale_ * G_MPS2_;

accel_2 = static_cast(accel_cnts_2) * accel_scale_ * -1.0f* G_MPS2_;

So (without reading the registers) this might explain the -Z and the swapped X and Y.

\$\endgroup\$
2
  • \$\begingroup\$ Hi @tomnexus, got this from the library docs github.com/bolderflight/invensense-imu#sensor-orientation, does it explain the behaviour I am getting? \$\endgroup\$ Commented Sep 4, 2023 at 6:29
  • 1
    \$\begingroup\$ Got a reply from the library author: "Yes, please refer to the documentation on the README for the orientation of the outputs from this library. By default, the MPU-9250 gyro and accel values are in a different orientation than the magnetometer values (refer to page 38 of the MPU-9250 datasheet). This library rotates the outputs so they all have the same orientation and to match a common orientation for aeronautical systems (+X out the nose, +Y out the right wing, +Z down)." \$\endgroup\$ Commented Sep 4, 2023 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.