]> git.mxchange.org Git - flightgear.git/blob - src/ATC/approach.hxx
Alexander's Approach ATC class modified to support his new menu/transmission code
[flightgear.git] / src / ATC / approach.hxx
1 // approach.hxx -- Approach class\r
2 //\r
3 // Written by Alexander Kappes, started March 2002.\r
4 //\r
5 // Copyright (C) 2002  Alexander Kappes\r
6 //\r
7 // This program is free software; you can redistribute it and/or\r
8 // modify it under the terms of the GNU General Public License as\r
9 // published by the Free Software Foundation; either version 2 of the\r
10 // License, or (at your option) any later version.\r
11 //\r
12 // This program is distributed in the hope that it will be useful, but\r
13 // WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
15 // General Public License for more details.\r
16 //\r
17 // You should have received a copy of the GNU General Public License\r
18 // along with this program; if not, write to the Free Software\r
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
20 \r
21 \r
22 #ifndef _FG_APPROACH_HXX\r
23 #define _FG_APPROACH_HXX\r
24 \r
25 #include <stdio.h>\r
26 \r
27 #include <simgear/compiler.h>\r
28 #include <simgear/math/sg_geodesy.hxx>\r
29 #include <simgear/misc/sgstream.hxx>\r
30 #include <simgear/magvar/magvar.hxx>\r
31 #include <simgear/timing/sg_time.hxx>\r
32 #include <simgear/bucket/newbucket.hxx>\r
33 \r
34 #include <Main/fg_props.hxx>\r
35 \r
36 #ifdef SG_HAVE_STD_INCLUDES\r
37 #  include <istream>\r
38 #include <iomanip>\r
39 #elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )\r
40 #  include <iostream.h>\r
41 #elif defined( __BORLANDC__ )\r
42 #  include <iostream>\r
43 #else\r
44 #  include <istream.h>\r
45 #include <iomanip.h>\r
46 #endif\r
47 \r
48 #if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )\r
49 SG_USING_STD(istream);\r
50 #endif\r
51 \r
52 SG_USING_STD(string);\r
53 \r
54 #include "ATC.hxx"\r
55 #include "transmission.hxx"\r
56 \r
57 //DCL - a complete guess for now.\r
58 #define FG_APPROACH_DEFAULT_RANGE 100\r
59 \r
60 // Contains all the information about a plane that the approach control needs\r
61 const int    max_planes = 20;  // max number of planes on the stack\r
62 const int    max_wp = 10;      // max number of waypoints for approach phase\r
63 const double max_ta = 130;     // max turning angle for plane during approach\r
64 const double tbm    = 20000.0; // min time (in ms) between two messages\r
65 const double lfl    = 10.0;    // length of final leg\r
66 \r
67 struct PlaneApp {\r
68 \r
69   // variables for plane if it's on the radar\r
70   string ident;          // indentification of plane\r
71   double lon;            // longitude in degrees\r
72   double lat;            // latitude in degrees\r
73   double alt;            // Altitute above sea level in feet\r
74   double hdg;            // heading of plane in degrees\r
75   double dist;           // distance to airport in miles\r
76   double brg;            // bearing relative to airport in degrees\r
77   double spd;            // speed above ground\r
78   int    contact;        // contact with approach established?\r
79                          // 0 = no contact yet\r
80                          // 1 = in contact\r
81                          // 2 = handed off to tower\r
82   double turn_rate;      // standard turning rate of the plane in seconds per degree\r
83   double desc_rate;      // standard descent rate of the plane in feets per minute\r
84   double clmb_rate;      // standard climb rate of the plane in feets per minute\r
85 \r
86   // additional variables if contact has been established\r
87   int    wpn;                 // number of waypoints\r
88   double wpts[max_wp][6];     // assigned waypoints for approach phase \r
89                               // first wp in list is airport\r
90                               // last waypoint point at which contact was established\r
91                               // second index: 0 = bearing to airport\r
92                               // second index: 1 = distance to airport\r
93                               // second index: 2 = alt \r
94                               // second index: 3 = ETA\r
95                               // second index: 4 = heading to next waypoint\r
96                               // second index: 5 = distance to next waypoint\r
97 \r
98   double dnwp;           // distance to next waypoint\r
99   double dcc;            // closest distance to current assigned course\r
100   double dnc;            // closest distance to course from next to next to next wp\r
101   double aalt;           // assigned altitude\r
102   double ahdg;           // assigned heading\r
103   bool   on_crs;         // is the plane on course?\r
104   bool   wp_change;      // way point has changed\r
105   double tlm;            // time when last message was sent\r
106   TransCode lmc;         // code of last message\r
107 };\r
108 \r
109 \r
110 class FGApproach : public FGATC {\r
111 \r
112   int      bucket;\r
113 \r
114   string active_runway;         \r
115   double active_rw_hdg;\r
116   double active_rw_lon;\r
117   double active_rw_lat;\r
118   double active_rw_len;\r
119 \r
120   bool     display;             // Flag to indicate whether we should be outputting to the display.\r
121   bool     displaying;          // Flag to indicate whether we are outputting to the display.\r
122   int      num_planes;          // number of planes on the stack\r
123   PlaneApp planes[max_planes];  // Array of planes\r
124   string   transmission;\r
125   bool     first;\r
126 \r
127   SGPropertyNode *comm1_node;\r
128   SGPropertyNode *comm2_node;\r
129 \r
130   SGPropertyNode *atcmenu_node;\r
131   SGPropertyNode *atcopt0_node;\r
132   SGPropertyNode *atcopt1_node;\r
133   SGPropertyNode *atcopt2_node;\r
134   SGPropertyNode *atcopt3_node;\r
135   SGPropertyNode *atcopt4_node;\r
136   SGPropertyNode *atcopt5_node;\r
137   SGPropertyNode *atcopt6_node;\r
138   SGPropertyNode *atcopt7_node;\r
139   SGPropertyNode *atcopt8_node;\r
140   SGPropertyNode *atcopt9_node;\r
141 \r
142   // for failure modeling\r
143   string trans_ident;   // transmitted ident\r
144   bool approach_failed; // approach failed?\r
145 \r
146 public:\r
147 \r
148   FGApproach(void);\r
149   ~FGApproach(void);\r
150 \r
151   void Init();\r
152 \r
153   void Update();\r
154 \r
155   // Add new plane to stack if not already registered \r
156   // Input:  pid - id of plane (name) \r
157   // Output: "true" if added; "false" if already existend\r
158   void AddPlane(string pid);\r
159 \r
160   // Remove plane from stack if out of range\r
161   int RemovePlane();\r
162   \r
163   //Indicate that this instance should be outputting to the ATC display\r
164   inline void SetDisplay(void) {display = true;}\r
165   \r
166   //Indicate that this instance should not be outputting to the ATC display\r
167   inline void SetNoDisplay(void) {display = false;}\r
168   \r
169   inline double get_bucket() const { return bucket; }\r
170   inline int get_pnum() const { return num_planes; }\r
171   inline string get_trans_ident() { return trans_ident; }\r
172   inline atc_type GetType() { return APPROACH; }\r
173   \r
174 private:\r
175 \r
176   void calc_wp( const int &i);\r
177 \r
178   void update_plane_dat();\r
179 \r
180   void get_active_runway();\r
181 \r
182   void update_param(const int &i);\r
183 \r
184   double round_alt( bool hl, double alt );\r
185 \r
186   double angle_diff_deg( const double &a1, const double &a2);\r
187 \r
188 // ========================================================================\r
189 // get point2 given starting point1 and course and distance\r
190 // input:  point1 = heading in degrees, distance\r
191 // input:  course in degrees, distance\r
192 // output: point2 = heading in degrees, distance\r
193 // ========================================================================\r
194   void calc_cd_head_dist(const double &h1, const double &d1,\r
195                          const double &course, const double &dist,\r
196                          double *h2, double *d2);\r
197 \r
198 \r
199 // ========================================================================\r
200 // get heading and distance between two points; point2 ---> point1\r
201 // input:  point1 = heading in degrees, distance\r
202 // input:  point2 = heading in degrees, distance\r
203 // output: course in degrees, distance\r
204 // ========================================================================\r
205   void calc_hd_course_dist(const double &h1, const double &d1,\r
206                            const double &h2, const double &d2,\r
207                            double *course, double *dist);\r
208 \r
209 \r
210 \r
211 // ========================================================================\r
212 // closest distance between a point and a straigt line in 2 dim.\r
213 // the input variables are given in (heading, distance) \r
214 // relative to a common point\r
215 // input:  point        = heading in degrees, distance\r
216 // input:  straigt line = anker vector (heading in degrees, distance), \r
217 //                        heading of direction vector\r
218 // output: distance\r
219 // ========================================================================\r
220   double calc_psl_dist(const double &h1, const double &d1,\r
221                        const double &h2, const double &d2,\r
222                        const double &h3);\r
223 \r
224   // Pointers to current users position\r
225   SGPropertyNode *lon_node;\r
226   SGPropertyNode *lat_node;\r
227   SGPropertyNode *elev_node;\r
228   SGPropertyNode *hdg_node;\r
229   SGPropertyNode *speed_node;\r
230   SGPropertyNode *etime_node;\r
231   \r
232   //Update the transmission string\r
233   void UpdateTransmission(void);\r
234   \r
235   friend istream& operator>> ( istream&, FGApproach& );\r
236 };\r
237 \r
238 #endif // _FG_APPROACH_HXX\r