Skip to main content
Visitor II
October 15, 2021
Question

Question about MotionFX error in 9-axis

  • October 15, 2021
  • 5 replies
  • 6315 views

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

    This topic has been closed for replies.

    5 replies

    ST Employee
    October 18, 2021

    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?

    MPoul.2Author
    Visitor II
    October 18, 2021

    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.

    ST Employee
    October 18, 2021

    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.

    ST Employee
    October 25, 2021

    Hello Matthieu,

    would you please send me the last two files (calibrated/uncalibrated) as source file (excel) so I can plot the data in different way?

    MPoul.2Author
    Visitor II
    October 27, 2021

    Hi Miroslav

    After trying to go back to the example, it seems that the example code works well with the angle returned (and it is well calibrated). So i would like to modify this example in order to add our previous functions.

    As we need SPI, I would like to add an interupt based SPI, in order to not break what is currently working with the motionFX example, however i can't find any ST example with it... Would you know where i could find one?

    I also need to save the calibration and reuse it. I found MotionFX_LoadMagCalFromNVM(,,) and save functions in the manager, however i don't know if i should modify those in order to have a clean code. In our previous project i was saving the values in the flash memory and i was directly reusing it without going through magCalibration functions.

    Also, as the examples are included in a very large package, i would like to extract the project from it, Is this possible?

    Thank you very much and sorry for the inconvenience.

    ST Employee
    October 27, 2021

    Hi Matthieu,

    concerning the examples for MotionFX and SPI communication with sensors, there is no simple example.

    There is firmware for SensorTile.box which use MotionFX and SPI communication with sensors, your can find it here, but maybe it will be difficult to read.

    You can also use STM32CubeMX ad X-CUBE-MEMS1 and generate the DatalogFusion for CUSTOM board, in this case you can select the sensors and the communication interface I2C/SPI. If you install additional package X-CUBE-MEMS1 into the STM32CubeMX you should see also User Manual which describes how to generate example applications.

    You could also modify the example which you already have from I2C to SPI, I think it is not so difficult.

    Concerning saving the calibration values, you can implement it by yourself. Save calibration values to a memory when you are satisfied with the cal. values and load and use them at the next start until you run the calibration algorithm again and you get new values.

    Or you can implement the MotionFX_LoadMagCalFromNVM/MotionFX_SaveMagCalFromNVM, you can modify these function in order to save and load the values to a memory you want to use. Load function is automatically called when the calibration is enables and save function is called when the algorithm is disables.

    If you want to reduce the size of the package, it is possible to delete drivers (sensors, STM32 HAL, BSP) which you don't use, all middleware except MotionFX you use and also all examples and application except DatalogFusion. If you would generate the application using STM32CubeMX it will generate project with only files which are needed.

    ST Employee
    November 24, 2021

    Hello,

    here is response from my colleague who is expert on sensor fusion:

    At the start of the MotionFX, heading is initialized with zero degree and will initial the heading value using magnetometer value only when there is a motion.

    This is done to make sure magnetometer is calibrated and it can be determined only when there is some rotation. Therefore, the customer is seeing 0 at the beginning but after rotation, it converges to 217 deg.

    When I compare the rotation from mag and gyro : Here is the value I am getting

    Heading from Magnetometer : [-97 (313->216), 95, 95, -95, -95]

    Heading from Gyro integration : [-87,90, 90, -88, -88]

    0693W00000GYgVSQA1.png 

    The differences in both sensors show some calibration issue with magnetometer but it is acceptable. As MotionFX get more data, it tends to handle the error better due to better observation of error.

    MPoul.2Author
    Visitor II
    December 3, 2021

    Hi Miroslav thank you for your answer.

    I understand that the calibration is important in the final result, but i still can't figure how with the same program we can observe such a difference between our board and the ST Nucleo board. I tried to use the registers from the gyroscope to enable its low pass filter, and it seemed to increase the accuracy in the gyroscope integrated angle values. However we still obtains errors of about 7 degrees on the origin point (yaw calculated from MotionFX)

    After your message i also tried to get a better calibration, which i did, but even then then the result didn't improve.

    [edit] Actually it seems we do have the same behaviour with the STM32 unicleo borad, but the gap between values seems to be a bit smaller. This gap is about 3 to 4° while it can go up du 7° with our board depending on the config parameters and the registers values.

    ST Employee
    December 7, 2021

    Hello,

    The different behavior between Nucleo and custom platform can be due to soft iron distortion of magnetometer. We can validate if soft iron distortion needs correction if you provide us 3D motion data.

    Here is the process:

    1. Data should be collected in a magnetic interference-free environment such as Park /Garden where no ferromagnetic (iron pipes, current carrying wires) material is present. Please make sure Laptop/mobile devices are not close to the subjected device during the test.
    2. During data collection please make sure components such as Wireless antenna (Wi-Fi, GPS, NFC) etc. should be off. Any scanning will cause short and long term shift in the magnetic field.
    3. ODR: raw (uncalibrated) magnetic data at 50 or higher Hz

    Data should be collected as follows.

    1. Place the device on the flat surface and slowly rotate the device by 360 degrees two times.
    2. Flip the device and follow the step 1
    3. Rotate the device in the vertical plane (About X and Y both).
    4. Perform 8 pattern rotation 2 times slowly .

    MPoul.2Author
    Visitor II
    December 20, 2021

    Hi Miroslav,

    Thank you for your help. You will find attached a .rar file containing both .csv and .xlsx files from the log function of the Unicleo Gui.

    I've done 2 measurements for the unicleo as i did too many 8 figures, but the 2nd measurement seems a bit off so maybe we can just crop the 1st measurement data.

    I also found that our board results seem better than the nucleo board with the ATime Mtime and Fr time used for those measurements (2.5, 3.5 and 4.5)

    However, on Nucleo Board, better results were achieved with the following values : a2.5, m2.5, fr10

    The magnetometer ODR was 100Hz.

    Also the movements were "handmade" so the values may also be a bit off.

    ST Employee
    January 6, 2022

    Hello,

    I'm sorry for late reply, I was on vacation.

    From the datalog we have calculated SI matrix:

       0.9731   0.0103   0.0011

       0.0103   1.0344  -0.0130

       0.0011  -0.0130   1.0256

    You can multiply this matrix on uncalibrated data directly before sending it to MotionFX/MotionMC library to reduce SI error.

    Example :

    Xnew = 0.9731*X_raw + 0.0103*Y_raw + 0.0011*Z_raw

    Please note the SI matrix is computed on the data logged and if there is some transformation performed (after motionFX call) then appropriate transformation will be needed before applying the SI matrix.