<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problem with Drift in Orientation with SensorFusion 7.0 in Sensors</title>
    <link>https://community.nxp.com/t5/Sensors/Problem-with-Drift-in-Orientation-with-SensorFusion-7-0/m-p/615795#M3772</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jonathan,&lt;/P&gt;&lt;P&gt;We don't normally offer support for ports on competitive parts (Invensense is NXP's competition), but I'll try to answer a few of your questions (and others are welcome to jump in with additional suggestions). &amp;nbsp;In order:&lt;/P&gt;&lt;P&gt;1. &amp;nbsp;Section 5.3 of the user guide discusses hardware abstraction issues.&lt;/P&gt;&lt;P&gt;2. The Kalman filter includes gyro offsets as 3 of the variables (XY&amp;amp;Z) it tracks. &amp;nbsp;So long as your device has some rotation, it will continuously update those estimates. &amp;nbsp;The magnetometer and gyro reference vectors should keep things stable when the device is at rest.&lt;/P&gt;&lt;P&gt;3. Sorry, I can't offer code reviews.&lt;/P&gt;&lt;P&gt;4. Proper magnetic calibration is very important. &amp;nbsp;Don't expect good 9-axis results without it. &amp;nbsp;The routines we include generally do a pretty good job handling hard/soft iron sources that are fixed spatially with respect to the sensor. &amp;nbsp;We include some code to handle general interference, although there are limitations to just how well that can be done.&lt;/P&gt;&lt;P&gt;5. If you check the code comments, you will see that&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&amp;nbsp;iFirstAccelMagLock is just a boolean variable used to ensure that some initialization code runs only once. &amp;nbsp;Don't infer any general health from it's status.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;6. I see no problem with the approach you outline so long as your MCU has enough MIPS to keep up.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;7. Read the manual. &amp;nbsp;I tried to put as much "collective wisdom" there as I possibly could.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Mike&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Apr 2017 18:32:42 GMT</pubDate>
    <dc:creator>michaelestanley</dc:creator>
    <dc:date>2017-04-21T18:32:42Z</dc:date>
    <item>
      <title>Problem with Drift in Orientation with SensorFusion 7.0</title>
      <link>https://community.nxp.com/t5/Sensors/Problem-with-Drift-in-Orientation-with-SensorFusion-7-0/m-p/615794#M3771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am developing an application that uses &amp;nbsp;a 9-DOF MEMS navigation device (&lt;STRONG&gt;InvenSense MPU-9250&lt;/STRONG&gt;, hopefully containing NXP parts??) to provide real-time orientation on custom designed hardware, software and drivers. Since everything is custom, I had to strip down the SensorFusion 7.0 library to the core routines provided in the SDK. In addition, I call the initialization functions directly and wrote my own function to load the data into a 1 element FIFO for gyro, magnetometer and accelerometer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The axes of the MPU-9250 are defined as shown in the image below. Therefore, I rotate the magnetometer axes to make it the same as for the gyro and accelerometer. I do this by negating the Z-axis and swapping X and Y axes.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="mpu9250-axes.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/6778i906D42CED80480AA/image-size/large?v=v2&amp;amp;px=999" role="button" title="mpu9250-axes.png" alt="mpu9250-axes.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have also checked to confirm that the units are correct (acceleration in g, rotational velocity in degrees/s, and magnetometer in micro Teslas). I set the conversion factors for "counts per unit" and "units per count" for integer and floats appropriately (or so I believe).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am running the&amp;nbsp;&lt;STRONG&gt;fRun_9DOF_GBY_KALMAN&lt;/STRONG&gt; algorithm at 200 Hz and loading new data/samples into my 1 element FIFO also at 200 Hz for all 9 axes. I find that after moving the device around a bit, the&amp;nbsp;&lt;SPAN style="color: #24292e; background-color: #ffffff;"&gt;&lt;STRONG&gt;iFirstAccelMagLock&lt;/STRONG&gt; flag will switch from 0 to 1 (which would seem to be a good sign).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #24292e; background-color: #ffffff;"&gt;However, I am finding that the various angular outputs of the Kalman filter, which are&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;fPhiPl; ///&amp;lt; roll (deg)&lt;/LI&gt;&lt;LI&gt;fThePl; ///&amp;lt; pitch (deg)&lt;/LI&gt;&lt;LI&gt;fPsiPl; ///&amp;lt; yaw (deg)&lt;/LI&gt;&lt;LI&gt;fRhoPl; ///&amp;lt; compass (deg)&lt;/LI&gt;&lt;LI&gt;fChiPl; ///&amp;lt; tilt from vertical (deg)&lt;/LI&gt;&lt;LI&gt;fDeltaPl; ///&amp;lt; a posteriori inclination angle from Kalman filter (deg)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; color: #24292e;"&gt;&lt;STRONG&gt;seem to be drifting in space and not responding to actual rotation of the device. &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried measuring the DC offset of my gyro with long term averaging at rest. It is about 0.5 deg/s, which I subtract out, but this drift and lack of response persists.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thus, I have the following &lt;SPAN style="color: #ff0000;"&gt;questions&lt;/SPAN&gt; regarding the usage of the SensorFusion 7.0 library:&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Where is it specified exactly what the expected input axes and units are for all 9 degrees of freedom, including rotational direction for the gyro? I assume that X, Y and Z axes should all be consistent for gyro, mag and accel, and that the right hand rule should be satisfied for the gyro rotational direction. But again, is this documented precisely somewhere?&lt;/LI&gt;&lt;LI&gt;How sensitive is the algorithm to gryo DC offset / drift? Do I need to zero this out precisely for my hardware?&lt;/LI&gt;&lt;LI&gt;Am I missing any&amp;nbsp;calibration routines in my main loop?&lt;/LI&gt;&lt;LI&gt;How sensitive is SensorFusion (fRun_9DOF_GBY_KALMAN) to the calibration of the magnetometer? I noticed my magnetometer seems to be off by a factor of 10x, and its near a lot of metal, so I don't know if the field components (X,Y,Z)&amp;nbsp;are also off. Should I expect the algorithm to not operate properly unless the magnetometer reading and field distortion is minimal? I saw some hard/soft iron and calibration routines in the code, so I'm wondering how good of a job these do for compensation for an uncalibrated magnetometer.&lt;/LI&gt;&lt;LI&gt;What does it mean when&amp;nbsp;iFirstAccelMagLock = 1? Does this mean that SensorFusion believes my magnetometer and gyro data is working correctly together, or could&amp;nbsp;&lt;SPAN&gt;iFirstAccelMagLock = 1 even if the gyro and magnetometer data is screwed up somehow. In other words, how reliable an indication of proper operation is this variable?&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;I am sampling my 9-DOF device at 200 Hz and loading data at 200 Hz into SensorFusion with a 1 element FIFO. The analog bandwidth of my samples is around 50 or 100 Hz (I can configure this). I am reading the output of &lt;SPAN style="color: #24292e; background-color: #ffffff;"&gt;SV_9DOF_GBY_KALMAN&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;also at 200 Hz. Are there any problems with this approach?&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Any other pointers you can share with me to get this working properly?&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Feb 2026 21:01:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Sensors/Problem-with-Drift-in-Orientation-with-SensorFusion-7-0/m-p/615794#M3771</guid>
      <dc:creator>joncox</dc:creator>
      <dc:date>2026-02-03T21:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Drift in Orientation with SensorFusion 7.0</title>
      <link>https://community.nxp.com/t5/Sensors/Problem-with-Drift-in-Orientation-with-SensorFusion-7-0/m-p/615795#M3772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jonathan,&lt;/P&gt;&lt;P&gt;We don't normally offer support for ports on competitive parts (Invensense is NXP's competition), but I'll try to answer a few of your questions (and others are welcome to jump in with additional suggestions). &amp;nbsp;In order:&lt;/P&gt;&lt;P&gt;1. &amp;nbsp;Section 5.3 of the user guide discusses hardware abstraction issues.&lt;/P&gt;&lt;P&gt;2. The Kalman filter includes gyro offsets as 3 of the variables (XY&amp;amp;Z) it tracks. &amp;nbsp;So long as your device has some rotation, it will continuously update those estimates. &amp;nbsp;The magnetometer and gyro reference vectors should keep things stable when the device is at rest.&lt;/P&gt;&lt;P&gt;3. Sorry, I can't offer code reviews.&lt;/P&gt;&lt;P&gt;4. Proper magnetic calibration is very important. &amp;nbsp;Don't expect good 9-axis results without it. &amp;nbsp;The routines we include generally do a pretty good job handling hard/soft iron sources that are fixed spatially with respect to the sensor. &amp;nbsp;We include some code to handle general interference, although there are limitations to just how well that can be done.&lt;/P&gt;&lt;P&gt;5. If you check the code comments, you will see that&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&amp;nbsp;iFirstAccelMagLock is just a boolean variable used to ensure that some initialization code runs only once. &amp;nbsp;Don't infer any general health from it's status.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;6. I see no problem with the approach you outline so long as your MCU has enough MIPS to keep up.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;7. Read the manual. &amp;nbsp;I tried to put as much "collective wisdom" there as I possibly could.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Mike&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Apr 2017 18:32:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Sensors/Problem-with-Drift-in-Orientation-with-SensorFusion-7-0/m-p/615795#M3772</guid>
      <dc:creator>michaelestanley</dc:creator>
      <dc:date>2017-04-21T18:32:42Z</dc:date>
    </item>
  </channel>
</rss>

