Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / src / Computer / FlyingComputer.hpp
blobbd128beee61effa18d3988bef5b95562cf626d50
1 /*
2 Copyright_License {
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 #ifndef XCSOAR_FLYING_COMPUTER_HPP
25 #define XCSOAR_FLYING_COMPUTER_HPP
27 #include "StateClock.hpp"
28 #include "Math/fixed.hpp"
29 #include "Geo/GeoPoint.hpp"
30 #include "DeltaTime.hpp"
32 struct NMEAInfo;
33 struct DerivedInfo;
34 struct AircraftState;
35 struct FlyingState;
37 /**
38 * Detect takeoff and landing.
40 class FlyingComputer {
41 DeltaTime delta_time;
43 /**
44 * Tracks the duration the aircraft has been stationary.
46 StateClock<60, 5> stationary_clock;
48 /**
49 * Tracks the duration the aircraft has been moving.
51 StateClock<30, 5> moving_clock;
53 /**
54 * Tracks the duration the aircraft has been climbing. If the
55 * aircraft has been climbing for a certain amount of time, it is
56 * assumed that it is still flying, even if the ground speed is
57 * small (for example, when flying in a wave without airspeed
58 * input).
60 StateClock<20, 5> climbing_clock;
62 /**
63 * If the aircraft is currenly assumed to be moving, then this
64 * denotes the initial moving time stamp. This gets reset to a
65 * negative value when the aircraft is stationary for a certain
66 * amount of time.
68 fixed moving_since;
70 /**
71 * If the aircraft is currently assumed to be moving, then this
72 * denotes the location when moving started initially. This
73 * attribute is only valid if #moving_since is non-negative.
75 GeoPoint moving_at;
77 fixed stationary_since;
78 GeoPoint stationary_at;
80 fixed climbing_altitude;
82 fixed sinking_since;
84 GeoPoint sinking_location;
86 fixed sinking_altitude;
88 /**
89 * The last altitude when the aircraft was supposed to be on the
90 * ground. This is usually the elevation of the take-off airfield.
92 * A negative value means unknown. Sorry for these few airfields
93 * that are below MSL ...
95 fixed last_ground_altitude;
97 public:
98 void Reset();
100 void Compute(fixed takeoff_speed,
101 const NMEAInfo &basic,
102 const DerivedInfo &calculated,
103 FlyingState &flying);
105 void Compute(fixed takeoff_speed,
106 const AircraftState &state, fixed dt,
107 FlyingState &flying);
110 * Finish the landing detection. If landing has not been detected,
111 * but the aircraft has not been moving, this force-detects the
112 * landing now. Call at the end of a replay.
114 void Finish(FlyingState &flying, fixed time);
116 protected:
117 void CheckRelease(FlyingState &state, fixed time, const GeoPoint &location,
118 fixed altitude);
121 * Check for monotonic climb. This check is used for "flying"
122 * detection in a wave, when ground speed is low, no airspeed is
123 * available and no map was loaded.
125 * @return true if the aircraft has been climbing for more than 10
126 * seconds
128 bool CheckClimbing(fixed dt, fixed altitude);
130 void Check(FlyingState &state, fixed time);
133 * Update flying state when moving
135 * @param time Time the aircraft is moving
137 void Moving(FlyingState &state, fixed time, fixed dt,
138 const GeoPoint &location);
141 * Update flying state when stationary
143 * @param time Time the aircraft is stationary
144 * @param on_ground Whether the aircraft is known to be on the ground
146 void Stationary(FlyingState &state, fixed time, fixed dt,
147 const GeoPoint &location);
150 #endif