gpsmagswitch: Drop tiltCompensation because of unscaled values

master
Erik Andresen 2023-02-28 10:36:45 +01:00
parent 71964b041e
commit 331a366ce7
3 changed files with 8 additions and 51 deletions

View File

@ -4,13 +4,12 @@ However GPS position is noisy and prone to jump around.
This results in randomly jumping GPS course values when speed is slow or standing still. This results in randomly jumping GPS course values when speed is slow or standing still.
So in these cases a user might want to get the moving direction from a compass instead. So in these cases a user might want to get the moving direction from a compass instead.
This is why this service replaces the GPS course with the compass heading when the speed is slower then 6 km/h (threshold is configurable, see settings). This is why this service replaces the GPS course with the compass heading when the speed is slower then 6 km/h (threshold is configurable, see settings).
You can switch between the built-in compass and "Navigation Compass" (magnav) as the source of the compass heading. When using magnav on Bangle.js 2 at least firmware 2v16.191 is recommended to get a three-dimensional reading.
## Important Notes ## Important Notes
* **Watch orientation** * **Watch orientation**
When the GPS is calculating the course the orientation of the watch does not matter. When the GPS is calculating the course the orientation of the watch does not matter.
When the Compass is used as the source of the current heading its top must obviously point at the moving direction (Usually away from you). When the Compass is used as the source of the current heading its top must obviously point at the moving direction (Usually away from you).
* **Tilt compensation**
When "Navigation Compass" is installed the built-in compass gets automatic tilt compensation. This can be turned off in settings. Without "Navigation Compass" installed or this feature disabled the watch must be orientated with the display up to provide a useable compass value.
* **Compass reset and calibration** * **Compass reset and calibration**
When using "Navigation Compass" as compass source (see settings) please remember to calibrate it regularly. When using "Navigation Compass" as compass source (see settings) please remember to calibrate it regularly.
With this service installed the built-in compass calibration is automatically reset when the compass is turned on (deactivatable in settings). It can also be reset with a tap on the Widget (Bangle.js 2 only). Please note that directly after a reset the built-in compass must be turned 360 degrees to provide a useable value. With this service installed the built-in compass calibration is automatically reset when the compass is turned on (deactivatable in settings). It can also be reset with a tap on the Widget (Bangle.js 2 only). Please note that directly after a reset the built-in compass must be turned 360 degrees to provide a useable value.
@ -21,22 +20,18 @@ This is why this service replaces the GPS course with the compass heading when t
## Widget ## Widget
The widget indicates if the current GPS course is provided from GPS or compass. The widget indicates if the current GPS course is provided from GPS or compass.
It can be turned off in the settings. It can be turned off in the settings.
On Bangle.js 2 a click on the widget does reset the built-in compass. On Bangle.js 2 a click on the widget does reset the built-in compass, has only an affect if the built-in compass is used.
## Settings ## Settings
* **Speed threshold** * **Speed threshold**
- (default = 6 km/h) When GPS speed is lower then this threshold use the compass direction. The speed must be for at least 10 seconds this fast to switch back to GPS course. - (default = 6 km/h) When GPS speed is lower then this threshold use the compass direction. The speed must be for at least 10 seconds this fast to switch back to GPS course.
* **Compass source** * **Compass source**
- off: Disables this addon. - off: Disables this service.
- built-in (default): Uses the built-in compass. Its calibration can be restarted by pressing the Widget. When tilt compensation is disabled or "Navigation compass" is not installed the watch must be orientated horizontally for the compass heading to be used. - built-in (default if "Navigation Compass" is not installed): Uses the built-in compass. Its calibration can be restarted by pressing the Widget. The watch must be orientated horizontally for the compass heading to be used.
- magnav (only if "Navigation Compass" is installed): Compass heading is provided by "Navigation Compass" (magnav). Remember to calibrate it regularly. - magnav (default if "Navigation Compass" is installed): Compass heading is provided by "Navigation Compass" (magnav). Remember to calibrate it regularly, at least each time after attaching the charge cable.
* **Reset compass when powered on** * **Reset compass when powered on**
- Off: Do nothing when compass is turned on. - Off: Do nothing when compass is turned on.
- On (default): The calibration of the built-in compass is reset when it is turned on. - On (default): The calibration of the built-in compass is reset when it is turned on.
* **Tilt compensation on built-in compass**
Only available if "Navigation Compass" is installed.
- Off: Leaves the value of the built-in compass unchanged.
- On (default): Apply the tilt compensation from "Navigation Compass" to the built-in compass in _all_ applications.
* **Show Widget** * **Show Widget**
- Never: Widget is hidden. - Never: Widget is hidden.
- Active (default): Widget is only visible when replacing GPS course with compass heading. - Active (default): Widget is only visible when replacing GPS course with compass heading.

View File

