1 // approach.hxx -- Approach class
\r
3 // Written by Alexander Kappes, started March 2002.
\r
5 // Copyright (C) 2002 Alexander Kappes
\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
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
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
22 #ifndef _FG_APPROACH_HXX
\r
23 #define _FG_APPROACH_HXX
\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
34 #include <Main/fg_props.hxx>
\r
36 #ifdef SG_HAVE_STD_INCLUDES
\r
39 #elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )
\r
40 # include <iostream.h>
\r
41 #elif defined( __BORLANDC__ )
\r
42 # include <iostream>
\r
44 # include <istream.h>
\r
45 #include <iomanip.h>
\r
48 #if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )
\r
49 SG_USING_STD(istream);
\r
52 SG_USING_STD(string);
\r
55 #include "transmission.hxx"
\r
57 //DCL - a complete guess for now.
\r
58 #define FG_APPROACH_DEFAULT_RANGE 100
\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
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
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
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
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
110 class FGApproach : public FGATC {
\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
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
127 SGPropertyNode *comm1_node;
\r
128 SGPropertyNode *comm2_node;
\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
142 // for failure modeling
\r
143 string trans_ident; // transmitted ident
\r
144 bool approach_failed; // approach failed?
\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
160 // Remove plane from stack if out of range
\r
163 //Indicate that this instance should be outputting to the ATC display
\r
164 inline void SetDisplay(void) {display = true;}
\r
166 //Indicate that this instance should not be outputting to the ATC display
\r
167 inline void SetNoDisplay(void) {display = false;}
\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
176 void calc_wp( const int &i);
\r
178 void update_plane_dat();
\r
180 void get_active_runway();
\r
182 void update_param(const int &i);
\r
184 double round_alt( bool hl, double alt );
\r
186 double angle_diff_deg( const double &a1, const double &a2);
\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
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
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
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
232 //Update the transmission string
\r
233 void UpdateTransmission(void);
\r
235 friend istream& operator>> ( istream&, FGApproach& );
\r
238 #endif // _FG_APPROACH_HXX
\r