ecompass rollover from +180 to -180

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ecompass rollover from +180 to -180

1,190 Views
lucasbaer
Contributor I

Hello All,

I am working with the Sensor Fusion ecompass software with an FRDM-K22F + FRDM-STBC-AGM01 demo board combo.

My question is this:

The range of compass angles output is -180 to +180. When looking at the Compass Angle output in a putty window everything looks good except when the angle approaches and passes 180. Instead of transitioning smoothly like 177,178,179,180,-179,-178,-177 the device does a complete rollover. It gets to about 178 then begins to drop in 10 degree increments until it wraps back to -180. Like this:

175

176

177

160

150

140

...

...

10

0

-10

-20

...

...

-160

-170

-175

-176

-177

It takes about 50 readings for the compass angle to wrap around to the correct negative value. Hopefully this explanation is clear. I have multiple excel data dumps explicitly profiling the event, but I doubt that level of detail is necessary to debug this. This event occurs when transitioning from positive to negative as well as from negative to positive.

Is anybody else seeing this? I'm using freescale hardware and the sensor fusion library and haven't edited the code in any way regarding the readings. Everything is factory stock hardware and software. This rollover event is a real killer as anytime the ecompass is in the  +/-3 degree range of 180 the reading is invalid.

If this has been answered somewhere else please point me there and sorry for the redundancy!

Thanks!

Labels (1)
0 Kudos
5 Replies

644 Views
lucasbaer
Contributor I

Hi Mike,

Thanks for your support. I'm glad there is new, much improved code.

I probably should have prefaced this post with the fact that I am a complete neophyte to the world of kinetis, sensor fusion, KDS, etc. (Now Coldfire V1 + Codewarrior + Processor Expert? That's another story - domination!)

My belief is that the workflow is:

Navigate to Welcome to MCUXpresso | MCUXpresso Config Tools

Create an SDK, download and unzip it

Open KDS -> File -> New -> Kinetis SDK 2.x Project 

Point to recently unzipped SDK

Select the specific project you want from the dropdown

I believe I have accomplished this. When I do so I'm presented with the following menus:

pastedImage_1.png

Is this what you were referring to when you recommended the following:

Try the application under SDK_2.1_FRDM-K22F/boards/frdmk22f_agm01/issdk_examples/algorithms/sensorfusion

If not, where is the recommended application?

I have indeed downloaded the Sensor Fusion Toolkit.

Thanks!

0 Kudos

644 Views
michaelestanley
NXP Employee
NXP Employee

Lucas,

Either of the 1st two listed will work.  algorithms/sensorfusion/baremetal_agm01 does not require an RTOS.  The freertos_agm01 version is based on FreeRTOS.  Just open them up, compile and download to your board.  Then fire up the Sensor Fusion Toolbox and click the AutoDetect button.

I also HIGHLY recommend you read the documentation for the sensor fusion kit.  It's in <sdk_root>/middleware/issdk_1.1/algorithms/sensorfusion/docs.  Start with the datasheet (NSFK_DS.pdf) and then move on to the user guide (NSFK_Prod_UG.pdf).

Regards,

Mike

0 Kudos

644 Views
lucasbaer
Contributor I

Hi Mike,

Thanks for the prompt reply.

Here is the workflow I followed:

I went to: Welcome to MCUXpresso | MCUXpresso Config Tools and created an SDK for my hardware platform (FRDM-K22F-AGM01). 

Download SDK

Unzip SDK

Open Kinetis Design Studio

File->New->Kinetis SDK 2.x Project

Navigate to the SDK downloaded from the link listed above

Name Project, Hit Next

Go through nested menus as follows: Boards->FRDM-K22F board->Examples->demo_apps->ecompass

Here is a picture:

pastedImage_2.png

Click Finish

From here I have a full source code project I can work with in Kinetis Design Studio. This project builds fine and I have edited it successfully, adding some debug statements, button pushes, etc. I have not touched any of the ecompass code. The fact that I am able to build, load and debug the program on the target hardware makes me feel like I didn't miss any check boxes or fat finger something anywhere in the download process. As far as the project goes the magnetic calibration is built in, and once complete the program repeatedly prints the ecompass reading over a COM port to a putty window.

Here is a copy of the readme.txt file that is included with the project:

Overview
========
The E-Compass demo application demonstrates the use of the FXOS8700 sensor. The tilt-compensated algorithm calculates
all three angles (pitch, roll, and yaw or compass heading).

Toolchain supported
===================
- IAR embedded Workbench 7.70.1
- Keil MDK 5.20
- GCC ARM Embedded 2015-4.9-q3
- Kinetis Development Studio IDE 3.2.0
- Atollic TrueSTUDIO 5.5.2

Hardware requirements
=====================
- Mini/micro USB cable
- FRDMK22F board
- Personal Computer

Board settings
==============
No special settings are required.

Prepare the Demo
================
1. Connect a USB cable between the host PC and the OpenSDA USB port on the target board.
2. Open a serial terminal with the following settings:
- 115200 baud rate
- 8 data bits
- No parity
- One stop bit
- No flow control
3. Download the program to the target board.
4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo
================
When the demo runs successfully, you can see the information below printed to the terminal.

Note: you must rotate the board 360 degrees to get the max / min value of the magnetic field.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To calibrate Magnetometer, roll the board on all orientations to get max and min values
Press any key to start calibrating...

Calibrating magnetometer...
Calibrate magnetometer successfully!
Magnetometer offset Mx: 313 - My: 432 - Mz: 494
Compass Angle: xxxx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Customization options
=====================

Hopefully this is enough info to figure out what I'm working with. This ecompass output of this project definitely is ranged from -180 to +180. 

Thanks!

0 Kudos

644 Views
michaelestanley
NXP Employee
NXP Employee

Thanks Lucas, I found it.  This example was up to date maybe 8 years ago, but we've gotten much better since.  I need to see if I can get this one removed from the SDK.  It is not based on the sensor fusion library, and a quick inspection of the code shows it's offers only a 1st order hard iron computation.  I suggest you switch to the examples I pointed you to above.  They provide not only basic eCompass, but a full 9-axis version that is far superior.

Mike

0 Kudos

644 Views
michaelestanley
NXP Employee
NXP Employee

Lucas,

There have been multiple eCompass applications built over the years, by different individuals/businesses within NXP.

Can you tell me exactly which software release you are using and the URL you got it from?

I ask because the current sensor fusion release (7.1) has a 0 to 360 compass heading range.  There's no rollover at 180 degrees. it happens at 0/360.  We rolled the magnetic calibration software into the sensor fusion builds several years back.  Is it possible you have an older release of just the eCompass software or a standalone project that is not part of the standard NXP sensor fusion release?

The other reason I suspect a different application is that the standard sensor fusion kit has a binary interface back to the sensor fusion toolbox.  There's no way you could easily decipher it in putty.  

The MCUXpresso SDK builder at Welcome to MCUXpresso | MCUXpresso Config Tools  can be used to build a K22F SDK.  Make sure you select the ISSDK and FreeRTOS options.  Try the application under SDK_2.1_FRDM-K22F/boards/frdmk22f_agm01/issdk_examples/algorithms/sensorfusion.  You will also need the Sensor Fusion Toolkit, which can be downloaded from nxp.com/sensorfusion.

Please let me know if that helps.

Mike

0 Kudos