android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / src / Computer / ThermalLocator.hpp
blob43d45c53de100a553dc7b6009e7b9e8578a02d81
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 THERMALLOCATOR_H
25 #define THERMALLOCATOR_H
27 #include "Math/fixed.hpp"
28 #include "Geo/GeoPoint.hpp"
29 #include "Geo/SpeedVector.hpp"
30 #include "Geo/Flat/FlatPoint.hpp"
32 class TaskProjection;
33 struct ThermalLocatorInfo;
35 /**
36 * Class to estimate the location of the center of a thermal
37 * when circling.
39 class ThermalLocator {
40 public:
41 static constexpr unsigned TLOCATOR_NMIN = 5;
42 static constexpr unsigned TLOCATOR_NMAX = 60;
44 private:
45 /** Class used to hold thermal estimate samples */
46 struct Point
48 /**
49 * Calculate drifted, weighted values of point
51 * @param t Current time
52 * @param location_0 Initial location
53 * @param wind_drift Wind drift offset
54 * @param decay decay factor for weighting
56 void Drift(fixed t, const TaskProjection& projection,
57 const GeoPoint& wind_drift);
59 /** Actual location of sample */
60 GeoPoint location;
61 /** Projected/drifted sample */
62 FlatPoint loc_drift;
63 /** Time of sample (s) */
64 fixed t_0;
65 /** Scaled updraft value of sample */
66 fixed w;
67 /** Lift weighting used for this point */
68 fixed lift_weight;
69 /** Recency weighting used for this point */
70 fixed recency_weight;
73 /** Circular buffer of points */
74 Point points[TLOCATOR_NMAX];
76 /** Index of next point to add */
77 unsigned n_index;
78 /** Number of points in buffer */
79 unsigned n_points;
81 public:
82 /**
83 * Update locator estimate. If not in circling mode, resets the
84 * object.
86 * @param circling Whether aircraft is in circling mode
87 * @param time Time of fix (s)
88 * @param location Location of aircraft
89 * @param w Net updraft speed (m/s)
90 * @param wind Wind vector
91 * @param therm Output thermal estimate data
93 void Process(const bool circling, const fixed time, const GeoPoint &location,
94 const fixed w, const SpeedVector wind,
95 ThermalLocatorInfo& therm);
97 /**
98 * Reset as if never flown
100 void Reset();
102 private:
103 FlatPoint glider_average();
105 void AddPoint(const fixed t, const GeoPoint &location, const fixed w);
106 void Update(const fixed t_0, const GeoPoint &location_0,
107 const SpeedVector wind, ThermalLocatorInfo &therm);
109 void Drift(const fixed t_0, const TaskProjection& projection,
110 const GeoPoint& traildrift);
113 #endif