1 // approach.hxx -- Approach class
3 // Written by Alexander Kappes, started March 2002.
5 // Copyright (C) 2002 Alexander Kappes
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.
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.
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.
22 #ifndef _FG_APPROACH_HXX
23 #define _FG_APPROACH_HXX
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>
34 #include <Main/fg_props.hxx>
36 #ifdef SG_HAVE_STD_INCLUDES
39 #elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )
40 # include <iostream.h>
41 #elif defined( __BORLANDC__ )
48 #if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )
49 SG_USING_STD(istream);
55 #include "transmission.hxx"
57 //DCL - a complete guess for now.
58 #define FG_APPROACH_DEFAULT_RANGE 100
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 = 20000.0; // min time (in ms) between two messages
65 const double lfl = 10.0; // length of final leg
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?
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
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
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
110 class FGApproach : public FGATC {
114 string active_runway;
115 double active_rw_hdg;
116 double active_rw_lon;
117 double active_rw_lat;
118 double active_rw_len;
120 bool display; // Flag to indicate whether we should be outputting to the display.
121 bool displaying; // Flag to indicate whether we are outputting to the display.
122 int num_planes; // number of planes on the stack
123 PlaneApp planes[max_planes]; // Array of planes
127 SGPropertyNode *comm1_node;
128 SGPropertyNode *comm2_node;
130 SGPropertyNode *atcmenu_node;
131 SGPropertyNode *atcopt0_node;
132 SGPropertyNode *atcopt1_node;
133 SGPropertyNode *atcopt2_node;
134 SGPropertyNode *atcopt3_node;
135 SGPropertyNode *atcopt4_node;
136 SGPropertyNode *atcopt5_node;
137 SGPropertyNode *atcopt6_node;
138 SGPropertyNode *atcopt7_node;
139 SGPropertyNode *atcopt8_node;
140 SGPropertyNode *atcopt9_node;
142 // for failure modeling
143 string trans_ident; // transmitted ident
144 bool approach_failed; // approach failed?
153 void Update(double dt);
155 // Add new plane to stack if not already registered
156 // Input: pid - id of plane (name)
157 // Output: "true" if added; "false" if already existend
158 void AddPlane(string pid);
160 // Remove plane from stack if out of range
163 //Indicate that this instance should be outputting to the ATC display
164 inline void SetDisplay(void) {display = true;}
166 //Indicate that this instance should not be outputting to the ATC display
167 inline void SetNoDisplay(void) {display = false;}
169 inline double get_bucket() const { return bucket; }
170 inline int get_pnum() const { return num_planes; }
171 inline string get_trans_ident() { return trans_ident; }
172 inline atc_type GetType() { return APPROACH; }
176 void calc_wp( const int &i);
178 void update_plane_dat();
180 void get_active_runway();
182 void update_param(const int &i);
184 double round_alt( bool hl, double alt );
186 double angle_diff_deg( const double &a1, const double &a2);
188 // ========================================================================
189 // get point2 given starting point1 and course and distance
190 // input: point1 = heading in degrees, distance
191 // input: course in degrees, distance
192 // output: point2 = heading in degrees, distance
193 // ========================================================================
194 void calc_cd_head_dist(const double &h1, const double &d1,
195 const double &course, const double &dist,
196 double *h2, double *d2);
199 // ========================================================================
200 // get heading and distance between two points; point2 ---> point1
201 // input: point1 = heading in degrees, distance
202 // input: point2 = heading in degrees, distance
203 // output: course in degrees, distance
204 // ========================================================================
205 void calc_hd_course_dist(const double &h1, const double &d1,
206 const double &h2, const double &d2,
207 double *course, double *dist);
211 // ========================================================================
212 // closest distance between a point and a straigt line in 2 dim.
213 // the input variables are given in (heading, distance)
214 // relative to a common point
215 // input: point = heading in degrees, distance
216 // input: straigt line = anker vector (heading in degrees, distance),
217 // heading of direction vector
219 // ========================================================================
220 double calc_psl_dist(const double &h1, const double &d1,
221 const double &h2, const double &d2,
224 // Pointers to current users position
225 SGPropertyNode *lon_node;
226 SGPropertyNode *lat_node;
227 SGPropertyNode *elev_node;
228 SGPropertyNode *hdg_node;
229 SGPropertyNode *speed_node;
230 SGPropertyNode *etime_node;
232 //Update the transmission string
233 void UpdateTransmission(void);
235 friend istream& operator>> ( istream&, FGApproach& );
238 #endif // _FG_APPROACH_HXX