4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "FlightStatistics.hpp"
26 void FlightStatistics::Reset() {
27 ScopeLock
lock(mutex
);
29 thermal_average
.Reset();
31 altitude_base
.Reset();
32 altitude_ceiling
.Reset();
34 altitude_terrain
.Reset();
38 FlightStatistics::StartTask()
40 ScopeLock
lock(mutex
);
41 // JMW clear thermal climb average on task start
42 thermal_average
.Reset();
47 FlightStatistics::AddAltitudeTerrain(const fixed tflight
, const fixed terrainalt
)
49 ScopeLock
lock(mutex
);
50 altitude_terrain
.LeastSquaresUpdate(std::max(fixed(0), tflight
/ 3600),
55 FlightStatistics::AddAltitude(const fixed tflight
, const fixed alt
)
57 ScopeLock
lock(mutex
);
58 altitude
.LeastSquaresUpdate(std::max(fixed(0), tflight
/ 3600), alt
);
62 FlightStatistics::AverageThermalAdjusted(const fixed mc_current
,
65 ScopeLock
lock(mutex
);
68 if (thermal_average
.y_ave
> fixed(0)) {
69 if (mc_current
> fixed(0) && circling
)
70 mc_stats
= (thermal_average
.sum_n
* thermal_average
.y_ave
+ mc_current
) /
71 (thermal_average
.sum_n
+ 1);
73 mc_stats
= thermal_average
.y_ave
;
75 mc_stats
= mc_current
;
82 FlightStatistics::AddTaskSpeed(const fixed tflight
, const fixed val
)
84 ScopeLock
lock(mutex
);
85 task_speed
.LeastSquaresUpdate(tflight
/ 3600, std::max(fixed(0),val
));
89 FlightStatistics::AddClimbBase(const fixed tflight
, const fixed alt
)
91 ScopeLock
lock(mutex
);
93 if (!altitude_ceiling
.IsEmpty())
94 // only update base if have already climbed, otherwise
95 // we will catch the takeoff height as the base.
96 altitude_base
.LeastSquaresUpdate(std::max(fixed(0), tflight
) / 3600, alt
);
100 FlightStatistics::AddClimbCeiling(const fixed tflight
, const fixed alt
)
102 ScopeLock
lock(mutex
);
103 altitude_ceiling
.LeastSquaresUpdate(std::max(fixed(0), tflight
) / 3600, alt
);
107 * Adds a thermal to the ThermalAverage calculator
108 * @param v Average climb speed of the last thermal
111 FlightStatistics::AddThermalAverage(const fixed v
)
113 ScopeLock
lock(mutex
);
114 thermal_average
.LeastSquaresUpdate(v
);