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( __BORLANDC__ ) || (__APPLE__)
46 SG_USING_STD(istream);
51 //DCL - a complete guess for now.
52 #define FG_APPROACH_DEFAULT_RANGE 100
54 // Contains all information about a plane that the approach control needs
55 const int max_planes = 20; // max number of planes on the stack
56 const int max_wp = 10; // max number of waypoints for approach phase
59 // variables for plane if it's on the radar
60 string ident; // indentification of plane
61 double lon; // longitude in degrees
62 double lat; // latitude in degrees
63 double alt; // Altitute above sea level in feet
64 double hdg; // heading of plane in degrees
65 double dist; // distance to airport in miles
66 double brg; // bearing relative to airport in degrees
67 double spd; // speed above ground
68 int contact; // contact with approach established?
71 // 2 = handed off to tower
73 // additional variables if contact has been established
74 int wpn; // number of waypoints
75 double wpts[max_wp][6]; // assigned waypoints for approach phase
76 // first wp in list is airport
77 // last waypoint point at which contact was established
78 // second index: 0 = bearing to airport
79 // second index: 1 = distance to aiport
80 // second index: 2 = alt
81 // second index: 3 = ETA
82 // second index: 4 = heading to next waypoint
83 // second index: 5 = distance to next waypoint
85 double dnwp; // distance to next waypoint
86 double dcc; // closest distance to current assigned course
87 double dnc; // closest distance to course from next to next to next wp
88 double aalt; // assigned alt at next waypoint
89 double ahdg; // assigned heading
90 bool on_crs; // is the plane on course?
91 double tlm; // time when last message was sent
97 class FGApproach : public FGATC {
100 string active_runway;
101 double active_rw_hdg;
103 bool display; // Flag to indicate whether we should be outputting to the display.
104 bool displaying; // Flag to indicate whether we are outputting to the display.
105 int num_planes; // number of planes on the stack
106 PlaneApp planes[max_planes]; // Array of planes
110 SGPropertyNode *comm1_node;
111 SGPropertyNode *comm2_node;
113 // for failure modeling
114 string trans_ident; // transmitted ident
115 bool approach_failed; // approach failed?
126 // Add new plane to stack if not already registered
127 // Input: pid - id of plane (name)
128 // Output: "true" if added; "false" if already existend
129 void AddPlane(string pid);
131 // Remove plane from stack if out of range
134 //Indicate that this instance should be outputting to the ATC display
135 inline void SetDisplay(void) {display = true;}
137 //Indicate that this instance should not be outputting to the ATC display
138 inline void SetNoDisplay(void) {display = false;}
140 inline double get_bucket() const { return bucket; }
141 inline int get_pnum() const { return num_planes; }
142 inline string get_trans_ident() { return trans_ident; }
143 inline atc_type GetType() { return APPROACH; }
147 void update_plane_dat();
149 void get_active_runway();
151 // ========================================================================
152 // get heading and distance between two points; point2 ---> point1
153 // input: point1 = heading in degrees, distance
154 // input: point2 = heading in degrees, distance
155 // ouput: course in degrees, distance
156 // ========================================================================
157 void calc_hd_course_dist(const double &h1, const double &d1,
158 const double &h2, const double &d2,
159 double *course, double *dist);
161 // ========================================================================
162 // closest distance between a point and a straigt line in 2 dim.
163 // the input variables are given in (heading, distance)
164 // relative to a common point
165 // input: point = heading in degrees, distance
166 // input: straigt line = anker vector (heading in degrees, distance),
167 // heading of direction vector
169 // ========================================================================
170 double calc_psl_dist(const double &h1, const double &d1,
171 const double &h2, const double &d2,
174 // Pointers to current users position
175 SGPropertyNode *lon_node;
176 SGPropertyNode *lat_node;
177 SGPropertyNode *elev_node;
179 //Update the transmission string
180 void UpdateTransmission(void);
184 #endif // _FG_APPROACH_HXX