3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef XCSOAR_FLIGHT_PHASE_DETECTOR_HPP
23 #define XCSOAR_FLIGHT_PHASE_DETECTOR_HPP
27 #include "Math/fixed.hpp"
28 #include "Geo/GeoPoint.hpp"
29 #include "Time/BrokenDateTime.hpp"
33 enum class CirclingMode
: uint8_t;
36 * Phase of the flight.
38 * May represent both single phase and totals for a set of phases.
49 enum CirclingDirection
: uint8_t {
56 /** Type of the phase */
58 /** Date and time in UTC when the phase started */
59 BrokenDateTime start_datetime
;
60 /** Date and time in UTC when the phase ended */
61 BrokenDateTime end_datetime
;
62 /** Seconds from midnight UTC when the phase started */
64 /** Seconds from midnight UTC when the phase ended */
66 /** Direction of circling (or NO_DIRECTION when not circling) */
67 CirclingDirection circling_direction
;
68 /** Starting altitude of the phase */
70 /** Ending altitude of the phase */
72 /** Starting location of the phase */
74 /** Ending location of the phase */
76 /** Duration of the phase in seconds */
78 /** Fraction of the phase duration compared to total flight time. */
80 /** Altitude difference between start_alt and end_alt */
82 /** Distance travelled during the phase, i.e. sum of distances between fixes. */
84 /** Number of the phases of the same type, combined into this phase. */
87 /** Average ground speed during the phase */
88 fixed
GetSpeed() const;
89 /** Average vertical speed during the phase */
90 fixed
GetVario() const;
91 /** Average glide rate during the phase */
92 fixed
GetGlideRate() const;
98 phase_type
= NO_PHASE
;
99 start_datetime
.Clear();
100 end_datetime
.Clear();
101 start_time
= fixed(0);
105 circling_direction
= NO_DIRECTION
;
112 typedef std::list
<Phase
> PhaseList
;
116 * Combined statistics for each phase type
119 Phase total_circstats
,
126 total_circstats
.Clear();
127 left_circstats
.Clear();
128 right_circstats
.Clear();
129 mixed_circstats
.Clear();
130 total_cruisestats
.Clear();
136 * Detect flight phases
138 * Divide flight into circling/cruise phases and calculate basic statistics for
141 * Dependencies: #CirclingComputer.
143 class FlightPhaseDetector
{
145 Phase previous_phase
;
148 CirclingMode last_turn_mode
;
156 FlightPhaseDetector();
159 * Split track to circling/cruise phases and calculate basic statistics for
162 * Actual circling detection is done by #CirclingComputer. We aggregate its
163 * data to a list of Phases by grouping set of samples with the same
164 * CirclingInfo.turn_mode value.
166 * If turn_mode is uncertain for given group (POSSIBLE_CLIMB or
167 * POSSIBLE_CRUISE), actual phase type is determined by subsequent group
168 * and two groups are combined into single phase. If phase is shorter than
169 * certain threshold (MIN_PHASE_TIME), it is not considered as a separate
170 * phase and combined with previous one.
172 * @param basic Basic flight information for the iteration
173 * @param calculated Calculated flight data for the iteration
175 void Update(const MoreData
&basic
, const DerivedInfo
&calculated
);
178 * Complete phase calculation and calculate overall flight statistics.
180 * Called at the end of the flight when no flight data is pending.
186 * Return detected phases
188 * Available after Finish() is called.
190 const PhaseList
&GetPhases() const {
195 * Return calculated totals
197 * Available after Finish() is called.
199 const PhaseTotals
&GetTotals() const {