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 = 2.0; // min time (in sec) 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 int num_planes; // number of planes on the stack
121 PlaneApp planes[max_planes]; // Array of planes
125 SGPropertyNode *comm1_node;
126 SGPropertyNode *comm2_node;
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;
140 // for failure modeling
141 string trans_ident; // transmitted ident
142 bool approach_failed; // approach failed?
151 void Update(double dt);
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(string pid);
158 // Remove plane from stack if out of range
161 inline double get_bucket() const { return bucket; }
162 inline int get_pnum() const { return num_planes; }
163 inline string get_trans_ident() { return trans_ident; }
167 void calc_wp( const int &i);
169 void update_plane_dat();
171 void get_active_runway();
173 void update_param(const int &i);
175 double round_alt( bool hl, double alt );
177 double angle_diff_deg( const double &a1, const double &a2);
179 // ========================================================================
180 // get point2 given starting point1 and course and distance
181 // input: point1 = heading in degrees, distance
182 // input: course in degrees, distance
183 // output: point2 = heading in degrees, distance
184 // ========================================================================
185 void calc_cd_head_dist(const double &h1, const double &d1,
186 const double &course, const double &dist,
187 double *h2, double *d2);
190 // ========================================================================
191 // get heading and distance between two points; point2 ---> point1
192 // input: point1 = heading in degrees, distance
193 // input: point2 = heading in degrees, distance
194 // output: course in degrees, distance
195 // ========================================================================
196 void calc_hd_course_dist(const double &h1, const double &d1,
197 const double &h2, const double &d2,
198 double *course, double *dist);
202 // ========================================================================
203 // closest distance between a point and a straigt line in 2 dim.
204 // the input variables are given in (heading, distance)
205 // relative to a common point
206 // input: point = heading in degrees, distance
207 // input: straigt line = anker vector (heading in degrees, distance),
208 // heading of direction vector
210 // ========================================================================
211 double calc_psl_dist(const double &h1, const double &d1,
212 const double &h2, const double &d2,
215 // Pointers to current users position
216 SGPropertyNode *lon_node;
217 SGPropertyNode *lat_node;
218 SGPropertyNode *elev_node;
219 SGPropertyNode *hdg_node;
220 SGPropertyNode *speed_node;
221 SGPropertyNode *etime_node;
223 //Update the transmission string
224 void UpdateTransmission(void);
226 friend istream& operator>> ( istream&, FGApproach& );
229 #endif // _FG_APPROACH_HXX