1
\$\begingroup\$

I'm having a hard time putting this question into words but basically I have an IMU (MPU-6050) and am able to get the data to stream using the i2cDev library.

The IMU is in a box and I want to be able to determine which side the box is on (which I assume will be easy using using the gravitational direction as a reference point) and then have that side's yaw be calculated.

In a sense, I want to pretend that the absolute Yaw, Pitch, and Roll don't exist for the device and instead that each side of the box has a relative Yaw.

\$\endgroup\$
  • \$\begingroup\$ Careful with MPU-6050 and the i2c library. It uses blocking calls which I've had trouble with in the past. Now, if you're accessing the X,Y,Z acceleration values, the side that the box is on will be the one with the largest X or Y or Z value. If its x=0,y=10,z=0, then perhaps it's right side up. If it's x=0,y=0,z=10, then it's on it's left side. Depends how you orient the sensor? Perhaps this is too obvious and I don't understand what you're asking? Posting code snippets never hurts. \$\endgroup\$ – Brian Dohler Jul 11 '16 at 2:09
  • \$\begingroup\$ I'm using an ESP8266 so the blocking calls aren't too problematic (tonnes of horsepower). I may have found the solution. It appears that the library automatically handles changing the Yaw/Pitch/Roll to being relative to which side is facing up (except the Yaw are not at linear with rotation when the chip isn't sitting parallel to the ground). \$\endgroup\$ – sabjorn Jul 16 '16 at 1:49
1
\$\begingroup\$

Jeff Roberg (author of I2CDev) has done a pretty good job with his MPU6050 library. Note that, pitch and roll are absolute values when you calculate them from the accelerometer values, but Yaw is relative as there is no Magnetometer in MPU6050.

When you power up the MPU6050, it will always start counting the yaw value from 0 or so degrees (range: 0 - 360 degrees), and then there will be some drift happening. But, the pitch and roll values will always be absolute in the range of -90 to +90 degrees.

If you want to calculate the orientation, don't follow yaw value! Use a combination of the 'gravity' component and the 'pitch' or 'roll' component.

\$\endgroup\$
  • \$\begingroup\$ What i'm finding is that the Yaw value reorients itself based on which side is facing down. In other words, if I put the the MPU 90 degrees to the ground (perpendicular rather than parallel), the axis which was formerly Pitch (or Roll) becomes the Yaw value automatically. And i'm not sure why. This works for my purposes but the Yaw values when the board is at this angle do not track as smoothly as when parallel to the ground. \$\endgroup\$ – sabjorn Sep 8 '16 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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