@ -1,13 +1,11 @@
{ {
const settings = Object.assign({ const settings = Object.assign({
speed: 6, // when lower then this use direction from compass speed: 6, // when lower then this use direction from compass
compassSrc: 1, // [off, built-in, magnav] compassSrc: 2, // [off, built-in, magnav]
resetCompassOnPwr: true, // reset compass on power on resetCompassOnPwr: true, // reset compass on power on
tiltCompensation: true, // tilt compensation on built-in compass
}, require("Storage").readJSON("gpsmagcourse.json", true) || {}); }, require("Storage").readJSON("gpsmagcourse.json", true) || {});
const CALIBDATA = (settings.compassSrc === 2) ? require("Storage").readJSON("magnav.json",1) : undefined; const CALIBDATA = (settings.compassSrc === 2) ? require("Storage").readJSON("magnav.json",1) : undefined;
let cntAboveSpeed = 0; let cntAboveSpeed = 0;
let lastMag;
// Check if magnav is installed // Check if magnav is installed
try { try {
@ -17,9 +15,6 @@
if (settings.compassSrc === 2) { if (settings.compassSrc === 2) {
settings.compassSrc = 1; settings.compassSrc = 1;
} }
if (settings.tiltCompensation) {
settings.tiltCompensation = false;
}
} }
if (settings.compassSrc === 2 && !CALIBDATA) { if (settings.compassSrc === 2 && !CALIBDATA) {
// No calibration for magnav, fallback to default compass // No calibration for magnav, fallback to default compass
@ -38,25 +33,6 @@
}; };
} // if (settings.resetCompassOnPwr) } // if (settings.resetCompassOnPwr)
if (settings.tiltCompensation) {
const origGetCompass = Bangle.getCompass;
Bangle.getCompass = function(argObj) {
if (!isNaN(lastMag.heading) && (argObj === undefined || !argObj.noTiltComp)) {
return lastMag;
}
return origGetCompass();
};
Bangle.on('mag', function(mag) {
if (!isNaN(mag.heading)) {
const d = require("magnav").tiltfix(mag, Bangle.getAccel());
mag.headingOrig = mag.heading;
mag.heading = d;
}
lastMag = mag;
});
} // if (settings.tiltCompensation)
if (settings.compassSrc > 0) { if (settings.compassSrc > 0) {
const isFaceUp = (acc) => { const isFaceUp = (acc) => {
return (acc.z<-6700/8192) && (acc.z>-9000/8192) && Math.abs(acc.x)<2048/8192 && Math.abs(acc.y)<2048/8192; return (acc.z<-6700/8192) && (acc.z>-9000/8192) && Math.abs(acc.x)<2048/8192 && Math.abs(acc.y)<2048/8192;
@ -65,7 +41,7 @@
const changeGpsCourse = (gps) => { const changeGpsCourse = (gps) => {
cntAboveSpeed = gps.speed < settings.speed ? 0 : cntAboveSpeed+1; cntAboveSpeed = gps.speed < settings.speed ? 0 : cntAboveSpeed+1;
if (cntAboveSpeed < 10) { // need to stay x events above or equal threshold if (cntAboveSpeed < 10) { // need to stay x events above or equal threshold
if (settings.compassSrc === 1 && (settings.tiltCompensation || isFaceUp(Bangle.getAccel()))) { // Use uncompensated built-in compass heading only if face is up if (settings.compassSrc === 1 && isFaceUp(Bangle.getAccel())) { // Use built-in compass heading only if face is up
const heading = Bangle.getCompass().heading; const heading = Bangle.getCompass().heading;
if (!isNaN(heading)) { if (!isNaN(heading)) {
gps.courseOrig = gps.course; gps.courseOrig = gps.course;

View File

@ -3,9 +3,8 @@
// Load settings // Load settings
const settings = Object.assign({ const settings = Object.assign({
speed: 6, // when lower then this use direction from compass speed: 6, // when lower then this use direction from compass
compassSrc: 1, // [off, built-in, magnav] compassSrc: 2, // [off, built-in, magnav]
resetCompassOnPwr: true, // reset compass on power on resetCompassOnPwr: true, // reset compass on power on
tiltCompensation: true, // tilt compensation on built-in compass
showWidget: 2, // 0 = never, 1 = when replacing GPS course with compass course, 2 = when GPS is on showWidget: 2, // 0 = never, 1 = when replacing GPS course with compass course, 2 = when GPS is on
}, require("Storage").readJSON(FILE, true) || {}); }, require("Storage").readJSON(FILE, true) || {});
@ -23,9 +22,6 @@
if (settings.compassSrc === 2) { if (settings.compassSrc === 2) {
settings.compassSrc = 1; settings.compassSrc = 1;
} }
if (settings.tiltCompensation) {
settings.tiltCompensation = false;
}
} }
const compassSrcOpts = [/*LANG*/"off", /*LANG*/"built-in"]; const compassSrcOpts = [/*LANG*/"off", /*LANG*/"built-in"];
if (magnavInstalled) { if (magnavInstalled) {
@ -74,16 +70,6 @@
}, },
}; };
if (magnavInstalled) {
menu[/*LANG*/'Tilt compensation on built-in compass'] = {
value: !!settings.tiltCompensation,
onchange: v => {
settings.tiltCompensation = v;
writeSettings();
}
};
}
// Show the menu // Show the menu
E.showMenu(menu); E.showMenu(menu);
}) })