aerostitch / testnavit

0 stars 0 forks source link

Android: enable magnetic compass #245

Open aerostitch opened 10 years ago

aerostitch commented 10 years ago

Issue migrated from trac ticket # 1234

component: core | priority: minor | keywords: patches android compass

2014-08-13 01:58:22: @jandegr created the issue


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

aerostitch commented 10 years ago

2014-08-13 01:59:15: @jandegr uploaded file AndroidCompasS.zip (5.5 KiB)

aerostitch commented 10 years ago

2014-08-13 02:09:44: @jandegr uploaded file AndroidCompass.zip (1.7 KiB)

patch

aerostitch commented 10 years ago

2014-08-14 11:38:01: @jandegr uploaded file AndroidCompass2.zip (2.2 KiB)

version 2 of android magn. compass

aerostitch commented 10 years ago

2014-08-14 11:38:28: @jandegr commented


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

aerostitch commented 10 years ago

2014-09-22 06:56:00: @mvglasow commented


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.

aerostitch commented 10 years ago

2014-09-29 11:55:20: @jandegr commented


Replying to [comment:2 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........

aerostitch commented 10 years ago

2014-09-29 13:19:27: @mvglasow commented


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.

aerostitch commented 10 years ago

2014-10-13 05:15:39: @jandegr uploaded file AndroidCompass3.diff (7.0 KiB)

third version of magnetic compass for Android Navit

aerostitch commented 10 years ago

2014-10-13 05:39:15: @jandegr commented


Replying to [comment:4 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

aerostitch commented 10 years ago

2014-10-13 05:39:15: @jandegr

aerostitch commented 8 years ago

2015-11-27 00:37:42: @mvglasow commented


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