[SOLVED] How to change IMU going from 179 to -179 (wrapping data) (MPU9250)

Hi Everyone,

Yet another question around IMUs. In particular I am using an MPU9250. The issue I'm having is in the natural orientation of the my project the IMU seems to wobble the line where the IMU changes from 180 to -180 on the Roll data. This means any slight vibration, even when the IMU is sat stationary with no noticeable movement fluctuates the data massively. (See below image)

For reference I am using the following library

I can't see anything obvious in the documentation for library which details how to remap this. without corrupting the data. Any tips?

A common issue with many IMU libraries. Where rollover is not being done correctly. Meaning the IMU is sitting at 0 but when it 'feels'-1 or 2 degrees it shoots to -179, which is on the other side of your scale.

I solved it by writing my own library.

Try different library.

Thanks Idahowalker. What would doing it correctly look like?

Logically in my mind it would being at 90 and the roll and pitch angles should calculate the change in angle limited to +/-180.

Unfortunately for this particular IMU there aren't many libraries which calculate aeroplane co ordinates (yaw pitch and roll) and which does it well....

I have tried a calling the registers directly in a make shift library of my own but to no avail. I don't think my coding skill is quite at that level yet unfortunately. Perhaps the best solution is to try and find the calculations in the library source code and adapting it to use what I mentioned above?

Ya, I find many libraries do not do what I want so I lod em as files for the project and make adjustments as necessary.

The Boulder Mtn library for the MPU9250 worked well. If you open up the ccp file of the Boulder library the way he transforms the x,y,z is visible.

Taken you suggestion into account. I'm assuming you meant Bolder Flight Controller (only similar library I could find.

I have managed to get something working which is somewhat surprisingly accurate by calculating roll and pitch using the accel data from the library. The following is how I did this.

  pitch = 180 * atan (accelerationX/sqrt(accelerationY*accelerationY + accelerationZ*accelerationZ))/M_PI;
  roll = 180 * atan (accelerationY/sqrt(accelerationX*accelerationX + accelerationZ*accelerationZ))/M_PI;

Win!... at least it was at first :confused: . The issue now is that the Y accel data is not directional. What I mean is regardless of the direction of rotation, the angle decreases. For e.g if I rotate the IMU forward (CW) the values from the Y accel decreases (subsequently so does the roll) and also if I rotate it backward (CCW) it still decreases. I've been trying to find the answer to why this is happening in the source code but no dice.... any tips or suggestions?

A

Solved it !

Anyone who may have a similar issue and stumbles accross this post see below link to the fix.

Essentially go into the library and swap the 'void update_euler(){' with the one specified in the issues page. Also change the update quat filter as described.

Thanks for your help anyway Idahowalker!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.