SkillAgentSearch skills...

USFSMAX

Example host MCU sketch to demonstrate use of the USFSMAX coprocessor

Install / Use

/learn @gregtomasch/USFSMAX

README

USFSMAX AHRS Motion Coprocessor

Introduction

Tlera Corporation offers a popular set of attitude and heading reference system (AHRS) boards known as the "Ultimate Sensor Fusion Solution" or USFS. The heart of the USFS is EM Microelectronic's EM7180 "Sentral" sensor fusion coprocessor, which uses PNICorp's “SpacePoint<sup>TM</sup> adaptive fusion algorithm. With proper sensor calibration, the USFS can readily provide heading accuracy of ~2deg RMS or better.

Many customers have found the USFS to be a good solution for their applications. However, there are two fundamental limitations to the Sentral sensor fusion solution:

  • The ~2deg RMS residual heading error level is dominated by uncorrected (sinusoidal) systematic sensor errors
  • The SpacePoint adaptive algorithm is "Always on". In the case of external magnetic interference, the algorithm can adapt to local corruption of the geomagnetic field... Potentially giving bad heading results that can persist for several minutes after the magnetic interference has been resolved

Closer examination of the Sentral's residual heading error showed it to be remarkably stable as well as systematic. These facts convinced me that an improved sensor calibration method and user control over any adaptive elements in the fusion algorithm would be key areas to improve beyond the ~2deg RMS heading error level provided by the Sentral.

These were the primary motivating factors behind development of the "USFSMAX" motion coprocessor, documented in detail on hackaday.io. The actual coprocessor is Maxim Integrated's MAX32660 Cortex M4F microcontroller. The MAX32660 is paired with ST Micro's LSM6DSM accel/gyro, LIS2MDL magnetometer and LPS22HB barometer all of which are "Best in breed" contenders among the various MEMS sensors currently available.

alt text

The USFSMAX hardware is an excellent platform for enhanced sensor calibration and fusion algorithm development:

  • Lots of horsepower - 96MHz Cortex M4F CPU
  • Lots of memory - 256KB flash, 96KB SRAM
  • High-quality, stable MEMS sensors
  • 1MHz asynchronous I2C slave bus for fast data transfer to the host MCU

USFSMAX Performance

Over the period of about two years, I have made a great deal of progress in terms of both the fusion and sensor calibration methods. These advances have been incorporated into the USFSMAX motion coprocessor hardware to provide results that are significantly better than those from the Sentral. Calibration and characterization of the first four prototype USFSMAX units showed RMS heading error ranging between 0.25 and 0.35deg.

alt text

Furthermore, the sinusoidal character of the heading error has been largely eiminated, indicating that the vast majority of systematic sensor errors have been effectively corrected. This level of accuracy can be enabling for many user applications in a smaller form factor and at a fraction of the price of other AHRS solutions.

But perhaps the most important advance is in the area of improved practical performance. Typically, the sensors can be well-calibrated after bench procedures conducted under controlled conditions... But the actual practical performance degrades during real-world usage out in the field. After extensive testing and observation it became clear that degraded heading accuracy is almost entirely driven by residual "Hard iron" effects. I have developed an in-situ dynamic hard iron (DHI) corrector that is capable of measuring and subtracting any hard-iron-like magnetic interference once the USFSMAX has been installed in a test object for use. To demonstrate the DHI corrector's efficacy, a small rare-earth magnet was attached to the USFSMAX's test fixture after the bench calibration was done. The DHI corrector was reset and "Taught" by tumbling the USFSMAX in 3-D. The results show that with the rare earth magnet attached the heading is unusable (RMS heading error 99.4deg) and that the DHI corrector recovered the heading accuracy back to the same level observed immediately after the bench calibration procedure (RMS heading error 0.18deg).

at text

Dynamic Hard Iron (DHI) Corrector

Note: DO NOT enable the DHI until you are ready to train the corrector under the method and controlled conditions described below. Enabling the DHI without following the proper training procedure can result in unstable output data rates and erroneous heading results. The DHI corrector programmed into the USFSMAX's firmware is adaptive, similar in nature of the Sentral's SpacePoint<sup>TM</sup> algorithm but with some key differences:

  1. The DHI corrector can be enabled or disabled at startup by user command from the host MCU
  2. If there is a valid DHI correction in the USFSMAX's EEPROM, it is loaded and used at startup if the DHI corrector is enabled
  3. The DHI corrector starts collecting data at startup/reset only when there is no valid DHI correction in the EEPROM and then stops once the new hard iron correction estimate is complete. It is *necessary to reset the DHI corrector from the host MCU (clearing the DHI corrector's training data buffer) and consciously train the DHI corrector under known/controlled conditions
  4. The new DHI correction estimate is automatically stored in the USFSMAX's EEPROM upon completion
  5. The DHI corrector can be reset at any time by user command from the host MCU. Once reset, any hard iron correction estimate in the EEPROM is invalidated and data collection for a new correction estimate begins
  6. When the new hard iron correction estimate is complete, a quality figure-of-merit for the estimate is available as well. The user can then choose to let the estimate stand or reset the corrector and try again

So, the user can decide when to use the DHI corrector and the timespan over which the correction data set is collected is limited. If the user decides the hard iron correction estimate has become stale, the corrector can be reset at will to begin a new estimate. If transient magnetic interference is not a large issue, the USFSMAX will rely on the last saved hard iron correction estimate until a new one is generated. The quality of the latest correction estimate is judged by the R-squared metric. When the variation in the magnetic data set NOT explained by the hard iron correction estimate tends to zero, R-squared tends to 1.0. For the moment it is up to the user to interpret the R-squared value and either accept the hard iron correction estimate or reject it and reset the corrector.

As a final matter, there are actually two versions of the DHI corrector: 3-D and 2-D. They are both capable of yielding excellent hard iron correction estimates but both are included for different use cases of the USFSMAX. Simply stated, if the test object to which the USFSMAX is attached is small/light and can easily be tumbled in 3-Space, the 3-D corrector is the best choice. If the test object is unwieldy or its motion is largely constrained to the X-Y (horizontal) plane the 2-D corrector is a better choice. Both correctors collect 150 data points at enforced separation before calculating the final correction estimate. When the estimate is complete, the hard iron corrector status bit in the calibration status register toggles true and the R-squared value populates the appropriate data registers. The desired corrector can be chosen at startup by user command from the host MCU. To get the best hard iron correction estimate:

  • 3-D corrector: Tumble the USFSMAX (attached to the test object) in 3-Space trying to sample all possible orientations. The intent is to randomly collect training data that uniformly covers the response surface of the magnetometer triple. In a good magnetic environment (no significant stray fields) the 3-D corrector should complete the new hard iron estimate in ~60 - 90s of random rotation. If done properly, R-square >= 0.95 is quite normal
  • 2-D corrector: Rotate the USFSMAX (attached to the test object) in the X-Y (horizontal) plane. Better hard iron correction estimates are obtained when the USFSMAX is within +/- ~5deg of level during horizontal rotation. In a good magnetic environment (no significant stray fields) the 2-D corrector should complete the new hard iron estimate in ~15 - 20 rotations in th

Related Skills

View on GitHub
GitHub Stars17
CategoryDevelopment
Updated22d ago
Forks2

Languages

C++

Security Score

80/100

Audited on Mar 7, 2026

No findings