@@ -2702,38 +2702,63 @@ function addPosition(position) {
27022702
27032703 if ( dt >= 0 ) {
27042704 if ( vehicle . num_positions > 0 && dt > 0 ) {
2705- var search_ts = new_ts - 10000
27062705
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+ // }
27152720
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)
27272723
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;
27332726
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+
27372762 if ( ! isNaN ( rate ) && isFinite ( rate ) ) {
27382763 vehicle . ascent_rate = 0.2 * rate + 0.8 * vehicle . ascent_rate ;
27392764 }
@@ -2743,7 +2768,7 @@ function addPosition(position) {
27432768 if ( ! isNaN ( horizontal_rate_temp ) && isFinite ( horizontal_rate_temp ) ) {
27442769 vehicle . horizontal_rate = horizontal_rate_temp ;
27452770 }
2746- }
2771+ // }
27472772 }
27482773
27492774 // add the new position
@@ -3302,7 +3327,7 @@ function liveData() {
33023327 if ( ( dateNow - tempDate ) < 30000 ) {
33033328 var test = formatData ( frame ) ;
33043329 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 ) ;
33063331 }
33073332 $ ( "#stTimer" ) . attr ( "data-timestamp" , dateNow ) ;
33083333 $ ( "#stText" ) . text ( "websocket |" ) ;
0 commit comments