Minimu-9 V2 Python Script Wrong Axis

I was testing the AHRS code and while it seems the arduino code is working properly, Python code seems to have pitch and roll axis flipped and I don’t know how to change this.

In the Arduino AHRS code, if I use the default axis setting:

int SENSOR_SIGN[9] = {1,1,1,-1,-1,-1,1,1,1};

Then there’s massive drift with the gyroscope and incorrect yaw.

But if I use the next setting:

int SENSOR_SIGN[9] = {1,-1,-1,-1,1,1,1,-1,-1};

The sensor is very responsive and yaw works correctly. The only problem is that pitch and roll are flipped. If I tilt the pitch nose down, the python script draws nose pitch up. Roll is flipped likewise.

I tried changing each axis setting in the Arduino code but it doesn’t seem to be having any positive effect. When making changes, I made sure I consider each axis in each sensors in the code above. x,y,z,x,y,z,x,y,z

I have already calibrated the magnetometer using the Arduino library for lsm303.

I found a fix.

In the ‘if len(words) > 2:’ loop,

This line:
axis=(cos(pitch)*cos(yaw),cos(pitch)*sin(yaw),sin(pitch))

Must be changed to this:
axis=(cos(pitch)*cos(yaw),-cos(pitch)*sin(yaw),-sin(pitch))

Other than this, sensor performs amazingly!!! I can even flip it upside down and there seems to be very minimal drift (about 1 degree) which I am very happy with.

Thanks Pololu!

Hello, jykm12.

I’m glad to hear you figured out a solution, although I’m not sure why you needed to change the code (I would have expected one or the other definition of SENSOR_SIGN to just work). Do the IMU and the software seem to be working as you expect now? How do you have the board mounted or positioned?

- Kevin

I’m not sure. The code with its default settings was not working for me (massive drift and wrong axis all over) so I was trying the second option and I noticed that it was working very well except the flipped axis. I did not know much about the code that was provided but managed to get it working.

I had the board firmly placed on a breadboard with no devices that may possibly interfere with magnetometer.