From 75ed834129d89004238ab7c7000de2636137fca2 Mon Sep 17 00:00:00 2001 From: nujw Date: Sun, 21 Feb 2021 10:24:16 +1300 Subject: [PATCH 01/20] Added third [C]lock mode to display large clock face. --- apps/speedalt/app.js | 65 +++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 9e95737c4..3dffe3a47 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -3,7 +3,7 @@ Speed and Altitude [speedalt] Mike Bennett mike[at]kereru.com 1.16 : Use new GPS settings module */ -var v = '1.20'; +var v = '1.21'; var buf = Graphics.createArrayBuffer(240,160,2,{msb:true}); // Load fonts @@ -25,7 +25,6 @@ var emulator = (process.env.BOARD=="EMSCRIPTEN")?1:0; // 1 = running in emulato var wp = {}; // Waypoint to use for distance from cur position. function nxtWp(inc){ - if (cfg.modeA) return; cfg.wp+=inc; loadWp(); } @@ -98,6 +97,14 @@ function drawFix(dat) { } +function drawClock() { + if (!canDraw) return; + buf.clear(); + drawTime(); + g.reset(); + g.drawImage(img,0,40); +} + function drawPrimary(n,u) { // Primary Display @@ -146,11 +153,21 @@ function drawSecondary(n,u) { } function drawTime() { - var x = 0; - var y = 160; + var x, y; + + if ( cfg.modeA == 2 ) { + x=120; + y=80; + buf.setFontAlign(0,0); //left, bottom + buf.setFontVector(80); + } + else { + x = 0; + y = 160; + buf.setFontAlign(-1,1); + buf.setFont("7x11Numeric7Seg", 2); + } - buf.setFont("7x11Numeric7Seg", 2); - buf.setFontAlign(-1,1); //left, bottom buf.setColor(0); buf.drawString(time,x,y); @@ -161,7 +178,7 @@ function drawTime() { function drawWP() { var nm = wp.name; - if ( nm == undefined || nm == 'NONE' || cfg.modeA ) nm = ''; + if ( nm == undefined || nm == 'NONE' || cfg.modeA != 0 ) nm = ''; buf.setFontAlign(-1,1); //left, bottom buf.setColor(2); @@ -180,15 +197,14 @@ function drawSats(sats) { buf.setFontVector(20); buf.setColor(2); - if ( cfg.modeA ) buf.drawString("A",240,140); - else buf.drawString("D",240,140); - - if ( showMax && cfg.modeA ) { - buf.setFontAlign(0,1); //centre, bottom - buf.drawString("MAX",120,164); + if ( cfg.modeA == 1 ) { + buf.drawString("A",240,140); + if ( showMax ) { + buf.setFontAlign(0,1); //centre, bottom + buf.drawString("MAX",120,164); + } } - - + if ( cfg.modeA == 0 ) buf.drawString("D",240,140); } function onGPS(fix) { @@ -239,7 +255,7 @@ function onGPS(fix) { age = Math.max(0,Math.round(getTime())-(lf.time.getTime()/1000)); } - if ( cfg.modeA ) { + if ( cfg.modeA == 1 ) { if ( showMax ) drawFix({ speed:max.spd, @@ -258,8 +274,8 @@ function onGPS(fix) { age:age, fix:lf.fix }); // Show speed/altitude - } - else { + } + if ( cfg.modeA == 0 ) { // Show speed/distance if ( di <= 0 ) drawFix({ @@ -280,6 +296,10 @@ function onGPS(fix) { fix:lf.fix }); } + if ( cfg.modeA == 2 ) { + // Large clock + drawClock(); + } } @@ -288,12 +308,12 @@ function setButtons(){ // Spd+Dist : Select next waypoint setWatch(function(e) { var dur = e.time - e.lastTime; - if ( cfg.modeA ) { + if ( cfg.modeA == 1 ) { // Spd+Alt mode - Switch between fix and MAX if ( dur < 2 ) showMax = !showMax; // Short press toggle fix/max display else { max.spd = 0; max.alt = 0; } // Long press resets max values. } - else nxtWp(1); // Spd+Dist mode - Select next waypoint + if ( cfg.modeA == 0 ) nxtWp(1); // Spd+Dist mode - Select next waypoint onGPS(lf); }, BTN1, { edge:"falling",repeat:true}); @@ -315,7 +335,8 @@ function setButtons(){ // Toggle between alt or dist setWatch(function(e){ - cfg.modeA = !cfg.modeA; + cfg.modeA = cfg.modeA+1; + if ( cfg.modeA > 2 ) cfg.modeA = 0; savSettings(); onGPS(lf); }, BTN3, {repeat:true,edge:"falling"}); @@ -373,7 +394,7 @@ cfg.dist = cfg.dist||1000;// Multiplier for distnce unit conversions. cfg.dist_unit = cfg.dist_unit||'km'; // Displayed altitude units cfg.colour = cfg.colour||0; // Colour scheme. cfg.wp = cfg.wp||0; // Last selected waypoint for dist -cfg.modeA = cfg.modeA||0; // 0 = [D], 1 = [A] +cfg.modeA = cfg.modeA||0; // 0 = [D]ist, 1 = [A]ltitude, 2 = [C]lock cfg.primSpd = cfg.primSpd||0; // 1 = Spd in primary, 0 = Spd in secondary From 2c0cff2b2cb181776bf93c762393f962a60626ed Mon Sep 17 00:00:00 2001 From: nujw Date: Sun, 21 Feb 2021 10:39:01 +1300 Subject: [PATCH 02/20] Clock update to 10 secs --- apps/speedalt/app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 3dffe3a47..63129def2 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -2,6 +2,7 @@ Speed and Altitude [speedalt] Mike Bennett mike[at]kereru.com 1.16 : Use new GPS settings module +1.21 : Third mode large clock display */ var v = '1.21'; var buf = Graphics.createArrayBuffer(240,160,2,{msb:true}); @@ -454,4 +455,4 @@ else { Bangle.on('GPS', onGPS); setButtons(); -setInterval(updateClock, 30000); +setInterval(updateClock, 10000); From bca2740a0bbe516f0d82fa3d9302a7f8104798d9 Mon Sep 17 00:00:00 2001 From: nujw Date: Sun, 21 Feb 2021 10:40:49 +1300 Subject: [PATCH 03/20] Update apps.json --- apps.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps.json b/apps.json index f28a1ac03..7b7e6f2c7 100644 --- a/apps.json +++ b/apps.json @@ -2640,7 +2640,7 @@ "name": "GPS Adventure Sports", "shortName":"GPS Adv Sport", "icon": "app.png", - "version":"1.00", + "version":"1.01", "description": "GPS speed, altitude and distance to waypoint display. Designed for easy viewing and use during outdoor activities such as para-gliding, hang-gliding, sailing, cycling etc.", "tags": "tool,outdoors", "type":"app", From 10d2b0f9564dd5d49b9f0d434b807aa9849355d0 Mon Sep 17 00:00:00 2001 From: nujw Date: Sun, 21 Feb 2021 11:00:53 +1300 Subject: [PATCH 04/20] Added waypoint selection to large display mode. Aids visibility in strong light. --- apps/speedalt/app.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 63129def2..59f62d18d 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -4,7 +4,7 @@ Mike Bennett mike[at]kereru.com 1.16 : Use new GPS settings module 1.21 : Third mode large clock display */ -var v = '1.21'; +var v = '1.22'; var buf = Graphics.createArrayBuffer(240,160,2,{msb:true}); // Load fonts @@ -102,6 +102,7 @@ function drawClock() { if (!canDraw) return; buf.clear(); drawTime(); + drawWP(); g.reset(); g.drawImage(img,0,40); } @@ -158,8 +159,8 @@ function drawTime() { if ( cfg.modeA == 2 ) { x=120; - y=80; - buf.setFontAlign(0,0); //left, bottom + y=0; + buf.setFontAlign(0,-1); buf.setFontVector(80); } else { @@ -179,13 +180,21 @@ function drawTime() { function drawWP() { var nm = wp.name; - if ( nm == undefined || nm == 'NONE' || cfg.modeA != 0 ) nm = ''; - - buf.setFontAlign(-1,1); //left, bottom + if ( nm == undefined || nm == 'NONE' || cfg.modeA ==1 ) nm = ''; buf.setColor(2); - buf.setFontVector(20); - buf.drawString(nm.substring(0,6),77,160); - + + if ( cfg.modeA == 0 ) { // dist mode + buf.setFontAlign(-1,1); //left, bottom + buf.setFontVector(20); + buf.drawString(nm.substring(0,6),72,160); + } + + if ( cfg.modeA == 2 ) { // clock/large mode + buf.setFontAlign(0,1); //left, bottom + buf.setFontVector(55); + buf.drawString(nm.substring(0,6),120,160); + } + } function drawSats(sats) { @@ -314,7 +323,7 @@ function setButtons(){ if ( dur < 2 ) showMax = !showMax; // Short press toggle fix/max display else { max.spd = 0; max.alt = 0; } // Long press resets max values. } - if ( cfg.modeA == 0 ) nxtWp(1); // Spd+Dist mode - Select next waypoint + else nxtWp(1); // Spd+Dist or Clock mode - Select next waypoint onGPS(lf); }, BTN1, { edge:"falling",repeat:true}); From a5a59dbd0fc066007f32e78a9c705a22fcb78c3f Mon Sep 17 00:00:00 2001 From: nujw Date: Sun, 21 Feb 2021 11:23:37 +1300 Subject: [PATCH 05/20] Enlarge mode indicators --- apps/speedalt/app.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 59f62d18d..754980a0b 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -4,7 +4,7 @@ Mike Bennett mike[at]kereru.com 1.16 : Use new GPS settings module 1.21 : Third mode large clock display */ -var v = '1.22'; +var v = '1.23'; var buf = Graphics.createArrayBuffer(240,160,2,{msb:true}); // Load fonts @@ -204,17 +204,17 @@ function drawSats(sats) { buf.setFontAlign(1,1); //right, bottom buf.drawString(sats,240,160); - buf.setFontVector(20); + buf.setFontVector(40); buf.setColor(2); if ( cfg.modeA == 1 ) { - buf.drawString("A",240,140); + buf.drawString('A',240,140); if ( showMax ) { buf.setFontAlign(0,1); //centre, bottom - buf.drawString("MAX",120,164); + buf.drawString('MAX',120,164); } } - if ( cfg.modeA == 0 ) buf.drawString("D",240,140); + if ( cfg.modeA == 0 ) buf.drawString('D',240,140); } function onGPS(fix) { From c872417eda669954c00fe7b1cc9302afecee4d4b Mon Sep 17 00:00:00 2001 From: nujw Date: Mon, 22 Feb 2021 10:07:54 +1300 Subject: [PATCH 06/20] Enlarge units display. --- apps/speedalt/app.js | 14 ++++++++------ apps/speedalt/settings.js | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 754980a0b..4752fed85 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -4,7 +4,7 @@ Mike Bennett mike[at]kereru.com 1.16 : Use new GPS settings module 1.21 : Third mode large clock display */ -var v = '1.23'; +var v = '1.24'; var buf = Graphics.createArrayBuffer(240,160,2,{msb:true}); // Load fonts @@ -108,7 +108,7 @@ function drawClock() { } function drawPrimary(n,u) { - + // Primary Display var s=40; // Font size @@ -116,7 +116,7 @@ function drawPrimary(n,u) { if ( l <= 7 ) s=48; if ( l <= 6 ) s=55; - if ( l <= 5 ) s=68; + if ( l <= 5 ) s=66; if ( l <= 4 ) s=85; if ( l <= 3 ) s=110; @@ -124,11 +124,13 @@ function drawPrimary(n,u) { buf.setColor(1); buf.setFontVector(s); buf.drawString(n,110,0); - + + + // Primary Units buf.setFontAlign(1,-1,3); //right buf.setColor(2); - buf.setFontVector(25); + buf.setFontVector(35); buf.drawString(u,210,0); } @@ -150,7 +152,7 @@ function drawSecondary(n,u) { // Secondary Units buf.setFontAlign(-1,1); //left, bottom buf.setColor(2); - buf.setFontVector(25); + buf.setFontVector(30); buf.drawString(u,s,135); } diff --git a/apps/speedalt/settings.js b/apps/speedalt/settings.js index aeec76c98..7ecc2b940 100644 --- a/apps/speedalt/settings.js +++ b/apps/speedalt/settings.js @@ -48,14 +48,14 @@ '< Back': function() { E.showMenu(appMenu); }, 'default (spd)' : function() { setUnits(0,''); }, 'Kph (spd)' : function() { setUnits(1,'kph'); }, - 'Knots (spd)' : function() { setUnits(1.852,'knots'); }, + 'Knots (spd)' : function() { setUnits(1.852,'kts'); }, 'Mph (spd)' : function() { setUnits(1.60934,'mph'); }, 'm/s (spd)' : function() { setUnits(3.6,'m/s'); }, 'Km (dist)' : function() { setUnitsDist(1000,'km'); }, - 'Miles (dist)' : function() { setUnitsDist(1609.344,'miles'); }, + 'Miles (dist)' : function() { setUnitsDist(1609.344,'mi'); }, 'Nm (dist)' : function() { setUnitsDist(1852.001,'nm'); }, 'Meters (alt)' : function() { setUnitsAlt(1,'m'); }, - 'Feet (alt)' : function() { setUnitsAlt(0.3048,'feet'); } + 'Feet (alt)' : function() { setUnitsAlt(0.3048,'ft'); } }; const colMenu = { From 67d48dad7d6977d1db1a737c7c588bcdd93389ec Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 2 Mar 2021 12:56:48 +1300 Subject: [PATCH 07/20] Add Kalman filtering to smooth speed and alt. --- apps/speedalt/app.js | 196 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 192 insertions(+), 4 deletions(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 4752fed85..7cddba28f 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -3,8 +3,177 @@ Speed and Altitude [speedalt] Mike Bennett mike[at]kereru.com 1.16 : Use new GPS settings module 1.21 : Third mode large clock display +1.25 : add smoothing with kalman filter */ -var v = '1.24'; +var v = '1.25'; + +/*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */ +var KalmanFilter = (function () { + 'use strict'; + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; + } + + /** + * KalmanFilter + * @class + * @author Wouter Bulten + * @see {@link http://github.com/wouterbulten/kalmanjs} + * @version Version: 1.0.0-beta + * @copyright Copyright 2015-2018 Wouter Bulten + * @license MIT License + * @preserve + */ + var KalmanFilter = + /*#__PURE__*/ + function () { + /** + * Create 1-dimensional kalman filter + * @param {Number} options.R Process noise + * @param {Number} options.Q Measurement noise + * @param {Number} options.A State vector + * @param {Number} options.B Control vector + * @param {Number} options.C Measurement vector + * @return {KalmanFilter} + */ + function KalmanFilter() { + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$R = _ref.R, + R = _ref$R === void 0 ? 1 : _ref$R, + _ref$Q = _ref.Q, + Q = _ref$Q === void 0 ? 1 : _ref$Q, + _ref$A = _ref.A, + A = _ref$A === void 0 ? 1 : _ref$A, + _ref$B = _ref.B, + B = _ref$B === void 0 ? 0 : _ref$B, + _ref$C = _ref.C, + C = _ref$C === void 0 ? 1 : _ref$C; + + _classCallCheck(this, KalmanFilter); + + this.R = R; // noise power desirable + + this.Q = Q; // noise power estimated + + this.A = A; + this.C = C; + this.B = B; + this.cov = NaN; + this.x = NaN; // estimated signal without noise + } + /** + * Filter a new value + * @param {Number} z Measurement + * @param {Number} u Control + * @return {Number} + */ + + + _createClass(KalmanFilter, [{ + key: "filter", + value: function filter(z) { + var u = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + + if (isNaN(this.x)) { + this.x = 1 / this.C * z; + this.cov = 1 / this.C * this.Q * (1 / this.C); + } else { + // Compute prediction + var predX = this.predict(u); + var predCov = this.uncertainty(); // Kalman gain + + var K = predCov * this.C * (1 / (this.C * predCov * this.C + this.Q)); // Correction + + this.x = predX + K * (z - this.C * predX); + this.cov = predCov - K * this.C * predCov; + } + + return this.x; + } + /** + * Predict next value + * @param {Number} [u] Control + * @return {Number} + */ + + }, { + key: "predict", + value: function predict() { + var u = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + return this.A * this.x + this.B * u; + } + /** + * Return uncertainty of filter + * @return {Number} + */ + + }, { + key: "uncertainty", + value: function uncertainty() { + return this.A * this.cov * this.A + this.R; + } + /** + * Return the last filtered measurement + * @return {Number} + */ + + }, { + key: "lastMeasurement", + value: function lastMeasurement() { + return this.x; + } + /** + * Set measurement noise Q + * @param {Number} noise + */ + + }, { + key: "setMeasurementNoise", + value: function setMeasurementNoise(noise) { + this.Q = noise; + } + /** + * Set the process noise R + * @param {Number} noise + */ + + }, { + key: "setProcessNoise", + value: function setProcessNoise(noise) { + this.R = noise; + } + }]); + + return KalmanFilter; + }(); + + return KalmanFilter; + +}()); + +var spdFilter = new KalmanFilter({R: 0.01, Q: 3}); +var altFilter = new KalmanFilter({R: 0.01, Q: 3}); + + var buf = Graphics.createArrayBuffer(240,160,2,{msb:true}); // Load fonts @@ -223,13 +392,14 @@ function onGPS(fix) { if ( emulator ) { fix.fix = 1; - fix.speed = 10; - fix.alt = 354; + fix.speed = 10 + (Math.random()*5); + fix.alt = 354 + (Math.random()*50); fix.lat = -38.92; fix.lon = 175.7613350; fix.course = 245; fix.satellites = 12; fix.time = new Date(); + fix.smoothed = 0; } var m; @@ -240,7 +410,22 @@ function onGPS(fix) { var age = '---'; if (fix.fix) lf = fix; - if (lf.fix) { + + if (lf.fix) { + + // Smooth data + if ( lf.smoothed !== 1 ) { + + print('u: '+lf.speed+' '+lf.alt); + + lf.speed = spdFilter.filter(lf.speed); + lf.alt = altFilter.filter(lf.alt); + + print('f: '+lf.speed+' '+lf.alt); + + lf.smoothed = 1; + } + // Speed if ( cfg.spd == 0 ) { @@ -410,6 +595,9 @@ cfg.modeA = cfg.modeA||0; // 0 = [D]ist, 1 = [A]ltitude, 2 = [C]lock cfg.primSpd = cfg.primSpd||0; // 1 = Spd in primary, 0 = Spd in secondary +cfg.spd = 1; +cfg.spd_unit = 'kph'; + loadWp(); /* From 15ec3dc05dc8adfd6e6fdca524dc269d71af6338 Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 2 Mar 2021 13:07:08 +1300 Subject: [PATCH 08/20] Update apps.json Add kalman filtering to smooth speed and alt. --- apps.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps.json b/apps.json index 7b7e6f2c7..1f39b4ade 100644 --- a/apps.json +++ b/apps.json @@ -2640,7 +2640,7 @@ "name": "GPS Adventure Sports", "shortName":"GPS Adv Sport", "icon": "app.png", - "version":"1.01", + "version":"1.02", "description": "GPS speed, altitude and distance to waypoint display. Designed for easy viewing and use during outdoor activities such as para-gliding, hang-gliding, sailing, cycling etc.", "tags": "tool,outdoors", "type":"app", From 70b231ee18a0f0b61c96b81c3a19f3715198792f Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 2 Mar 2021 13:29:21 +1300 Subject: [PATCH 09/20] Tweaks to filter settings --- apps/speedalt/app.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 7cddba28f..e24ca3e49 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -3,9 +3,9 @@ Speed and Altitude [speedalt] Mike Bennett mike[at]kereru.com 1.16 : Use new GPS settings module 1.21 : Third mode large clock display -1.25 : add smoothing with kalman filter +1.01b : add smoothing with kalman filter */ -var v = '1.25'; +var v = '1.01b'; /*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */ var KalmanFilter = (function () { @@ -171,7 +171,7 @@ var KalmanFilter = (function () { }()); var spdFilter = new KalmanFilter({R: 0.01, Q: 3}); -var altFilter = new KalmanFilter({R: 0.01, Q: 3}); +var altFilter = new KalmanFilter({R: 0.01, Q: 10}); var buf = Graphics.createArrayBuffer(240,160,2,{msb:true}); @@ -575,7 +575,7 @@ function savSettings() { function setLpMode(m) { if (tmrLP) {clearInterval(tmrLP);tmrLP = false;} // Stop any scheduled drop to low power if ( !gpssetup ) return; - gpssetup.setPowerMode({power_mode:m}) + gpssetup.setPowerMode({power_mode:m}); } // =Main Prog @@ -594,10 +594,6 @@ cfg.wp = cfg.wp||0; // Last selected waypoint for dist cfg.modeA = cfg.modeA||0; // 0 = [D]ist, 1 = [A]ltitude, 2 = [C]lock cfg.primSpd = cfg.primSpd||0; // 1 = Spd in primary, 0 = Spd in secondary - -cfg.spd = 1; -cfg.spd_unit = 'kph'; - loadWp(); /* From a116b9583974f02d081c90aa837f8144481ee7a8 Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 2 Mar 2021 13:32:22 +1300 Subject: [PATCH 10/20] Change ver --- apps/speedalt/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index e24ca3e49..30542590f 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -5,7 +5,7 @@ Mike Bennett mike[at]kereru.com 1.21 : Third mode large clock display 1.01b : add smoothing with kalman filter */ -var v = '1.01b'; +var v = '1.02b'; /*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */ var KalmanFilter = (function () { From e706c44ebbf7a08282bef13b01ddc2019b9946a6 Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 2 Mar 2021 13:36:42 +1300 Subject: [PATCH 11/20] Update app.js --- apps/speedalt/app.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 30542590f..0b339bd84 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -3,9 +3,9 @@ Speed and Altitude [speedalt] Mike Bennett mike[at]kereru.com 1.16 : Use new GPS settings module 1.21 : Third mode large clock display -1.01b : add smoothing with kalman filter +1.02 : add smoothing with kalman filter */ -var v = '1.02b'; +var v = '1.02c'; /*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */ var KalmanFilter = (function () { @@ -415,14 +415,8 @@ function onGPS(fix) { // Smooth data if ( lf.smoothed !== 1 ) { - - print('u: '+lf.speed+' '+lf.alt); - lf.speed = spdFilter.filter(lf.speed); lf.alt = altFilter.filter(lf.alt); - - print('f: '+lf.speed+' '+lf.alt); - lf.smoothed = 1; } From c6e96119d9b71c8f02f2eb2197571f71f2ffc306 Mon Sep 17 00:00:00 2001 From: nujw Date: Wed, 3 Mar 2021 09:31:17 +1300 Subject: [PATCH 12/20] Adjust kalman filter settings. --- apps/speedalt/app.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 0b339bd84..396c93a5e 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -5,7 +5,7 @@ Mike Bennett mike[at]kereru.com 1.21 : Third mode large clock display 1.02 : add smoothing with kalman filter */ -var v = '1.02c'; +var v = '1.02d'; /*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */ var KalmanFilter = (function () { @@ -170,8 +170,8 @@ var KalmanFilter = (function () { }()); -var spdFilter = new KalmanFilter({R: 0.01, Q: 3}); -var altFilter = new KalmanFilter({R: 0.01, Q: 10}); +var spdFilter = new KalmanFilter({R: 0.01, Q: 2}); +var altFilter = new KalmanFilter({R: 0.01, Q: 2}); var buf = Graphics.createArrayBuffer(240,160,2,{msb:true}); @@ -189,6 +189,7 @@ var tmrLP; // Timer for delay in switching to low power after screen var max = {}; max.spd = 0; max.alt = 0; +max.n = 0; // counter. Only start comparing for max after a certain number of fixes to allow kalman filter to have smoohed the data. var emulator = (process.env.BOARD=="EMSCRIPTEN")?1:0; // 1 = running in emulator. Supplies test values; @@ -375,7 +376,7 @@ function drawSats(sats) { buf.setFontAlign(1,1); //right, bottom buf.drawString(sats,240,160); - buf.setFontVector(40); + buf.setFontVector(30); buf.setColor(2); if ( cfg.modeA == 1 ) { @@ -418,6 +419,7 @@ function onGPS(fix) { lf.speed = spdFilter.filter(lf.speed); lf.alt = altFilter.filter(lf.alt); lf.smoothed = 1; + if ( max.n <= 15 ) max.n++; } @@ -431,12 +433,12 @@ function onGPS(fix) { if ( sp < 10 ) sp = sp.toFixed(1); else sp = Math.round(sp); - if (parseFloat(sp) > parseFloat(max.spd) ) max.spd = parseFloat(sp); + if (parseFloat(sp) > parseFloat(max.spd) && max.n > 15 ) max.spd = parseFloat(sp); // Altitude al = lf.alt; al = Math.round(parseFloat(al)/parseFloat(cfg.alt)); - if (parseFloat(al) > parseFloat(max.alt) ) max.alt = parseFloat(al); + if (parseFloat(al) > parseFloat(max.alt) && max.n > 15 ) max.alt = parseFloat(al); // Distance to waypoint di = distance(lf,wp); From d3cd557e68092362ca015e431bb881d490714471 Mon Sep 17 00:00:00 2001 From: nujw Date: Fri, 5 Mar 2021 10:25:31 +1300 Subject: [PATCH 13/20] Tweak Kalman filter setting for speed. --- apps/speedalt/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 396c93a5e..f69b955a1 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -5,7 +5,7 @@ Mike Bennett mike[at]kereru.com 1.21 : Third mode large clock display 1.02 : add smoothing with kalman filter */ -var v = '1.02d'; +var v = '1.02e'; /*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */ var KalmanFilter = (function () { @@ -170,7 +170,7 @@ var KalmanFilter = (function () { }()); -var spdFilter = new KalmanFilter({R: 0.01, Q: 2}); +var spdFilter = new KalmanFilter({R: 0.1, Q: 1}); var altFilter = new KalmanFilter({R: 0.01, Q: 2}); From bef2955ba07058879df642f54deb142da9cc5303 Mon Sep 17 00:00:00 2001 From: nujw Date: Fri, 5 Mar 2021 17:27:05 +1300 Subject: [PATCH 14/20] Add Kalman Filter switch on/off to settings menu. --- apps/speedalt/app.js | 15 +++++++++------ apps/speedalt/settings.js | 20 ++++++++++++++++++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index f69b955a1..04bf58380 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -5,7 +5,7 @@ Mike Bennett mike[at]kereru.com 1.21 : Third mode large clock display 1.02 : add smoothing with kalman filter */ -var v = '1.02e'; +var v = '1.02g'; /*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */ var KalmanFilter = (function () { @@ -170,9 +170,6 @@ var KalmanFilter = (function () { }()); -var spdFilter = new KalmanFilter({R: 0.1, Q: 1}); -var altFilter = new KalmanFilter({R: 0.01, Q: 2}); - var buf = Graphics.createArrayBuffer(240,160,2,{msb:true}); @@ -416,8 +413,8 @@ function onGPS(fix) { // Smooth data if ( lf.smoothed !== 1 ) { - lf.speed = spdFilter.filter(lf.speed); - lf.alt = altFilter.filter(lf.alt); + if ( cfg.spdFilt ) lf.speed = spdFilter.filter(lf.speed); + if ( cfg.altFilt ) lf.alt = altFilter.filter(lf.alt); lf.smoothed = 1; if ( max.n <= 15 ) max.n++; } @@ -590,6 +587,12 @@ cfg.wp = cfg.wp||0; // Last selected waypoint for dist cfg.modeA = cfg.modeA||0; // 0 = [D]ist, 1 = [A]ltitude, 2 = [C]lock cfg.primSpd = cfg.primSpd||0; // 1 = Spd in primary, 0 = Spd in secondary +cfg.spdFilt = cfg.spdFilt==undefined?true:cfg.spdFilt; +cfg.altFilt = cfg.altFilt==undefined?true:cfg.altFilt; + +if ( cfg.spdFilt ) var spdFilter = new KalmanFilter({R: 0.1 , Q: 1 }); +if ( cfg.altFilt ) var altFilter = new KalmanFilter({R: 0.01, Q: 2 }); + loadWp(); /* diff --git a/apps/speedalt/settings.js b/apps/speedalt/settings.js index 7ecc2b940..6e417da56 100644 --- a/apps/speedalt/settings.js +++ b/apps/speedalt/settings.js @@ -29,13 +29,15 @@ settings.colour = c; writeSettings(); } + const appMenu = { '': {'title': 'GPS Speed Alt'}, '< Back': back, '< Load GPS Adv Sport': ()=>{load('speedalt.app.js');}, 'Units' : function() { E.showMenu(unitsMenu); }, - 'Colours' : function() { E.showMenu(colMenu); }/*, + 'Colours' : function() { E.showMenu(colMenu); }, + 'Kalman Filter' : function() { E.showMenu(kalMenu); }/*, 'Vibrate' : { value : settings.buzz, format : v => v?"On":"Off", @@ -66,7 +68,21 @@ 'Night' : function() { setColour(2); } }; + const kalMenu = { + '': {'title': 'Kalman Filter'}, + 'Speed' : { + value : settings.spdFilt, + format : v => v?"On":"Off", + onchange : () => { settings.spdFilt = !settings.spdFilt; writeSettings(); } + }, + 'Altitude' : { + value : settings.altFilt, + format : v => v?"On":"Off", + onchange : () => { settings.altFilt = !settings.altFilt; writeSettings(); } + } + }; + E.showMenu(appMenu); -}) +}); From c88b6d58b6ba0984407eafc58ebadd839ab66190 Mon Sep 17 00:00:00 2001 From: nujw Date: Fri, 5 Mar 2021 17:33:56 +1300 Subject: [PATCH 15/20] Fix Kalman menu --- apps/speedalt/settings.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/speedalt/settings.js b/apps/speedalt/settings.js index 6e417da56..488ba3b81 100644 --- a/apps/speedalt/settings.js +++ b/apps/speedalt/settings.js @@ -70,6 +70,7 @@ const kalMenu = { '': {'title': 'Kalman Filter'}, + '< Back': function() { E.showMenu(appMenu); }, 'Speed' : { value : settings.spdFilt, format : v => v?"On":"Off", From 6b290d1c8c516dce003af7d586b7d14d5342a55f Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 9 Mar 2021 17:36:24 +1300 Subject: [PATCH 16/20] Update ChangeLog --- apps/speedalt/ChangeLog | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/speedalt/ChangeLog b/apps/speedalt/ChangeLog index c5bde6c1a..de5c9c221 100644 --- a/apps/speedalt/ChangeLog +++ b/apps/speedalt/ChangeLog @@ -5,4 +5,6 @@ 0.05: Add setting to turn vibrate on/off. 0.06: Tweaks to vibration settings. 0.07: Switch to BTN1 for Max toggle and reset function. -1.00: New features. Added waypoints file and distance to selected waypoint display. Added integration with GPS Setup module to switch GPS to low power mode when screen off. Save display settings and restore when app restarted. \ No newline at end of file +1.00: New features. Added waypoints file and distance to selected waypoint display. Added integration with GPS Setup module to switch GPS to low power mode when screen off. Save display settings and restore when app restarted. +1.01: Add third screen mode with large clock and waypoint selection display to ease visibility in bright daylight. +1.02: Add Kalman filter to smooth the speed and altitude values. Can be disabled in settings. From 069a1fa8c959665d9a0139b977a96a1b2af0716c Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 9 Mar 2021 17:46:42 +1300 Subject: [PATCH 17/20] Update README.md --- apps/speedalt/README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/speedalt/README.md b/apps/speedalt/README.md index 50ffce70c..79b45c288 100644 --- a/apps/speedalt/README.md +++ b/apps/speedalt/README.md @@ -1,14 +1,14 @@ # GPS Speed, Altimeter and Distance to Waypoint -You can switch between two display modes. One showing speed and altitude (A) and one showing speed and distance to waypoint (D). +You can switch between three display modes. One showing speed and altitude (A), one showing speed and distance to waypoint (D) and a large dispay of time and selected waypoint. -Within each display mode one figure is displayed on the watch face using the largest possible characters depending on the number of digits. The other is in a smaller characters below that. Both are always visible. You can display the current or maximum observed speed/altitude values. Current time is always displayed. +Within the [A]ltitude and [D]istance displays modes one figure is displayed on the watch face using the largest possible characters depending on the number of digits. The other is in a smaller characters below that. Both are always visible. You can display the current or maximum observed speed/altitude values. Current time is always displayed. The waypoints list is the same as that used with the [GPS Navigation](https://banglejs.com/apps/#gps%20navigation) app so the same set of waypoints can be used across both apps. Refer to that app for waypoint file information. ## Buttons and Controls -BTN3 : Swaps the modes between Speed+[A]ltitude or Speed+[D]istance. +BTN3 : Cycles the modes between Speed+[A]ltitude, Speed+[D]istance and large Time/Waypoint ### [A]ltitude mode @@ -20,9 +20,13 @@ BTN1 : Long press > 2 secs resets the recorded maximum values. BTN1 : Select next waypoint. Last fix distance from selected waypoint is displayed. -### Both modes +### Large mode -BTN2 : Disables/Restores power saving timeout. Locks the screen on to enable reading for longer periods but uses maximum battery drain. Red LED (dot) at top of screen when screen is locked on. Press again to restore power saving timeouts. +BTN1 : Select next waypoint. Last fix distance from selected waypoint is displayed. + +### All modes + +BTN2 : Disables/Restores power saving timeout. Locks the screen on and GPS in SuperE mode to enable reading for longer periods but uses maximum battery drain. Red LED (dot) at top of screen when screen is locked on. Press again to restore power saving timeouts. BTN3 : Long press exit and return to watch. @@ -32,6 +36,10 @@ BTN4 : Left Display Tap : Swaps which figure is in the large display. You can ha Select the desired display units. Speed can be as per the default locale, kph, knots, mph or m/s. Distance can be km, miles or nautical miles. Altitude can be feet or metres. Select one of three colour schemes. Default (three colours), high contrast (all white on black) or night ( all red on black ). +## Kalman Filter + +This filter smooths the altitude and the speed values and reduces these values 'jumping around' from one GPS fix to the next. The down side of this is that if these values change rapidly ( eg. a quick change in altitude ) then it can take a few GPS fixes for the values to move to the new vlaues. Disabling the Kalman filter in the settings will cause the raw values to be displayed from each GPS fix as they are found. + ## Loss of fix When the GPS obtains a fix the number of satellites is displayed as 'Sats:nn'. When unable to obtain a fix then the last known fix is used and the age of that fix in seconds is displayed as 'Age:nn'. Seeing 'Sats' or 'Age' indicates whether the GPS has a current fix or not. From 5b4532eb8635a56d4e5e83d77ee937f52be4678e Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 9 Mar 2021 17:47:23 +1300 Subject: [PATCH 18/20] Update README.md --- apps/speedalt/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/speedalt/README.md b/apps/speedalt/README.md index 79b45c288..19006bc83 100644 --- a/apps/speedalt/README.md +++ b/apps/speedalt/README.md @@ -22,7 +22,7 @@ BTN1 : Select next waypoint. Last fix distance from selected waypoint is display ### Large mode -BTN1 : Select next waypoint. Last fix distance from selected waypoint is displayed. +BTN1 : Select next waypoint. ### All modes From f2baf6ad5fc505f7be1f3d1275a9b0672a2c8ca5 Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 9 Mar 2021 17:48:41 +1300 Subject: [PATCH 19/20] Update README.md --- apps/speedalt/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/speedalt/README.md b/apps/speedalt/README.md index 19006bc83..db3c7e673 100644 --- a/apps/speedalt/README.md +++ b/apps/speedalt/README.md @@ -146,6 +146,6 @@ Developed for my use in sailing, cycling and motorcycling. If you find this soft Many thanks to Gordon Williams. Awesome job. -Special thanks also to @jeffmer, for the [GPS Navigation](https://banglejs.com/apps/#gps%20navigation) app and @hughbarney for the Low power GPS code development. +Special thanks also to @jeffmer, for the [GPS Navigation](https://banglejs.com/apps/#gps%20navigation) app and @hughbarney for the Low power GPS code development and Wouter Bulten for the Kalman filter code. From 28012bbb41bf0d0991b38d4f24c4d35fefadc79f Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 9 Mar 2021 17:53:50 +1300 Subject: [PATCH 20/20] Update app.js --- apps/speedalt/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 04bf58380..c8735479d 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -1,8 +1,8 @@ /* Speed and Altitude [speedalt] Mike Bennett mike[at]kereru.com -1.16 : Use new GPS settings module -1.21 : Third mode large clock display +1.00 : Use new GPS settings module +1.01 : Third mode large clock display 1.02 : add smoothing with kalman filter */ var v = '1.02g';