From 04c6b6f249b2de319d7971246e7e316b4cc29df0 Mon Sep 17 00:00:00 2001 From: frederic wagner Date: Fri, 16 Sep 2022 16:35:13 +0200 Subject: [PATCH] breaks --- apps/gipy/ChangeLog | 1 + apps/gipy/TODO | 2 -- apps/gipy/app.js | 19 +++++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/gipy/ChangeLog b/apps/gipy/ChangeLog index 949698056..f9f55be15 100644 --- a/apps/gipy/ChangeLog +++ b/apps/gipy/ChangeLog @@ -57,3 +57,4 @@ 0.14: * Detect starting distance to compute a good average speed. * Settings + * Account for breaks in average speed. diff --git a/apps/gipy/TODO b/apps/gipy/TODO index d78d4c019..53c3530e2 100644 --- a/apps/gipy/TODO +++ b/apps/gipy/TODO @@ -10,8 +10,6 @@ - config screen - are we on foot (and should use compass) -- average speed becomes invalid if you stop and restart - - pause when not moving - we need to buzz 200m before sharp turns (or even better, 30seconds) (and look at more than next point) diff --git a/apps/gipy/app.js b/apps/gipy/app.js index dc1b1b35e..a918a7992 100644 --- a/apps/gipy/app.js +++ b/apps/gipy/app.js @@ -39,6 +39,8 @@ class Status { this.current_segment = null; // which segment is closest this.reaching = null; // which waypoint are we reaching ? this.distance_to_next_point = null; // how far are we from next point ? + this.paused_time = 0.0; // how long did we stop (stops don't count in avg speed) + this.paused_since = getTime(); let r = [0]; // let's do a reversed prefix computations on all distances: @@ -94,6 +96,18 @@ class Status { } else { this.instant_speed = oldest_point.distance(last_point) / (now - this.old_times[0]); + + // update paused time if we are too slow + if (this.instant_speed < 2) { + if (this.paused_since === null) { + this.paused_since = now; + } + } else { + if (this.paused_since !== null) { + this.paused_time += now - this.paused_since; + this.paused_since = null; + } + } } // let's just take angle of segment between newest point and a point a bit before let previous_index = this.old_points.length - 3; @@ -293,8 +307,9 @@ class Status { let point_time = this.old_times[this.old_times.length - 1]; let done_distance = this.remaining_distances_at_start[orientation] - remaining_distance; - let done_in = point_time - this.starting_times[orientation]; - if (done_in != 0) { + let done_in = + point_time - this.starting_times[orientation] - this.paused_time; + if (done_in > 0) { approximate_speed = Math.round((done_distance * 3.6) / done_in); } }