Thingy 52: raw magnetometer data

I recently purchased a Thingy 52 with the goal of processing the the raw magnetometer, accelerometer and gyroscope data using a sensor fusion algorithm to determine orientation.  One of my first goals is to determine the hard-iron offsets for the magnetometer data.  I've spent a decent amount of time processing the raw magnetometer data and it appears the MPU9250 inside the Thingy 52 is doing some sort of magnetometer calibration. This is not unexpected as there is a "Magnetometer compensation interval" configuration available as part of the Thingy motion service but I didn't think the MPU9250 magnetometer calibration would be applied to the raw magnetometer data which is available to read off the Thingy 52. Can anyone confirm if this is the case and whether or not there is a way to disable this feature so I can perform the magnetometer calibration myself.

  • Hi Peter,

    The "raw data characteristics" generally refers to raw data which is not calibrated in any way. As for the "compass compensation interval" mentioned in the product specification, I guess this is a feature of the sensor and is only relevant if you do compass functionality.

    Kind Regards,

    Priyanka

  • Hi Priyanka, 

    Thank you for the response.  

    My testing suggests the raw magnetometer data made available through the Thingy 52’s BLE Service → Motion service → Raw data characteristic (see Thingy configuration service) is actually the calibrated magnetometer data.  

    I’ve attached a figure showing the magnetometer data read off the Thingy 52 using the above-referenced “Raw data characteristic”.  For this dataset I set the magnetometer compensation interval to 500ms and the motion processing unit frequency to 10Hz and then start sending read requests to the Thingy 52 over the BLE link using Matlab’s ble service. The rate at which I can read the data is approximately 10Hz but most of the time the magnetometer values for the x, y and z directions is [0,0,0].  I have an if statement in my code which only saves the magnetometer values when the x, y and z values are not all zeros.  That’s what is plotted in the attached figure.  In addition, while reading the magnetometer data off the Thingy 52 I rotate the Thingy 52 around the x, y and z axes at 10 second intervals.  That is, for the first 10 seconds I rotate the Thingy 52 around its x axis, from 10 seconds to 20 seconds I rotate the Thingy 52 around its y axis, from 20 seconds to 30 seconds I rotate the Thingy 52 around its z axis.  I then repeat the process for time 30s to 60s. 

    What you’ll notice is that at time 28 seconds all three magnetometer values abruptly change.  I’ve done this experiment many times and I consistently see this behavior.  In addition, my calculations reveal the data before 28 seconds is uncalibrated and the data after 28 seconds is the magnetometer data with hard-iron offset (biases) removed.

    Another experiment I’ve done is to set the magnetometer compensation interval to 500ms and the motion processing unit frequency to 10Hz and then spin the magnetometer around its x axis for 60 seconds.  In this case, the abrupt change never occurs.   

    My working theory is the following:

    1. By setting the magnetometer compensation interval and/or setting the motion processing unit frequency, I’ve reset some part of the MPU9250’s magnetometer calibration algorithm.
    2. By rotating the magnetometer around its x, y and z axis sequentially the MPU9250’s internal magnetometer calibration algorithm is able to collect the data it needs to perform calibration.
    3. At time 28 seconds the internal magnetic calibration algorithm is happy with what it has calculated and applies the results to the magnetometer data.

    Regards,

    Peter

  • Hi Peter,

    The MPU9250 motion sensor actually does do it's own calibration which is the factory calibration and I wouldn't suggest changing this. Because if this was not done, then you would get a lot of noise and the data that you obtain would be really distorted. The factory calibration is custom for every sensor.

    But, there are some internal compensations that are done and you could try changing the COMPASS_BIAS values mentioned in the FW. There is also another option of creating your own library  but that can be extremely complicated and I would suggest changing the COMPASS_BIAS values. 

    Peter Murphy said:
    By setting the magnetometer compensation interval and/or setting the motion processing unit frequency, I’ve reset some part of the MPU9250’s magnetometer calibration algorithm.

    I am not sure of this, but as mentioned earlier, the MPU9250 does have an internal calibration being done which has nothing to do with the Thingy FW. And, the values that you set are run-time so each time you boot, it starts with the values that you have given. 

    Also, I would like to mention that the MPU9250 is End Of Life and is not recommended for new designs. 

    Kind Regards,

    Priyanka

Related