cancel
Showing results for 
Search instead for 
Did you mean: 

Question about MotionFX error in 9-axis

MPoul.2
Associate II

Hello,

I'm currently working on a project requiring to get X, Y and Z angles from 2 sensors, (IIS2MDC and ISM330DHCX). In order to do so, I use MotionFX and its 2 functions, MotionFX_propagate and MotionFX_update, both used to run Kalman STM's algorithms.

Everything works fine on the X and Y axis.

However, the Z axis is not responding as it should:

While the board is on it's first side, the Z angle is correctly read and computed. If the board is rotated of 90°, the result returned is indeed 90°.

But if the board is fliped on its other side, the angle I get is 60°.

Furthermore, that behavior is no observed if the data is acquired and processed as a 6-axis acquisition.

Has anyone observed such an issue? Could it be a magnetometer calibration or a sensor setup issue?

Many thanks for the help you could provide.

Matthieu

29 REPLIES 29
Miroslav BATEK
ST Employee

Hello,

Yes, It seems like a problem with the magnetometer. Did you perform magnetometer calibration?

Do you compensate the magnetometer data before passing them to the MotionFX library?

Hello,

Thank you for your answer.

I tried to use the functions used to calibrate magnetometer however, they never worked and the run function made my application crash. However, it seems that the calibration result is a constant offset. As a result it would also apply when the board is on the working side. So i'm not sure the calibration would result in any better results.

I'm currently working to use the Example Project from scratch to see if i did something wrong while setting up the project.

OK, I would focus on the reason why the function for magnetometer crashed The build-in magnetometer calibration provides Hard Iron coeffects, the magnetometer data must be compensated using these HI coefficients.

You can check example application in X-CUBE-MEMS1 package.

You can also share the code with me and I can check it.

So I completly replaced my application with the DataLogFusion example from IKS02A1 in which i added my SPI communication.

The issue still remains, however i can now run the callibrate function (not sure that it goes all the way to the end though).

I found while printing the magnetometer values that sometimes i have spikes, and sometimes those values get stuck to those wrong values (it goes from 0.20 to -40 for example). While I remain to values around 0.2, i get correct angles, but as soon as i get a change of value the returned angle is wrong).

I will send you the code i used, could you check if everything is setup as it should?

Many thanks for your answers.

Hello,

I don't see any obvious problem in your code.

In order to perform magnetometer calibration you need to do 8-shape movement or rotate the bord along all three axis. For details about magnetometer calibration you can check user manual for MotionMC library here.

Please check you are able to reach GOOD magnetometer calibration result (if (mag_data_out.cal_quality == MFX_MAGCALGOOD)).

If you are able to save datalog with the sensor data (timestamp, acc, gyro, mag) I can also check them.

You can record one log with the calibration and second log with the 90 degree movements.

Hello Miroslave,

Thanks a lot for your help. The calibration offset was indeed the issue, along some setup for the GetOrientation functions.

We greatly appreciate your help and the time you gave us.

Thank you once again and have a good day!

Matthieu

You are welcome. I'm glad you resolved the issue.

Hello Miroslav.

Sadly we were too fast in saying the issue was solved and we still have it.

While performing tests on the magnetometer (and only magnetometer), we found a strange behaviour.

While aligning (for example) axis Z on the earth magnetic field, the other 2 values should be near 0, as the axis are perpendicular to this field. However, one is always much higher (even higher than the Z value). If We perform a rotation on the Z axis, here is what happens:

0° : the abnormal value is now observed on Y axis

90° : the abnormal value is now observed on X axis

180°: (-)the abnormal value is now observed on Y axis

This value is always collinear to the gravity field.

We though this could be someway related to the desktop we use, but the same behavior is also observed when our board isn't near it.*

I'm pretty sure this value is what makes our measurment go wrong.

As for the values, when an axis is colinear to the magnetic field, its values is around +/- 200 mG, The wrong value is about 400 mG.

Hello,

would you please create a log of the magnetometer X,Y,Z data during a rotation along the axis and share it with me.

I'm not sure if I understand you correctly but it sounds like soft iron error:

Soft iron distortion arises from the interaction of the Earth magnetic field and the material which surrounds the magnetometer sensor distorting the Earth magnetic field. The distortion magnitude and direction depend on the incident angle of the Earth magnetic field on the material. Hence, it varies with the magnetometer orientation.

Soft Iron could be also compensated.