Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino - MPU 6050 - Library Orientation #397

Open
ThePoshTux opened this issue Sep 21, 2018 · 1 comment
Open

Arduino - MPU 6050 - Library Orientation #397

ThePoshTux opened this issue Sep 21, 2018 · 1 comment

Comments

@ThePoshTux
Copy link

ThePoshTux commented Sep 21, 2018

For my application of the sensor, a VR headset, I need the axes to be redefined to Yaw about the x-axis, Pitch about the y-axis and roll about the z-axis. Looking at example code and at the MPU6050_9Axis_MotionApps41.h library, I found that to redefine the axes the library must be modified. Shown below I have modified dmpGetYawPitchRoll (from the same library) to use the different axes so that the yaw and pitch now work correctly. However, the roll does not work correctly.

Modified code:
uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) { // yaw: (about x axis) data[0] = atan2(2*q -> y*q -> z - 2*q -> w*q -> x, 2*q -> w*q -> w + 2*q -> y*q -> y - 1); // pitch: (nose up/down, about y axis) data[1] = atan(gravity -> y / sqrt(gravity -> z*gravity -> z + gravity -> x*gravity -> x)); // roll: (tilt left/right, about z axis) data[2] = atan(gravity -> z / sqrt(gravity -> y*gravity -> y + gravity -> x*gravity -> x)); return 0; }

original:
uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) { // yaw: (about Z axis) data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1); // pitch: (nose up/down, about Y axis) data[1] = atan(gravity -> x / sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z)); // roll: (tilt left/right, about X axis) data[2] = atan(gravity -> y / sqrt(gravity -> x*gravity -> x + gravity -> z*gravity -> z)); return 0; }

When facing forward the roll works correctly, changing my yaw by +/- 90 degrees disables all roll and turning 180(from forwards) causing the roll to become inverted.
I believe my issue may stem from not modifying quaternation or gravity to the new axis but I am lost when trying to modify those sections of the code.

What would be the correct changes I would have to make to the library as to modify the orientation?

Looking at the Issues page I have seen people posting about issues that they think are of calibration but share symptoms of incorrect axes mapping I have experienced.

Regardless, thank you for the great work.

@ThePoshTux
Copy link
Author

#64

@ThePoshTux ThePoshTux changed the title MPU 6050 Library Orientation Arduino - MPU 6050 - Library Orientation Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant