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