@@ -2702,38 +2702,63 @@ function addPosition(position) {
2702
2702
2703
2703
if ( dt >= 0 ) {
2704
2704
if ( vehicle . num_positions > 0 && dt > 0 ) {
2705
- var search_ts = new_ts - 10000
2706
2705
2707
- function searchPositions ( times ) {
2708
- for ( i = times . length ; i >= 0 ; i -- ) {
2709
- if ( times [ i ] <= search_ts ) {
2710
- return times [ i ]
2711
- }
2712
- }
2713
- return null
2714
- }
2706
+ //
2707
+ // This commenteed block is an attempt at having the ascent rate and speed
2708
+ // calculations be run over a wider time range than just the last position.
2709
+ //
2710
+ // var search_ts = new_ts - 10000
2711
+
2712
+ // function searchPositions(times) {
2713
+ // for (i = times.length; i >= 0; i--) {
2714
+ // if (times[i] <= search_ts) {
2715
+ // return times[i]
2716
+ // }
2717
+ // }
2718
+ // return null
2719
+ // }
2715
2720
2716
- var search_match = searchPositions ( vehicle . positions_ts )
2717
- var search_index = vehicle . positions_ts . indexOf ( search_match )
2718
-
2719
- if ( search_match != null && search_match >= search_ts - 5000 ) {
2720
- var dtt = ( curr_ts - search_match ) / 1000 ;
2721
-
2722
- // calculate vertical rate
2723
- var rate = ( position . gps_alt - vehicle . positions_alts [ search_index ] ) / dtt ;
2724
- if ( ! isNaN ( rate ) && isFinite ( rate ) ) {
2725
- vehicle . ascent_rate = 0.2 * rate + 0.8 * vehicle . ascent_rate ;
2726
- }
2721
+ // var search_match = searchPositions(vehicle.positions_ts)
2722
+ // var search_index = vehicle.positions_ts.indexOf(search_match)
2727
2723
2728
- // calculate horizontal rate
2729
- horizontal_rate_temp = new_latlng . distanceTo ( vehicle . positions [ search_index ] ) / dtt ;
2730
- if ( ! isNaN ( horizontal_rate_temp ) && isFinite ( horizontal_rate_temp ) ) {
2731
- vehicle . horizontal_rate = horizontal_rate_temp ;
2732
- }
2724
+ // if (search_match != null && search_match >= search_ts - 5000) {
2725
+ // var dtt = (curr_ts - search_match) / 1000;
2733
2726
2734
- } else {
2735
- // calculate vertical rate
2736
- var rate = ( position . gps_alt - vehicle . curr_position . gps_alt ) / dt ;
2727
+ // //console.log("Search: Old: " + search_match + ", " + vehicle.positions_alts[search_index] + " New: " + curr_ts + ", " + position.gps_alt);
2728
+
2729
+ // // calculate vertical rate
2730
+ // if(position.data.hasOwnProperty('ascent_rate')){
2731
+ // // Use provided ascent rate if available.
2732
+ // var rate = position.data.ascent_rate;
2733
+ // } else {
2734
+ // var rate = (position.gps_alt - vehicle.positions_alts[search_index]) / dtt;
2735
+ // }
2736
+ // if (!isNaN(rate) && isFinite(rate)) {
2737
+ // vehicle.ascent_rate = 0.2 * rate + 0.8 * vehicle.ascent_rate;
2738
+ // }
2739
+
2740
+ // //console.log("Search OK - DTT: " + dtt + " Instant Rate: " + rate + " Average Rate: " + vehicle.ascent_rate);
2741
+
2742
+ // // calculate horizontal rate
2743
+ // horizontal_rate_temp = new_latlng.distanceTo(vehicle.positions[search_index]) / dtt;
2744
+ // if (!isNaN(horizontal_rate_temp) && isFinite(horizontal_rate_temp)) {
2745
+ // vehicle.horizontal_rate = horizontal_rate_temp;
2746
+ // }
2747
+
2748
+ // } else {
2749
+ // This section is the 'original' method of calculating the ascent and horizontal rates.
2750
+ // It works only on the last and current position.
2751
+ // The ascent rate is filtered.
2752
+
2753
+ // This commented block allows use of payload-supplied ascent rate data.
2754
+ // This might be worth using.
2755
+ //
2756
+ // if(position.data.hasOwnProperty('ascent_rate')){
2757
+ // var rate = position.data.ascent_rate;
2758
+ // } else {
2759
+ var rate = ( position . gps_alt - vehicle . curr_position . gps_alt ) / dt ;
2760
+ //}
2761
+
2737
2762
if ( ! isNaN ( rate ) && isFinite ( rate ) ) {
2738
2763
vehicle . ascent_rate = 0.2 * rate + 0.8 * vehicle . ascent_rate ;
2739
2764
}
@@ -2743,7 +2768,7 @@ function addPosition(position) {
2743
2768
if ( ! isNaN ( horizontal_rate_temp ) && isFinite ( horizontal_rate_temp ) ) {
2744
2769
vehicle . horizontal_rate = horizontal_rate_temp ;
2745
2770
}
2746
- }
2771
+ // }
2747
2772
}
2748
2773
2749
2774
// add the new position
@@ -3302,7 +3327,7 @@ function liveData() {
3302
3327
if ( ( dateNow - tempDate ) < 30000 ) {
3303
3328
var test = formatData ( frame ) ;
3304
3329
if ( clientActive ) {
3305
- live_data_buffer . positions . position . push . apply ( live_data_buffer . positions . position , test . positions . position )
3330
+ live_data_buffer . positions . position . push . apply ( live_data_buffer . positions . position , test . positions . position ) ;
3306
3331
}
3307
3332
$ ( "#stTimer" ) . attr ( "data-timestamp" , dateNow ) ;
3308
3333
$ ( "#stText" ) . text ( "websocket |" ) ;
0 commit comments