]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/approach.hxx
Remove confusing default (missing) path from 2D panel code.
[flightgear.git] / src / ATCDCL / 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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 #  include <iosfwd>
37
38 #include "ATC.hxx"
39 #include "transmission.hxx"
40
41 //DCL - a complete guess for now.
42 #define FG_APPROACH_DEFAULT_RANGE 100
43
44 // Contains all the information about a plane that the approach control needs
45 const int    max_planes = 20;  // max number of planes on the stack
46 const int    max_wp = 10;      // max number of waypoints for approach phase
47 const double max_ta = 130;     // max turning angle for plane during approach
48 const double tbm    = 2.0;     // min time (in sec) between two messages
49 const double lfl    = 10.0;    // length of final leg
50
51 struct PlaneApp {
52
53   // variables for plane if it's on the radar
54   std::string ident;          // indentification of plane
55   double lon;            // longitude in degrees
56   double lat;            // latitude in degrees
57   double alt;            // Altitute above sea level in feet
58   double hdg;            // heading of plane in degrees
59   double dist;           // distance to airport in miles
60   double brg;            // bearing relative to airport in degrees
61   double spd;            // speed above ground
62   int    contact;        // contact with approach established?
63                          // 0 = no contact yet
64                          // 1 = in contact
65                          // 2 = handed off to tower
66   double turn_rate;      // standard turning rate of the plane in seconds per degree
67   double desc_rate;      // standard descent rate of the plane in feets per minute
68   double clmb_rate;      // standard climb rate of the plane in feets per minute
69
70   // additional variables if contact has been established
71   int    wpn;                 // number of waypoints
72   double wpts[max_wp][6];     // assigned waypoints for approach phase 
73                               // first wp in list is airport
74                               // last waypoint point at which contact was established
75                               // second index: 0 = bearing to airport
76                               // second index: 1 = distance to airport
77                               // second index: 2 = alt 
78                               // second index: 3 = ETA
79                               // second index: 4 = heading to next waypoint
80                               // second index: 5 = distance to next waypoint
81
82   double dnwp;           // distance to next waypoint
83   double dcc;            // closest distance to current assigned course
84   double dnc;            // closest distance to course from next to next to next wp
85   double aalt;           // assigned altitude
86   double ahdg;           // assigned heading
87   bool   on_crs;         // is the plane on course?
88   bool   wp_change;      // way point has changed
89   double tlm;            // time when last message was sent
90   TransCode lmc;         // code of last message
91 };
92
93
94 class FGApproach : public FGATC {
95
96   int      bucket;
97
98   std::string active_runway;         
99   double active_rw_hdg;
100   double active_rw_lon;
101   double active_rw_lat;
102   double active_rw_len;
103
104   int      num_planes;          // number of planes on the stack
105   PlaneApp planes[max_planes];  // Array of planes
106   std::string   transmission;
107   bool     first;
108
109   SGPropertyNode_ptr comm1_node;
110   SGPropertyNode_ptr comm2_node;
111
112   SGPropertyNode_ptr atcmenu_node;
113   SGPropertyNode_ptr atcopt0_node;
114   SGPropertyNode_ptr atcopt1_node;
115   SGPropertyNode_ptr atcopt2_node;
116   SGPropertyNode_ptr atcopt3_node;
117   SGPropertyNode_ptr atcopt4_node;
118   SGPropertyNode_ptr atcopt5_node;
119   SGPropertyNode_ptr atcopt6_node;
120   SGPropertyNode_ptr atcopt7_node;
121   SGPropertyNode_ptr atcopt8_node;
122   SGPropertyNode_ptr atcopt9_node;
123
124   // for failure modeling
125   std::string trans_ident;      // transmitted ident
126   bool approach_failed; // approach failed?
127
128 public:
129
130   FGApproach(void);
131   ~FGApproach(void);
132
133   void Init();
134
135   void Update(double dt);
136
137   // Add new plane to stack if not already registered 
138   // Input:  pid - id of plane (name) 
139   // Output: "true" if added; "false" if already existend
140   void AddPlane(const std::string& pid);
141
142   // Remove plane from stack if out of range
143   int RemovePlane();
144   
145   inline double get_bucket() const { return bucket; }
146   inline int get_pnum() const { return num_planes; }
147   inline const std::string& get_trans_ident() { return trans_ident; }
148   
149 private:
150
151   void calc_wp( const int &i);
152
153   void update_plane_dat();
154
155   void get_active_runway();
156
157   void update_param(const int &i);
158
159   double round_alt( bool hl, double alt );
160
161   double angle_diff_deg( const double &a1, const double &a2);
162
163   void set_message(const std::string &s);
164
165 // ========================================================================
166 // get point2 given starting point1 and course and distance
167 // input:  point1 = heading in degrees, distance
168 // input:  course in degrees, distance
169 // output: point2 = heading in degrees, distance
170 // ========================================================================
171   void calc_cd_head_dist(const double &h1, const double &d1,
172                          const double &course, const double &dist,
173                          double *h2, double *d2);
174
175
176 // ========================================================================
177 // get heading and distance between two points; point2 ---> point1
178 // input:  point1 = heading in degrees, distance
179 // input:  point2 = heading in degrees, distance
180 // output: course in degrees, distance
181 // ========================================================================
182   void calc_hd_course_dist(const double &h1, const double &d1,
183                            const double &h2, const double &d2,
184                            double *course, double *dist);
185
186
187
188 // ========================================================================
189 // closest distance between a point and a straigt line in 2 dim.
190 // the input variables are given in (heading, distance) 
191 // relative to a common point
192 // input:  point        = heading in degrees, distance
193 // input:  straigt line = anker vector (heading in degrees, distance), 
194 //                        heading of direction vector
195 // output: distance
196 // ========================================================================
197   double calc_psl_dist(const double &h1, const double &d1,
198                        const double &h2, const double &d2,
199                        const double &h3);
200
201   // Pointers to current users position
202   SGPropertyNode_ptr lon_node;
203   SGPropertyNode_ptr lat_node;
204   SGPropertyNode_ptr elev_node;
205   SGPropertyNode_ptr hdg_node;
206   SGPropertyNode_ptr speed_node;
207   SGPropertyNode_ptr etime_node;
208   
209   //Update the transmission string
210   void UpdateTransmission(void);
211   
212   friend std::istream& operator>> ( std::istream&, FGApproach& );
213 };
214
215 #endif // _FG_APPROACH_HXX