Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>GPS altitude bounces around a lot, and each of these bounces looks like an ascent or descent. In my experience the barometer sensor bounces around a much narrower range.</p> <p>What you want to do is measure each climb (where a climb is defined as a constant increase in altitude), and sum the climbs to determine the total height climbed.</p> <p>With any sensor (GPS or baro) the altitude will bounce around a little and we don't want those little bounces to be registered as short descents and climbs. So when we are climbing, we want to ignore small dips in altitude.</p> <pre><code>double THRESHOLD = 10; Direction climbingOrDescending = Direction.NONE; double totalAscent = 0; double totalDescent = 0; double climbStart; double maxAltitude; double descentStart; double minAltitude; public void onSample(double sample) { if (climbingOrDescending == Direction.NONE) { // First sample climbingOrDescending = Direction.CLIMBING; // Arbitrary climbStart = sample; maxAltitude = sample; } else if (climbingOrDescending == Direction.CLIMBING) { if (sample &gt; maxAltitude) { maxAltitude = sample; } else if (sample &lt; (maxAltitude - THRESHOLD) ) { // bounces in sample that are smaller than THRESHOLD are ignored. If // the sample is far below maxAltitude... it is not a bounce, record // the climb and move to a descending state double altitudeGainedThisClimb = maxAltitude - climbStart; totalAscent += altitudeGainedThisClimb; // Prepare for descent. climbingOrDescending = Direction.DESCENDING; descentStart = maxAltitude; minAltitude = sample; } } else { // climbingOrDescending == DESCENDING // similar code goes here to measure descents } } public double getTotalAscent() { if (climbingOrDescending == Direction.CLIMBING) { return totalAscent + (maxAltitude - climbStart); } else { return totalAscent; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload