Having problems getting current heading to work for datafield, especially on a device vs the simulator

I've read many of the discussions on here about issues with GPS or compass data and the various issues people have had however I've tried a variety of solutions and nothing seems to work well. I'm trying to navigate to a waypoint at fairly slow speeds (< 8 mph). I'm writing a datafield app and testing it using the SUP application.

On the simulator it works better than on my Vivoactive HR watch. However when running a FIT file that was recorded with the SUP app, there are many data points where the lat/lon does not change at all, which I guess is ok, but seems unusual since they were recorded using the SMART algorithm rather than at time intervals.

When testing on the watch I find these things to happen when accessing data inside the compute method:

  • Activitiy.info.currentHeading:
    • is sometimes a null
    • sometimes appears to be magnetic heading
    • sometimes just freezes and doesn't change
  • Activity.info.currentLocation:
    • often doesn't change
    • appears to be physically correct or at least mostly accurate

When trying to calculate the heading from lat/lon pairs and comparing it to currentHeading:

  • Often the previous lat/lon is the same as the current lat/lon and so the calculation is skipped
  • Sometimes only one of either lat or lon changes resulting often in a heading of 0 or 90 (or some orthogonal result) which is incorrect
  • When compared to the info.currentHeading value they can be radically different
  • Sometimes the computed values are way off from reality
  • sometimes the currentHeading is responsive and accurate and appears to be magnetic, other times it seems to just freeze up and do nothing

I understand the complexities of GPS and accuracy as I've worked on navigation software for these products in the past. However the results I'm getting pretty much makes it impossible to get good heading data. It's very strange because the bearing, distance, etc. are usually correct, however sometimes the calculation (on the watch, not the simulator) will get stuck with a bad heading and never update. I have to restart the app to get the values to start updating again.

The simulator and FIT files or simulated data seem to work much better for some reason.  I've been working on this for a while and I've triple checked all the methods against other programs and I've compared my code to what others in the garmin forums have posted.

I've basically just modified one of the Garmin examples for a datafield and inserted my navigation code into the compute() method and just directly draw to the screen and console on the simulator.  I understand there are some other navigation objects like Position.currentLocation, etc.  Could using the Activity.info be a bad idea because the application could be modifying or doing something to these values?

This problem is driving me crazy because the results on the watch seem so much more random than in the simulator which is just running the datafield portion and not the full SUP app.

Any ideas?

Thanks

Edit: Here's some of the past treads I've gone through for help:

https://forums.garmin.com/developer/connect-iq/f/discussion/5906/position-info-heading-vs-activity-info-heading-and-limitations

https://forums.garmin.com/developer/connect-iq/f/discussion/3914/heading-does-not-work-when-recording-activity

https://forums.garmin.com/developer/connect-iq/f/discussion/3428/info-currentheading-not-returning-same-info-as-heading-data-field

https://forums.garmin.com/developer/connect-iq/f/discussion/3794/playback-fit-file-in-simulator

  • After more experimenting, I've decided to ignore the currentHeading field as it freezes randomly and stops working. So there is either something going on in the SUP app or with how this value is generated.

    I've had to just go with computing the heading from changes in lat/lon and then performing a rolling average of angles using a unit circle technique to average the values.

    Does anyone have any insight into what's going on with currentHeading or how to use it properly?