Fast reading of current heading for compass app

Hello,

is there any way how to create a compass app with smooth graphics?  It seems that Sensor.getInfo() takes about 90ms so it's slow for this purpose. Callbacks from internal sensors are limited as per the documentation to 1s period. Is there some workaround or other option how to achieve fast data reading without blocking the display update function?

Thanks,

Vlastik

  • Set up a timer and read the heading from the sensor and store the last N values in a circular array and use it to smooth it out, and read the stored value in no time as needed

  • Thanks for the reply. But I'm not sure if I got the point. In this case the execution flow will stuck in the timer callback function for 90ms. 

  • How often you refresh the screen today? How often you calculate changes? How long all this cycle (calculation + drawing) takes now? If it's more than 900ms/s then you have a bigger problem than waiting for 90ms once in a while.

  • Understand there are actually two different ways heading is determined, and "best source" is used.  if you are standing still or moving less than a few miles and hour, the compass is used, but if the activity used GPS, heading is based on changes to GPS location.  So if your arm is hanging to your side and you are walking/running/hiking, you not actually see the compass but what's reflected with GPS

  • I wanted 20fps to achieve relatively smooth experience. The native ABC app on Fenix 8 has I think even higher frame rate and it looks great. 20fps means 50ms for whole cycle. I did some profiling and calculation + drawing takes less than 10ms. So the issue is really that Sensor.getInfo() is blocking and takes about 90ms.     

  • I'm not sure why 10fps isn't enough, but if this is so important you can still read it every 100ms but draw "it" every 50ms. You will need to use the last 2 readings and use that to "predict" which direction and how fast to rotate. It could even be made to mimic a traditional compass with fluid in it that always has some lag in the rotation because of the surface tension(?) / viscosity of the fluid

  • Understand there are actually two different ways heading is determined, and "best source" is used.  if you are standing still or moving less than a few miles and hour, the compass is used, but if the activity used GPS, heading is based on changes to GPS location.  So if your arm is hanging to your side and you are walking/running/hiking, you not actually see the compass but what's reflected with GPS

    According to docs, what you said is definitely true about ActivityInfo.track and Position.Info.heading. For those fields, the docs explicitly say that the direction of travel (i.e. as determined by GPS) will used when you are moving, otherwise the compass will be used (if present). e.g. Position.Info.heading:

    The true north referenced heading in radians.

    This provides the direction of travel when moving. If supported by the device, it provides compass orientation when stopped.


    The docs for ActivityInfo.track and Sensor.Info.heading say this:

    The true north referenced heading in radians.

    This provides compass orientation if it is supported by the device.


    It says nothing about GPS or direction of travel when moving. Ofc, that doesn't 100% guarantee that only the compass is used. The docs could be incorrect, incomplete, or out of date. But there must be a reason that some docs mention "direction of travel when moving" while others don't. It seems intentional.

    OP is referencing Sensor.getInfo(), which means they must be reading Sensor.Info.heading.

    Does Sensor.Info.heading ever use GPS? If so, then I think the docs should be updated.

    It was my previous rough understanding that Sensor.Info.heading would only use the compass (if present). (I don't have a lot of experience with the various CIQ heading/track fields, so I'm not sure.)

  • I know there has been a lot of discussion about this stuff in the forums in the past, but I'm not sure if it definitively answers my question.

    There has def been confusion about this in the past:

    [https://forums.garmin.com/developer/connect-iq/f/discussion/2571/position---info---heading/20184#20184]

    I am not 100% certain, but I think the heading that is provided from the sensor module will give compass heading even while moving.


    That's what I expected but when I tested my App while driving a car, the compass heading was not different to the position heading.
    Anyway, I will check my source code and test again.