Skip to content

Stationary Drift

Bjarne Hansen edited this page Nov 21, 2020 · 7 revisions

Stationary Response

History

Tests using version 4.2 of the fusion library showed intermittent drifting away from the known heading, even when the sensor is held stationary. It's believed this is caused by a change in the magnetic environment after calibration, such that the calibration is no longer correct. If/when the environment is restored, or the sensor recalibrated, the drifting ceases.

The following testing has been performed using version 7.2 of the fusion code. which includes run-time magnetic calibration. On startup, the code loads any existing calibration from non-volatile memory. Then periodically during operation, it compares the actual magnetometer readings to expected readings and recalculates new calibration coefficients. This should give it more immunity from changes in the magnetic environment.

Procedure

An ESP32 loaded with the current fusion code was streaming readings via WiFi to the NXP Sensor Fusion Toolbox software running on a laptop. The sensor system had previously been rotated in the location of the test, until the Toolbox reported completion of magnetic calibration. Accelerometer and gyroscope calibration had not been performed.

Several trials in which the sensor was held steady for several minutes were conducted. Data was logged by the Toolbox to a file, and the reported magnetic heading was later graphed.

Several trials longer than 9 hours were also conducted, with the heading recorded every 1.0 seconds. These tests took place in a household environment with no known disturbances (magnetic or mechanical) in the room, but the air temperature varied between approx 15 - 21 C (low at night, rising in the morning, high during the day, then falling in the evening).

Results

Short-term Variability

The reported heading varied by about +/- 1 degree over several minutes. A typical plot from one of the trials is shown below. Heading Drift while sensor stationary

Noise Level

Over the longer term, the reported heading varied by about +/- 3 degrees in 10 hours, with a standard deviation of 0.76 degrees. The distribution appears approximately Gaussian. It was speculated that changing the sensor reading method to collect more than 1 magnetometer reading per fusion cycle might decrease the variation in heading. However two subsequent tests showed no significant improvement in the distribution of the readings. See the following histogram showing the percentage of total readings deviating given amounts from the mean heading. One data set is for 10.5 hours at the normal data-collection method (5 accel, 5 gyro, and 1 magnetometer sample per fusion cycle), and the second data set was 9 hours collecting 5 samples each of accel, gyro, and magnetometer. There was no noticeable change in the variability, so it does not appear that magnetometer readings are currently the limiting factor in reading stability. Histogram comparing 1- and 5-sample magnetometer readings

Long-term Variability

As noted above, the long-term variability had a standard deviation of 0.76 degrees about the mean heading, however all three tests showed an initial period of about 20 - 40 minutes during which the heading rose by about 2 - 3 degrees. I speculate that the increase is related to the fusion algorithm refining its calibration (possibly gyroscope zero-point?), as all three trials commenced with a reboot of the processor. It is not likely due to the system thermally warming up (as during 2 of the trials it had been operating for several hours previous to the test start). Plots are shown below. Long-term Heading Drift while sensor stationary: 1-sample magnetometer Long-term Heading Drift while sensor stationary: 5-sample magnetometer Long-term Heading Drift while sensor stationary: 5-sample magnetometer, overnight trial

Discussion

Variability of about +/- 1 degree for the majority of readings seems acceptable. Allowing the sensor to operate for an hour seems to allow it to settle (though it is not yet known whether the settled reading is more accurate than the initial reading). Further improvements might be seen through calibrating the gyro and/or accelerometer. It does not appear that increasing the sampling rate on the magnetometer will improve the readings noticeably given the other current possible contributions to variability.

Further Work

  • Tests with calibrated gyro and/or magnetometer
  • Temperature variation tests (perhaps use built-in temp sensor in sensor IC)
  • Other starting bearings, like at 90 and 180 degrees from the above tests which were at approx 100 degrees magnetic.