]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/rnav_waypt_controller.hxx
Restore GPS compatibility with 2.10
[flightgear.git] / src / Instrumentation / rnav_waypt_controller.hxx
1 // rnav_waypt_controller.hxx - Waypoint-specific behaviours for RNAV systems
2 // Written by James Turner, started 2009.
3 //
4 // Copyright (C) 2009  Curtis L. Olson
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
20 #ifndef FG_WAYPT_CONTROLLER_HXX
21 #define FG_WAYPT_CONTROLLER_HXX
22
23 #include <Navaids/waypoint.hxx>
24
25 namespace flightgear
26 {
27
28 /**
29  * Abstract RNAV interface, for devices which implement an RNAV
30  * system - INS / GPS / FMS
31  */
32 class RNAV
33 {
34 public:
35   virtual SGGeod position() = 0;
36   
37   /**
38    * True track in degrees
39    */
40   virtual double trackDeg() = 0;
41   
42   /**
43    * Ground speed (along the track) in knots
44    */
45   virtual double groundSpeedKts() = 0;
46   
47   /**
48    * Vertical speed in ft/minute
49    */
50   virtual double vspeedFPM()= 0;
51   
52   /**
53    * Magnetic variation at current position
54    */
55   virtual double magvarDeg() = 0;
56   
57   /**
58    * device selected course (eg, from autopilot / MCP / OBS) in degrees
59    */
60   virtual double selectedMagCourse() = 0;
61
62   /**
63    * minimum distance to a waypoint for overflight sequencing. 
64    */
65   virtual double overflightArmDistanceM() = 0;
66 };
67
68 class WayptController
69 {
70 public:
71   virtual ~WayptController();
72   
73   virtual void init();
74
75   virtual void update() = 0;
76
77   /**
78    * Compute time until the waypoint is done
79    */
80   virtual double timeToWaypt() const;
81
82   /**
83    * Compute distance until the waypoint is done
84    */
85   virtual double distanceToWayptM() const = 0;
86
87   /**
88    * Bearing to the waypoint, if this value is meaningful.
89    * Default implementation returns the target track
90    */
91   virtual double trueBearingDeg() const
92     { return _targetTrack; }
93
94   virtual double targetTrackDeg() const 
95     { return _targetTrack; }
96
97   virtual double xtrackErrorNm() const
98     { return 0.0; }
99
100   virtual double courseDeviationDeg() const
101     { return 0.0; }
102
103   /**
104    * Position associated with the waypt. For static waypoints, this is
105    * simply the waypoint position itself; for dynamic points, it's the
106    * estimated location at which the controller will be done.
107    */
108   virtual SGGeod position() const = 0;
109
110   /**
111    * Is this controller finished?
112    */
113   bool isDone() const
114     { return _isDone; }
115
116   /**
117    * to/from flag - true = to, false = from. Defaults to 'true' because
118    * nearly all waypoint controllers become done as soon as this value would
119    * become false.
120    */
121   virtual bool toFlag() const
122     { return true; }
123     
124   /**
125    * Static factory method, given a waypoint, return a controller bound
126    * to it, of the appropriate type
127    */
128   static WayptController* createForWaypt(RNAV* rnav, const WayptRef& aWpt);
129 protected:
130   WayptController(RNAV* aRNAV, const WayptRef& aWpt) :
131     _waypt(aWpt),
132     _targetTrack(0),
133     _rnav(aRNAV),
134     _isDone(false)
135   { }
136   
137   WayptRef _waypt;
138   double _targetTrack;
139   RNAV* _rnav;
140   
141   void setDone();
142 private:
143   bool _isDone;
144 };
145
146 /**
147  * Controller supports 'directTo' (DTO) navigation to a waypoint. This
148  * creates a course from a starting point, to the waypoint, and reports
149  * deviation from that course.
150  *
151  * The controller is done when the waypoint is reached (to/from goes to 'from')
152  */
153 class DirectToController : public WayptController
154 {
155 public:
156   DirectToController(RNAV* aRNAV, const WayptRef& aWpt, const SGGeod& aOrigin);
157   
158   virtual void init();
159   virtual void update();
160   virtual double distanceToWayptM() const;  
161   virtual double xtrackErrorNm() const;  
162   virtual double courseDeviationDeg() const;  
163   virtual double trueBearingDeg() const;
164   virtual SGGeod position() const;
165 private:
166   SGGeod _origin;
167   double _distanceM;
168   double _courseDev;
169 };
170
171 /**
172  *
173  */
174 class OBSController : public WayptController
175 {
176 public:
177   OBSController(RNAV* aRNAV, const WayptRef& aWpt);
178   
179   virtual void init();
180   virtual void update();
181   virtual double distanceToWayptM() const;  
182   virtual double xtrackErrorNm() const;  
183   virtual double courseDeviationDeg() const;  
184   virtual double trueBearingDeg() const;
185   virtual bool toFlag() const;
186   virtual SGGeod position() const;
187 private:
188   double _distanceM;
189   double _courseDev;
190 };
191
192 } // of namespace flightgear
193
194 #endif