| 1 | // AircraftPerformance.hxx - compute data about planned acft performance |
| 2 | // |
| 3 | // Copyright (C) 2018 James Turner <[email protected]> |
| 4 | // This program is free software; you can redistribute it and/or |
| 5 | // modify it under the terms of the GNU General Public License as |
| 6 | // published by the Free Software Foundation; either version 2 of the |
| 7 | // License, or (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, but |
| 10 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | // General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program; if not, write to the Free Software |
| 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | |
| 18 | #ifndef AIRCRAFTPERFORMANCE_HXX |
| 19 | #define AIRCRAFTPERFORMANCE_HXX |
| 20 | |
| 21 | #include <string> |
| 22 | #include <vector> |
| 23 | #include <functional> |
| 24 | |
| 25 | namespace flightgear |
| 26 | { |
| 27 | |
| 28 | const char ICAO_AIRCRAFT_CATEGORY_A = 'A'; |
| 29 | const char ICAO_AIRCRAFT_CATEGORY_B = 'B'; |
| 30 | const char ICAO_AIRCRAFT_CATEGORY_C = 'C'; |
| 31 | const char ICAO_AIRCRAFT_CATEGORY_D = 'D'; |
| 32 | const char ICAO_AIRCRAFT_CATEGORY_E = 'E'; |
| 33 | |
| 34 | /** |
| 35 | * Calculate flight parameter based on aircraft performance data. |
| 36 | * This is based on simple rules: it does not (yet) include data |
| 37 | * such as winds aloft, payload or temperature impact on engine |
| 38 | * performance. */ |
| 39 | class AircraftPerformance |
| 40 | { |
| 41 | public: |
| 42 | AircraftPerformance(); |
| 43 | |
| 44 | double turnRateDegSec() const; |
| 45 | |
| 46 | double turnRadiusMForAltitude(int altitudeFt) const; |
| 47 | |
| 48 | double groundSpeedForAltitudeKnots(int altitudeFt) const; |
| 49 | |
| 50 | int computePreviousAltitude(double distanceM, int targetAltFt) const; |
| 51 | int computeNextAltitude(double distanceM, int initialAltFt) const; |
| 52 | |
| 53 | double distanceNmBetween(int initialElevationFt, int targetElevationFt) const; |
| 54 | double timeBetween(int initialElevationFt, int targetElevationFt) const; |
| 55 | |
| 56 | double timeToCruise(double cruiseDistanceNm, int cruiseAltitudeFt) const; |
| 57 | |
| 58 | static double groundSpeedForCAS(int altitudeFt, double cas); |
| 59 | static double machForCAS(int altitudeFt, double cas); |
| 60 | static double groundSpeedForMach(int altitudeFt, double mach); |
| 61 | |
| 62 | private: |
| 63 | void readPerformanceData(); |
| 64 | |
| 65 | void icaoCategoryData(); |
| 66 | |
| 67 | /** |
| 68 | * @brief heuristicCatergoryFromTags - based on the aircraft tags, figure |
| 69 | * out a plausible ICAO category. Returns cat A if nothing better could |
| 70 | * be determined. |
| 71 | * @return a string containing a single ICAO category character A..E |
| 72 | */ |
| 73 | std::string heuristicCatergoryFromTags() const; |
| 74 | |
| 75 | class Bracket |
| 76 | { |
| 77 | public: |
| 78 | Bracket(int atOrBelow, int climb, int descent, double speed, bool isMach = false) : |
| 79 | atOrBelowAltitudeFt(atOrBelow), |
| 80 | climbRateFPM(climb), |
| 81 | descentRateFPM(descent), |
| 82 | speedIASOrMach(speed), |
| 83 | speedIsMach(isMach) |
| 84 | { } |
| 85 | |
| 86 | int gsForAltitude(int altitude) const; |
| 87 | |
| 88 | double climbTime(int alt1, int alt2) const; |
| 89 | double climbDistanceM(int alt1, int alt2) const; |
| 90 | double descendTime(int alt1, int alt2) const; |
| 91 | double descendDistanceM(int alt1, int alt2) const; |
| 92 | |
| 93 | int atOrBelowAltitudeFt; |
| 94 | int climbRateFPM; |
| 95 | int descentRateFPM; |
| 96 | double speedIASOrMach; |
| 97 | bool speedIsMach = false; |
| 98 | }; |
| 99 | |
| 100 | using PerformanceVec = std::vector<Bracket>; |
| 101 | |
| 102 | using BracketRange = std::pair<PerformanceVec::const_iterator, PerformanceVec::const_iterator>; |
| 103 | |
| 104 | PerformanceVec::const_iterator bracketForAltitude(int altitude) const; |
| 105 | BracketRange rangeForAltitude(int lowAltitude, int highAltitude) const; |
| 106 | |
| 107 | |
| 108 | using TraversalFunc = std::function<void(const Bracket& bk, int alt1, int alt2)>; |
| 109 | void traverseAltitudeRange(int initialElevationFt, int targetElevationFt, TraversalFunc tf) const; |
| 110 | |
| 111 | |
| 112 | PerformanceVec _perfData; |
| 113 | }; |
| 114 | |
| 115 | } |
| 116 | |
| 117 | #endif // AIRCRAFTPERFORMANCE_HXX |