Opened 3 years ago

Last modified 2 years ago

#1234 new enhancement/feature request

Android: enable magnetic compass

Reported by: jandegr Owned by: KaZeR
Priority: minor Milestone:
Component: core Version: git master
Severity: normal Keywords: patches android compass
Cc: http://wiki.navit-project.org/index.php/user:mvglasow, (2)

Description

Hi

I propose a patch for the Adroid port to enable the magnetic compass.

Usage : This is intended for profiles like bike, pedestrian, horse,... and rotates the map according to the magnetic bearing, even when standing still. In navit.xml set static_speed en static_distance to zero in the desired profile. The compass adapts to any device rotation (landscape, portrait) but if you hold it in a near vertical position the compass reading becomes inaccurate. I should apply another rotation for near vertical position, but left it for now.

Questions : This patch enables the magnetic compass allways and for every profile. Ideal would be if I could enable it based on the name of the vehicle_profile or even better based on an attribute in the vehicle_profile. How can I acces those profiles and their attributes from the Android layer ?

regards, Jan

Attachments (4)

AndroidCompasS.zip (5.5 KB) - added by jandegr 3 years ago.
AndroidCompass.zip (1.7 KB) - added by jandegr 3 years ago.
patch
AndroidCompass2.zip (2.2 KB) - added by jandegr 3 years ago.
version 2 of android magn. compass
AndroidCompass3.diff (7.0 KB) - added by jandegr 3 years ago.
third version of magnetic compass for Android Navit

Download all attachments as: .zip

Change History (10)

Changed 3 years ago by jandegr

Changed 3 years ago by jandegr

patch

Changed 3 years ago by jandegr

version 2 of android magn. compass

comment:1 Changed 3 years ago by jandegr

Hi, Untill someone (or myself) comes with a better solution, I made an entry in the Android popup menu (long tap) to toggle the magnetic compass on/off

attached version 2 patch

regards, Jan

comment:2 follow-up: Changed 3 years ago by mvglasow (2)

  • Cc http://wiki.navit-project.org/index.php/user:mvglasow (2) added

Suggestion: how about falling back to the magnetic compass when the vehicle is moving slowly? That is, either slower than the threshold in navit.xml, or when the distance between the last two waypoints divided by error exceeds a certain value.

comment:3 in reply to: ↑ 2 Changed 3 years ago by jandegr

Replying to http://wiki.navit-project.org/index.php/user:mvglasow (2):

Suggestion: how about falling back to the magnetic compass when the vehicle is moving slowly? That is, either slower than the threshold in navit.xml, or when the distance between the last two waypoints divided by error exceeds a certain value.

This would be an ideal solution, but only if it can be controlled from the vehicleprofile. I want it enabled when profile bike is active, but when stopping in front of the traffic lights with my car I don't want the map to realign with magnetic compass, but other users may want to configure it in another way. The implementation should differ from the one that we already have in the pedestrian plugin, in the way that the processing of the raw magn. and accelero values should be done in the android layer, as my patch already does. Then if other platforms would want to implement a magnetic compass as well, the core C code does not have to be changed each time. Unfortunatly my knowledge of the navit code is not enough yet to do it all on my own, but it is slowly growing........

comment:4 follow-up: Changed 3 years ago by mvglasow (2)

I agree that the vehicle code is best for handling the magnetic compass, as vehicle already incorporates the GPS code and is thus platform-specific anyway.

As for controlling compass use from vehicleprofile – fortunately, the static_speed and static_distance parameters (minimum speed and distance to previous position for Navit to process bearing from GPS) are vehicleprofile-specific, so it shouldn't be too difficult to add another parameter here.

However, I'd be interested to know why you don't want to fall back to the magnetic compass when stopping your car at a traffic light. Does that have to do with the reliability of the compass?

I know that the magnetic compass in a smartphone is not very reliable (I recently did a little experiment with a coworker in which we placed three phones on the table and compared compass readings, only to get three totally different ones.) GPS is reliable as long as the device is moving at a certain speed – in fact, even on a bike I find the GPS bearing is quite reliable as long as reception is good. It is only at walking speed that GPS bearing is of little use.

How about the following rudimentary calibration:

  • Whenever we get a reliable bearing from the GPS (i.e. speed and distance to previous point exceeds the configured thresholds), compare it to the magnetic compass and store the difference.
  • After a certain time without reliable bearing from GPS, use magnetic compass readings but apply the previously stored offset.
  • If we never got a reliable bearing from GPS, assume the offset to be zero, i.e. use magnetic compass readings without compensation. (In this case we essentially have no choice.)

As long as the compass does not spontaneously drift or oscillate (i.e. change its bearing even when the device is not moving), this should prevent the map from suddenly jumping to some random orientation when you stop at a traffic light. Also, if you turn on the spot, the map orientation should update accordingly.

Changed 3 years ago by jandegr

third version of magnetic compass for Android Navit

comment:5 in reply to: ↑ 4 Changed 3 years ago by jandegr

Replying to http://wiki.navit-project.org/index.php/user:mvglasow (2):

However, I'd be interested to know why you don't want to fall back to the magnetic compass when stopping your car at a traffic light. Does that have to do with the reliability of the compass?

You more or less already gave the answer yourself :

I know that the magnetic compass in a smartphone is not very reliable (I recently did a little experiment with a coworker in which we placed three phones on the table and compared compass readings, only to get three totally different ones.) GPS is reliable as long as the device is moving at a certain speed – in fact, even on a bike I find the GPS bearing is quite reliable as long as reception is good. It is only at walking speed that GPS bearing is of little use.

How about the following rudimentary calibration:

  • Whenever we get a reliable bearing from the GPS (i.e. speed and distance to previous point exceeds the configured thresholds), compare it to the magnetic compass and store the difference.
  • After a certain time without reliable bearing from GPS, use magnetic compass readings but apply the previously stored offset.
  • If we never got a reliable bearing from GPS, assume the offset to be zero, i.e. use magnetic compass readings without compensation. (In this case we essentially have no choice.)

As long as the compass does not spontaneously drift or oscillate (i.e. change its bearing even when the device is not moving), this should prevent the map from suddenly jumping to some random orientation when you stop at a traffic light. Also, if you turn on the spot, the map orientation should update accordingly.

But since it would be configurable from within the xml vehicleprofile, everyone could use it in his own way, but I would already be happy if a basic magnetic compass would be included. The calibration you propose would be nice as a project on it's own in follow- up of the basic magnetic compass.

In AndroidCompass3.diff I added a few lines to make the compass work in near-vertical positions as well. To use it: In the vehicle profile of your choice set static_speed en static_distance to zero. Run navit and select that profile. In the popup menu (long tap on Android screen), tap on 'enable magnetic compass' Now see the map align with the magnetic compass at each gps fix.

regards, Jan

Last edited 3 years ago by jandegr (previous) (diff)

comment:6 Changed 2 years ago by mvglasow (2)

I'm currently working on some logic to fuse locations from different sources. (Location, in this context, means position as well as speed, bearing and altitude.) My original intention was to have Navit fall back to network location when GPS becomes unavailable, but I have since come up with a skeleton which could use location information from any number of sources and is platform-independent.

The compass could, in this framework, just become another location source, supplying bearing but none of the other values.

Code is at: https://github.com/mvglasow/navit/tree/android-fused-location

Note: See TracTickets for help on using tickets.